This source file includes following definitions.
- StepWidgetLayerAnimatorToEnd
- GetShelfWidget
- GetShelfLayoutManager
- GetSystemTray
- done_waiting_
- WaitTillDoneAnimating
- WasValidAnimation
- IsDoneAnimating
- OnWidgetBoundsChanged
- was_visible_on_drag_start_
- ProcessScroll
- changed_auto_hide_state
- OnAutoHideStateChanged
- notification_view_
- CreateTrayView
- CreateDefaultView
- CreateDetailedView
- CreateNotificationView
- DestroyTrayView
- DestroyDefaultView
- DestroyDetailedView
- DestroyNotificationView
- UpdateAfterLoginStatusChange
- tray_view
- default_view
- detailed_view
- notification_view
- SetState
- UpdateAutoHideStateNow
- CreateTestWindow
- CreateTestWidgetWithParams
- CreateTestWidget
- SetUp
- RunGestureDragTests
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_table.h"
#include "ash/ash_switches.h"
#include "ash/display/display_manager.h"
#include "ash/focus_cycler.h"
#include "ash/root_window_controller.h"
#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_item.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/shelf_test_api.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/gestures/gesture_configuration.h"
#include "ui/gfx/animation/animation_container_element.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif
namespace ash {
namespace {
void StepWidgetLayerAnimatorToEnd(views::Widget* widget) {
gfx::AnimationContainerElement* element =
static_cast<gfx::AnimationContainerElement*>(
widget->GetNativeView()->layer()->GetAnimator());
element->Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
}
ShelfWidget* GetShelfWidget() {
return Shell::GetPrimaryRootWindowController()->shelf();
}
ShelfLayoutManager* GetShelfLayoutManager() {
return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
}
SystemTray* GetSystemTray() {
return Shell::GetPrimaryRootWindowController()->GetSystemTray();
}
class ShelfAnimationWaiter : views::WidgetObserver {
public:
explicit ShelfAnimationWaiter(const gfx::Rect& target_bounds)
: target_bounds_(target_bounds),
animation_steps_(0),
done_waiting_(false) {
GetShelfWidget()->AddObserver(this);
}
virtual ~ShelfAnimationWaiter() {
GetShelfWidget()->RemoveObserver(this);
}
void WaitTillDoneAnimating() {
if (IsDoneAnimating())
done_waiting_ = true;
else
base::MessageLoop::current()->Run();
}
bool WasValidAnimation() const {
return done_waiting_ && animation_steps_ > 0;
}
private:
bool IsDoneAnimating() const {
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
gfx::Rect current_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
int size = layout_manager->PrimaryAxisValue(current_bounds.height(),
current_bounds.width());
int desired_size = layout_manager->PrimaryAxisValue(target_bounds_.height(),
target_bounds_.width());
return (size == desired_size);
}
virtual void OnWidgetBoundsChanged(views::Widget* widget,
const gfx::Rect& new_bounds) OVERRIDE {
if (done_waiting_)
return;
++animation_steps_;
if (IsDoneAnimating()) {
done_waiting_ = true;
base::MessageLoop::current()->Quit();
}
}
gfx::Rect target_bounds_;
int animation_steps_;
bool done_waiting_;
DISALLOW_COPY_AND_ASSIGN(ShelfAnimationWaiter);
};
class ShelfDragCallback {
public:
ShelfDragCallback(const gfx::Rect& not_visible, const gfx::Rect& visible)
: not_visible_bounds_(not_visible),
visible_bounds_(visible),
was_visible_on_drag_start_(false) {
EXPECT_EQ(not_visible_bounds_.bottom(), visible_bounds_.bottom());
}
virtual ~ShelfDragCallback() {
}
void ProcessScroll(ui::EventType type, const gfx::Vector2dF& delta) {
if (GetShelfLayoutManager()->visibility_state() == ash::SHELF_HIDDEN)
return;
if (type == ui::ET_GESTURE_SCROLL_BEGIN) {
scroll_ = gfx::Vector2dF();
was_visible_on_drag_start_ = GetShelfLayoutManager()->IsVisible();
return;
}
if (type == ui::ET_GESTURE_SCROLL_END)
return;
if (type == ui::ET_GESTURE_SCROLL_UPDATE)
scroll_.Add(delta);
gfx::Rect shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
if (GetShelfLayoutManager()->IsHorizontalAlignment()) {
EXPECT_EQ(not_visible_bounds_.bottom(), shelf_bounds.bottom());
EXPECT_EQ(visible_bounds_.bottom(), shelf_bounds.bottom());
} else if (SHELF_ALIGNMENT_RIGHT ==
GetShelfLayoutManager()->GetAlignment()){
EXPECT_EQ(not_visible_bounds_.right(), shelf_bounds.right());
EXPECT_EQ(visible_bounds_.right(), shelf_bounds.right());
} else if (SHELF_ALIGNMENT_LEFT ==
GetShelfLayoutManager()->GetAlignment()) {
EXPECT_EQ(not_visible_bounds_.x(), shelf_bounds.x());
EXPECT_EQ(visible_bounds_.x(), shelf_bounds.x());
}
if (GetShelfWidget()->GetDimsShelf())
EXPECT_EQ(GetShelfWidget()->GetWindowBoundsInScreen(),
GetShelfWidget()->GetDimmerBoundsForTest());
EXPECT_GE(shelf_bounds.height(), not_visible_bounds_.height());
float scroll_delta = GetShelfLayoutManager()->PrimaryAxisValue(
scroll_.y(),
scroll_.x());
bool increasing_drag =
GetShelfLayoutManager()->SelectValueForShelfAlignment(
scroll_delta < 0,
scroll_delta > 0,
scroll_delta < 0,
scroll_delta > 0);
int shelf_size = GetShelfLayoutManager()->PrimaryAxisValue(
shelf_bounds.height(),
shelf_bounds.width());
int visible_bounds_size = GetShelfLayoutManager()->PrimaryAxisValue(
visible_bounds_.height(),
visible_bounds_.width());
int not_visible_bounds_size = GetShelfLayoutManager()->PrimaryAxisValue(
not_visible_bounds_.height(),
not_visible_bounds_.width());
if (was_visible_on_drag_start_) {
if (increasing_drag) {
EXPECT_LE(visible_bounds_size, shelf_size);
EXPECT_LE(abs(shelf_size - visible_bounds_size),
abs(scroll_delta));
} else {
if (shelf_size > not_visible_bounds_size) {
EXPECT_EQ(shelf_size, visible_bounds_size - abs(scroll_delta));
}
}
} else {
if (fabs(scroll_delta) <
visible_bounds_size - not_visible_bounds_size) {
EXPECT_EQ(shelf_size, not_visible_bounds_size + abs(scroll_delta));
} else {
EXPECT_LT(shelf_size, not_visible_bounds_size + abs(scroll_delta));
}
}
}
private:
const gfx::Rect not_visible_bounds_;
const gfx::Rect visible_bounds_;
gfx::Vector2dF scroll_;
bool was_visible_on_drag_start_;
DISALLOW_COPY_AND_ASSIGN(ShelfDragCallback);
};
class ShelfLayoutObserverTest : public ShelfLayoutManagerObserver {
public:
ShelfLayoutObserverTest()
: changed_auto_hide_state_(false) {
}
virtual ~ShelfLayoutObserverTest() {}
bool changed_auto_hide_state() const { return changed_auto_hide_state_; }
private:
virtual void OnAutoHideStateChanged(
ShelfAutoHideState new_state) OVERRIDE {
changed_auto_hide_state_ = true;
}
bool changed_auto_hide_state_;
DISALLOW_COPY_AND_ASSIGN(ShelfLayoutObserverTest);
};
class TestItem : public SystemTrayItem {
public:
TestItem()
: SystemTrayItem(GetSystemTray()),
tray_view_(NULL),
default_view_(NULL),
detailed_view_(NULL),
notification_view_(NULL) {}
virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE {
tray_view_ = new views::View;
tray_view_->SetLayoutManager(new views::FillLayout);
tray_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Tray")));
return tray_view_;
}
virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE {
default_view_ = new views::View;
default_view_->SetLayoutManager(new views::FillLayout);
default_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Default")));
return default_view_;
}
virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE {
detailed_view_ = new views::View;
detailed_view_->SetLayoutManager(new views::FillLayout);
detailed_view_->AddChildView(
new views::Label(base::UTF8ToUTF16("Detailed")));
return detailed_view_;
}
virtual views::View* CreateNotificationView(
user::LoginStatus status) OVERRIDE {
notification_view_ = new views::View;
return notification_view_;
}
virtual void DestroyTrayView() OVERRIDE {
tray_view_ = NULL;
}
virtual void DestroyDefaultView() OVERRIDE {
default_view_ = NULL;
}
virtual void DestroyDetailedView() OVERRIDE {
detailed_view_ = NULL;
}
virtual void DestroyNotificationView() OVERRIDE {
notification_view_ = NULL;
}
virtual void UpdateAfterLoginStatusChange(
user::LoginStatus status) OVERRIDE {}
views::View* tray_view() const { return tray_view_; }
views::View* default_view() const { return default_view_; }
views::View* detailed_view() const { return detailed_view_; }
views::View* notification_view() const { return notification_view_; }
private:
views::View* tray_view_;
views::View* default_view_;
views::View* detailed_view_;
views::View* notification_view_;
DISALLOW_COPY_AND_ASSIGN(TestItem);
};
}
class ShelfLayoutManagerTest : public ash::test::AshTestBase {
public:
ShelfLayoutManagerTest() {}
void SetState(ShelfLayoutManager* shelf,
ShelfVisibilityState state) {
shelf->SetState(state);
}
void UpdateAutoHideStateNow() {
GetShelfLayoutManager()->UpdateAutoHideStateNow();
}
aura::Window* CreateTestWindow() {
aura::Window* window = new aura::Window(NULL);
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_TEXTURED);
ParentWindowInPrimaryRootWindow(window);
return window;
}
views::Widget* CreateTestWidgetWithParams(
const views::Widget::InitParams& params) {
views::Widget* out = new views::Widget;
out->Init(params);
out->Show();
return out;
}
views::Widget* CreateTestWidget() {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
return CreateTestWidgetWithParams(params);
}
virtual void SetUp() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitch(
ash::switches::kAshEnableTrayDragging);
test::AshTestBase::SetUp();
}
void RunGestureDragTests(gfx::Vector2d);
private:
DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest);
};
void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Show();
widget->Maximize();
aura::Window* window = widget->GetNativeWindow();
shelf->LayoutShelf();
gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Rect bounds_shelf = window->bounds();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
shelf->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
gfx::Rect bounds_noshelf = window->bounds();
gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
shelf->LayoutShelf();
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
const int kNumScrollSteps = 4;
ShelfDragCallback handler(shelf_hidden, shelf_shown);
gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
gfx::Point end = start + delta;
generator.GestureScrollSequenceWithCallback(start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_NE(bounds_shelf.ToString(), window->bounds().ToString());
EXPECT_NE(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
generator.GestureScrollSequenceWithCallback(end, start,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
GetShelfWidget()->GetWindowBoundsInScreen());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
end = start - delta;
generator.GestureScrollSequenceWithCallback(start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
end = start + delta;
generator.GestureScrollSequenceWithCallback(end, start,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
if (GetShelfLayoutManager()->IsHorizontalAlignment())
end.set_y(start.y() + shelf_shown.height() * 3 / 10);
else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
end.set_x(start.x() - shelf_shown.width() * 3 / 10);
else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
end.set_x(start.x() + shelf_shown.width() * 3 / 10);
generator.GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 5);
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
end = start + delta;
generator.GestureScrollSequenceWithCallback(start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
gfx::Point extended_start = start;
if (GetShelfLayoutManager()->IsHorizontalAlignment())
extended_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().y() -1);
else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
extended_start.set_x(
GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
extended_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
end = extended_start - delta;
generator.GestureScrollSequenceWithCallback(extended_start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
GetShelfWidget()->GetWindowBoundsInScreen());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
end = start + delta;
generator.GestureScrollSequenceWithCallback(start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
gfx::Point outside_start = gfx::Point(
(GetShelfWidget()->GetWindowBoundsInScreen().x() +
GetShelfWidget()->GetWindowBoundsInScreen().right())/2,
GetShelfWidget()->GetWindowBoundsInScreen().y() - 50);
end = outside_start + delta;
generator.GestureScrollSequence(outside_start,
end,
base::TimeDelta::FromMilliseconds(10),
kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
gfx::Point below_start = start;
if (GetShelfLayoutManager()->IsHorizontalAlignment())
below_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() + 1);
else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
below_start.set_x(
GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
end = below_start - delta;
generator.GestureScrollSequence(below_start,
end,
base::TimeDelta::FromMilliseconds(10),
kNumScrollSteps);
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
GetShelfWidget()->GetWindowBoundsInScreen());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
end = start + delta;
generator.GestureScrollSequenceWithCallback(start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
widget->SetFullscreen(true);
wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(false);
shelf->UpdateVisibilityState();
gfx::Rect bounds_fullscreen = window->bounds();
EXPECT_TRUE(widget->IsFullscreen());
EXPECT_NE(bounds_noshelf.ToString(), bounds_fullscreen.ToString());
end = below_start - delta;
generator.GestureScrollSequenceWithCallback(below_start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
generator.GestureScrollSequenceWithCallback(below_start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(true);
shelf->UpdateVisibilityState();
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
end = start - delta;
generator.GestureScrollSequenceWithCallback(below_start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
widget->Close();
RunAllPendingInMessageLoop();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
end = below_start - delta;
generator.GestureScrollSequenceWithCallback(below_start, end,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
}
#if defined(OS_WIN)
#define MAYBE_SetVisible DISABLED_SetVisible
#else
#define MAYBE_SetVisible SetVisible
#endif
TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) {
ShelfWidget* shelf = GetShelfWidget();
ShelfLayoutManager* manager = shelf->shelf_layout_manager();
manager->LayoutShelf();
EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
gfx::Rect status_bounds(
shelf->status_area_widget()->GetWindowBoundsInScreen());
gfx::Rect shelf_bounds(
shelf->GetWindowBoundsInScreen());
int shelf_height = manager->GetIdealBounds().height();
gfx::Screen* screen = Shell::GetScreen();
gfx::Display display = screen->GetDisplayNearestWindow(
Shell::GetPrimaryRootWindow());
ASSERT_NE(-1, display.id());
EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
SetState(manager, SHELF_HIDDEN);
StepWidgetLayerAnimatorToEnd(shelf);
StepWidgetLayerAnimatorToEnd(shelf->status_area_widget());
EXPECT_EQ(SHELF_HIDDEN, manager->visibility_state());
display = screen->GetDisplayNearestWindow(
Shell::GetPrimaryRootWindow());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_GE(shelf->GetNativeView()->bounds().y(),
screen->GetPrimaryDisplay().bounds().bottom());
EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(),
screen->GetPrimaryDisplay().bounds().bottom());
SetState(manager, SHELF_VISIBLE);
StepWidgetLayerAnimatorToEnd(shelf);
StepWidgetLayerAnimatorToEnd(shelf->status_area_widget());
EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
display = screen->GetDisplayNearestWindow(
Shell::GetPrimaryRootWindow());
EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
shelf_bounds = shelf->GetNativeView()->bounds();
EXPECT_LT(shelf_bounds.y(), screen->GetPrimaryDisplay().bounds().bottom());
status_bounds = shelf->status_area_widget()->GetNativeView()->bounds();
EXPECT_LT(status_bounds.y(),
screen->GetPrimaryDisplay().bounds().bottom());
}
TEST_F(ShelfLayoutManagerTest, SideAlignmentInteractionWithLockScreen) {
ShelfLayoutManager* manager = GetShelfWidget()->shelf_layout_manager();
manager->SetAlignment(SHELF_ALIGNMENT_LEFT);
EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
Shell::GetInstance()->session_state_delegate()->LockScreen();
EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, manager->GetAlignment());
Shell::GetInstance()->session_state_delegate()->UnlockScreen();
EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
}
TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
ShelfWidget* shelf = GetShelfWidget();
shelf->shelf_layout_manager()->LayoutShelf();
EXPECT_EQ(SHELF_VISIBLE, shelf->shelf_layout_manager()->visibility_state());
SetState(shelf->shelf_layout_manager(), SHELF_HIDDEN);
shelf->shelf_layout_manager()->LayoutShelf();
EXPECT_EQ(SHELF_HIDDEN, shelf->shelf_layout_manager()->visibility_state());
gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow(
Shell::GetPrimaryRootWindow());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_GE(shelf->GetNativeView()->bounds().y(),
Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(),
Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
}
TEST_F(ShelfLayoutManagerTest, SetStateWhileAnimating) {
ShelfWidget* shelf = GetShelfWidget();
SetState(shelf->shelf_layout_manager(), SHELF_VISIBLE);
gfx::Rect initial_shelf_bounds = shelf->GetWindowBoundsInScreen();
gfx::Rect initial_status_bounds =
shelf->status_area_widget()->GetWindowBoundsInScreen();
ui::ScopedAnimationDurationScaleMode normal_animation_duration(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
SetState(shelf->shelf_layout_manager(), SHELF_HIDDEN);
SetState(shelf->shelf_layout_manager(), SHELF_VISIBLE);
gfx::Rect current_shelf_bounds = shelf->GetWindowBoundsInScreen();
gfx::Rect current_status_bounds =
shelf->status_area_widget()->GetWindowBoundsInScreen();
const int small_change = initial_shelf_bounds.height() / 2;
EXPECT_LE(
std::abs(initial_shelf_bounds.height() - current_shelf_bounds.height()),
small_change);
EXPECT_LE(
std::abs(initial_status_bounds.height() - current_status_bounds.height()),
small_change);
}
TEST_F(ShelfLayoutManagerTest, ShelfUpdatedWhenStatusAreaChangesSize) {
Shelf* shelf = Shelf::ForPrimaryDisplay();
ASSERT_TRUE(shelf);
ShelfWidget* shelf_widget = GetShelfWidget();
ASSERT_TRUE(shelf_widget);
ASSERT_TRUE(shelf_widget->status_area_widget());
shelf_widget->status_area_widget()->SetBounds(
gfx::Rect(0, 0, 200, 200));
EXPECT_EQ(200, shelf_widget->GetContentsView()->width() -
test::ShelfTestAPI(shelf).shelf_view()->width());
}
#if defined(OS_WIN)
#define MAYBE_AutoHide DISABLED_AutoHide
#else
#define MAYBE_AutoHide AutoHide
#endif
TEST_F(ShelfLayoutManagerTest, MAYBE_AutoHide) {
aura::Window* root = Shell::GetPrimaryRootWindow();
aura::test::EventGenerator generator(root, root);
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Maximize();
widget->Show();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
shelf->LayoutShelf();
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
GetShelfWidget()->GetWindowBoundsInScreen().y());
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
Shell::GetScreen()->GetDisplayNearestWindow(
root).work_area().bottom());
generator.MoveMouseTo(0, root->bounds().bottom() - 1);
SetState(shelf, SHELF_AUTO_HIDE);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
shelf->LayoutShelf();
EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(),
GetShelfWidget()->GetWindowBoundsInScreen().y());
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
Shell::GetScreen()->GetDisplayNearestWindow(
root).work_area().bottom());
generator.MoveMouseTo(0, 0);
SetState(shelf, SHELF_AUTO_HIDE);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
shelf->LayoutShelf();
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
GetShelfWidget()->GetWindowBoundsInScreen().y());
generator.PressLeftButton();
generator.MoveMouseTo(0, root->bounds().bottom() - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.ReleaseLeftButton();
generator.MoveMouseTo(1, root->bounds().bottom() - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
generator.PressLeftButton();
generator.MoveMouseTo(1, root->bounds().bottom() - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
}
TEST_F(ShelfLayoutManagerTest, MaximizeModePreventsMouseHide) {
aura::Window* root = Shell::GetPrimaryRootWindow();
aura::test::EventGenerator generator(root, root);
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Maximize();
widget->Show();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
shelf->OnMaximizeModeStarted();
shelf->LayoutShelf();
generator.MoveMouseTo(0, 0);
generator.PressLeftButton();
generator.MoveMouseTo(0, root->bounds().bottom() - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
}
TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnScreenBoundary) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x600,800x600");
DisplayLayout display_layout(DisplayLayout::RIGHT, 0);
Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
display_layout);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
CreateTestWidget();
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(root_windows[0],
GetShelfWidget()->GetNativeWindow()->GetRootWindow());
shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
int right_edge = root_windows[0]->GetBoundsInScreen().right() - 1;
int y = root_windows[0]->GetBoundsInScreen().y();
aura::test::EventGenerator& generator(GetEventGenerator());
generator.MoveMouseTo(right_edge - 50, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.MoveMouseTo(right_edge - 1, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
EXPECT_EQ(right_edge - 1, Shell::GetScreen()->GetCursorScreenPoint().x());
generator.MoveMouseTo(right_edge - 50, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.MoveMouseTo(right_edge - 1, y);
generator.MoveMouseTo(right_edge, y);
UpdateAutoHideStateNow();
EXPECT_NE(right_edge - 1, Shell::GetScreen()->GetCursorScreenPoint().x());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
generator.MoveMouseTo(right_edge - 50, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.MoveMouseTo(right_edge - 1, y);
generator.MoveMouseTo(right_edge + 50, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.MoveMouseTo(right_edge - 1, y);
generator.MoveMouseTo(right_edge + 2, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
generator.MoveMouseTo(right_edge + 2, y + 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
generator.MoveMouseTo(right_edge + 50, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.MoveMouseTo(right_edge + 2, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
}
TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Maximize();
widget->Show();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
aura::Window* root = Shell::GetPrimaryRootWindow();
shelf->LayoutShelf();
EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
GetShelfWidget()->GetWindowBoundsInScreen().y());
aura::Window* lock_container = Shell::GetContainer(
Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer);
views::Widget* lock_widget = new views::Widget;
views::Widget::InitParams lock_params(
views::Widget::InitParams::TYPE_WINDOW);
lock_params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
lock_params.parent = lock_container;
lock_widget->Init(lock_params);
lock_widget->Maximize();
lock_widget->Show();
Shell::GetInstance()->session_state_delegate()->LockScreen();
shelf->UpdateVisibilityState();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
Shell::GetInstance()->session_state_delegate()->UnlockScreen();
shelf->UpdateVisibilityState();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
}
TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Show();
aura::Window* window = widget->GetNativeWindow();
gfx::Rect display_bounds(
Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
widget->Maximize();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
window).work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
window).work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
window).work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
}
TEST_F(ShelfLayoutManagerTest, TestDimmingBehavior) {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->shelf_widget()->DisableDimmingAnimationsForTest();
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Show();
aura::Window* window = widget->GetNativeWindow();
gfx::Rect display_bounds(
Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
gfx::Point off_shelf = display_bounds.CenterPoint();
gfx::Point on_shelf =
shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
widget->Maximize();
on_shelf = shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.PressTouch();
generator.MoveTouch(off_shelf);
EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveTouch(on_shelf);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.ReleaseTouch();
EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveMouseTo(on_shelf);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.PressTouch();
generator.MoveTouch(off_shelf);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveTouch(on_shelf);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveTouch(off_shelf);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveTouch(on_shelf);
generator.ReleaseTouch();
widget->Restore();
EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
}
TEST_F(ShelfLayoutManagerTest, TestDimmingBehaviorWithMenus) {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->shelf_widget()->DisableDimmingAnimationsForTest();
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Show();
aura::Window* window = widget->GetNativeWindow();
gfx::Rect display_bounds(
Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
widget->Maximize();
gfx::Point off_shelf = display_bounds.CenterPoint();
gfx::Point on_shelf =
shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
shelf->shelf_widget()->ForceUndimming(true);
generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.PressTouch();
generator.MoveTouch(off_shelf);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveTouch(on_shelf);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveTouch(off_shelf);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.ReleaseTouch();
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
shelf->shelf_widget()->ForceUndimming(false);
EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
shelf->shelf_widget()->ForceUndimming(true);
generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
shelf->shelf_widget()->ForceUndimming(true);
EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
}
TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrShelfFocused) {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow(), gfx::Point());
generator.MoveMouseTo(0, 0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Show();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
widget->Activate();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
GetShelfWidget()->status_area_widget()->Activate();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
}
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) {
Shell* shell = Shell::GetInstance();
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->LayoutShelf();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->Show();
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
shell->ToggleAppList(NULL);
EXPECT_TRUE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
shell->ToggleAppList(NULL);
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
}
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) {
Shell* shell = Shell::GetInstance();
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->LayoutShelf();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
window->Show();
wm::ActivateWindow(window);
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
shell->ToggleAppList(NULL);
shell->UpdateShelfVisibility();
EXPECT_TRUE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
shell->ToggleAppList(NULL);
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
}
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfHiddenState) {
Shell* shell = Shell::GetInstance();
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->LayoutShelf();
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window->Show();
wm::ActivateWindow(window);
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
shell->ToggleAppList(NULL);
EXPECT_TRUE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
shell->ToggleAppList(NULL);
EXPECT_FALSE(shell->GetAppListTargetVisibility());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
}
TEST_F(ShelfLayoutManagerTest, FullscreenWindowInFrontHidesShelf) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
aura::Window* window1 = CreateTestWindow();
window1->SetBounds(gfx::Rect(0, 0, 100, 100));
window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window1->Show();
aura::Window* window2 = CreateTestWindow();
window2->SetBounds(gfx::Rect(0, 0, 100, 100));
window2->Show();
wm::GetWindowState(window1)->Activate();
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
wm::GetWindowState(window2)->Activate();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
wm::GetWindowState(window1)->Activate();
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
}
TEST_F(ShelfLayoutManagerTest, FullscreenWindowOnSecondDisplay) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x600,800x600");
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
Shell::RootWindowControllerList root_window_controllers =
Shell::GetAllRootWindowControllers();
aura::Window* window1 = CreateTestWindow();
window1->SetBoundsInScreen(
gfx::Rect(0, 0, 100, 100),
display_manager->GetDisplayAt(0));
window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window1->Show();
aura::Window* window2 = CreateTestWindow();
window2->SetBoundsInScreen(
gfx::Rect(800, 0, 100, 100),
display_manager->GetDisplayAt(1));
window2->Show();
EXPECT_EQ(root_windows[0], window1->GetRootWindow());
EXPECT_EQ(root_windows[1], window2->GetRootWindow());
wm::GetWindowState(window2)->Activate();
EXPECT_EQ(SHELF_HIDDEN,
root_window_controllers[0]->GetShelfLayoutManager()->visibility_state());
EXPECT_EQ(SHELF_VISIBLE,
root_window_controllers[1]->GetShelfLayoutManager()->visibility_state());
}
#if defined(OS_WIN)
#define MAYBE_SetAlignment DISABLED_SetAlignment
#else
#define MAYBE_SetAlignment SetAlignment
#endif
TEST_F(ShelfLayoutManagerTest, MAYBE_SetAlignment) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
shelf->LayoutShelf();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
gfx::Rect shelf_bounds(
GetShelfWidget()->GetWindowBoundsInScreen());
const gfx::Screen* screen = Shell::GetScreen();
gfx::Display display =
screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
ASSERT_NE(-1, display.id());
EXPECT_EQ(shelf->GetIdealBounds().width(),
display.GetWorkAreaInsets().left());
EXPECT_GE(
shelf_bounds.width(),
GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetSystemTray()->shelf_alignment());
StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen());
EXPECT_GE(status_bounds.width(),
status_area_widget->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(shelf->GetIdealBounds().width(),
display.GetWorkAreaInsets().left());
EXPECT_EQ(0, display.GetWorkAreaInsets().top());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_EQ(0, display.GetWorkAreaInsets().right());
EXPECT_EQ(display.bounds().x(), shelf_bounds.x());
EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
display.GetWorkAreaInsets().left());
EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
ASSERT_NE(-1, display.id());
EXPECT_EQ(shelf->GetIdealBounds().width(),
display.GetWorkAreaInsets().right());
EXPECT_GE(shelf_bounds.width(),
GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment());
status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
EXPECT_GE(status_bounds.width(),
status_area_widget->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(shelf->GetIdealBounds().width(),
display.GetWorkAreaInsets().right());
EXPECT_EQ(0, display.GetWorkAreaInsets().top());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_EQ(0, display.GetWorkAreaInsets().left());
EXPECT_EQ(display.work_area().right(), shelf_bounds.x());
EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
display.GetWorkAreaInsets().right());
EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
display.bounds().right() - display.work_area().right());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
shelf->SetAlignment(SHELF_ALIGNMENT_TOP);
display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
ASSERT_NE(-1, display.id());
EXPECT_EQ(shelf->GetIdealBounds().height(),
display.GetWorkAreaInsets().top());
EXPECT_GE(shelf_bounds.height(),
GetShelfWidget()->GetContentsView()->GetPreferredSize().height());
EXPECT_EQ(SHELF_ALIGNMENT_TOP, GetSystemTray()->shelf_alignment());
status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
EXPECT_GE(status_bounds.height(),
status_area_widget->GetContentsView()->GetPreferredSize().height());
EXPECT_EQ(shelf->GetIdealBounds().height(),
display.GetWorkAreaInsets().top());
EXPECT_EQ(0, display.GetWorkAreaInsets().right());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_EQ(0, display.GetWorkAreaInsets().left());
EXPECT_EQ(display.work_area().y(), shelf_bounds.bottom());
EXPECT_EQ(display.bounds().x(), shelf_bounds.x());
EXPECT_EQ(display.bounds().width(), shelf_bounds.width());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
display.GetWorkAreaInsets().top());
EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
display.work_area().y() - display.bounds().y());
}
TEST_F(ShelfLayoutManagerTest, DISABLED_GestureEdgeSwipe) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Show();
widget->Maximize();
aura::Window* window = widget->GetNativeWindow();
shelf->LayoutShelf();
gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Rect bounds_shelf = window->bounds();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
shelf->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.GestureEdgeSwipe();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
widget->SetFullscreen(true);
wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(false);
shelf->UpdateVisibilityState();
gfx::Rect bounds_fullscreen = window->bounds();
EXPECT_TRUE(widget->IsFullscreen());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
generator.GestureEdgeSwipe();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_FALSE(widget->IsFullscreen());
}
TEST_F(ShelfLayoutManagerTest, MaximizeModeGestureEdgeSwipe) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
widget->Init(params);
widget->Show();
widget->Maximize();
shelf->LayoutShelf();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
shelf->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
shelf->OnMaximizeModeStarted();
shelf->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.GestureEdgeSwipe();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
}
#if defined(OS_WIN)
#define MAYBE_GestureDrag DISABLED_GestureDrag
#else
#define MAYBE_GestureDrag GestureDrag
#endif
TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
ShelfLayoutManager* shelf = GetShelfLayoutManager();
{
SCOPED_TRACE("BOTTOM");
RunGestureDragTests(gfx::Vector2d(0, 120));
}
{
SCOPED_TRACE("LEFT");
shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
RunGestureDragTests(gfx::Vector2d(-120, 0));
}
{
SCOPED_TRACE("RIGHT");
shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
RunGestureDragTests(gfx::Vector2d(120, 0));
}
}
TEST_F(ShelfLayoutManagerTest, WindowVisibilityDisablesAutoHide) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x600,800x600");
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->LayoutShelf();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
views::Widget* dummy = CreateTestWidget();
shelf->UpdateVisibilityState();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
dummy->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
dummy->CloseNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
views::Widget* window1 = CreateTestWidget();
views::Widget* window2 = CreateTestWidget();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
window2->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
window2->Restore();
window1->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
window2->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
window2->Restore();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
window2->SetBounds(gfx::Rect(850, 50, 50, 50));
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
window2->SetBounds(gfx::Rect(50, 50, 50, 50));
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
}
TEST_F(ShelfLayoutManagerTest, ShelfAnimatesWhenGestureComplete) {
if (!SupportsHostWindowResize())
return;
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
gfx::Rect visible_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
{
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
gfx::Rect shelf_bounds_in_screen =
GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Point start(shelf_bounds_in_screen.CenterPoint());
gfx::Point end(start.x(), shelf_bounds_in_screen.bottom());
generator.GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 5);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
ShelfAnimationWaiter waiter(visible_bounds);
waiter.WaitTillDoneAnimating();
EXPECT_TRUE(waiter.WasValidAnimation());
}
CreateTestWidget();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
{
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
gfx::Point start =
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
gfx::Point end(start.x(), start.y() - 100);
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 1);
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
ShelfAnimationWaiter waiter1(visible_bounds);
waiter1.WaitTillDoneAnimating();
EXPECT_TRUE(waiter1.WasValidAnimation());
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
generator.GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 1);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
ShelfAnimationWaiter waiter2(auto_hidden_bounds);
waiter2.WaitTillDoneAnimating();
EXPECT_TRUE(waiter2.WasValidAnimation());
}
}
TEST_F(ShelfLayoutManagerTest, GestureRevealsTrayBubble) {
if (!SupportsHostWindowResize())
return;
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->LayoutShelf();
CreateTestWidget();
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
SystemTray* tray = GetSystemTray();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
EXPECT_FALSE(tray->HasSystemBubble());
gfx::Point start = GetShelfWidget()->status_area_widget()->
GetWindowBoundsInScreen().CenterPoint();
gfx::Point end(start.x(), start.y() - 100);
generator.GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 1);
EXPECT_TRUE(tray->HasSystemBubble());
tray->CloseSystemBubble();
RunAllPendingInMessageLoop();
EXPECT_FALSE(tray->HasSystemBubble());
end.set_y(start.y() - 30);
generator.GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(500), 100);
EXPECT_FALSE(tray->HasSystemBubble());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
start.set_y(start.y() + 100);
end.set_y(start.y() - 400);
generator.GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(10), 1);
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_TRUE(tray->HasSystemBubble());
}
TEST_F(ShelfLayoutManagerTest, ShelfFlickerOnTrayActivation) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
CreateTestWidget();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
Shell::GetInstance()->accelerator_controller()->PerformAction(
SHOW_SYSTEM_TRAY_BUBBLE, ui::Accelerator());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
EXPECT_TRUE(GetSystemTray()->HasSystemBubble());
}
TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
shelf->LayoutShelf();
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
views::Widget* widget_one = CreateTestWidgetWithParams(params);
widget_one->Maximize();
views::Widget* widget_two = CreateTestWidgetWithParams(params);
widget_two->Maximize();
widget_two->Activate();
EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
widget_two->GetNativeWindow()->bounds().ToString());
int area_when_shelf_shown =
widget_one->GetNativeWindow()->bounds().size().GetArea();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
widget_two->GetNativeWindow()->bounds().ToString());
EXPECT_LT(area_when_shelf_shown,
widget_one->GetNativeWindow()->bounds().size().GetArea());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
widget_two->GetNativeWindow()->bounds().ToString());
EXPECT_EQ(area_when_shelf_shown,
widget_one->GetNativeWindow()->bounds().size().GetArea());
}
TEST_F(ShelfLayoutManagerTest, Dimming) {
GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
scoped_ptr<aura::Window> w1(CreateTestWindow());
w1->Show();
wm::ActivateWindow(w1.get());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
ShelfWidget* shelf = GetShelfWidget();
EXPECT_FALSE(shelf->GetDimsShelf());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_TRUE(shelf->GetDimsShelf());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_FALSE(shelf->GetDimsShelf());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_TRUE(shelf->GetDimsShelf());
GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_FALSE(shelf->GetDimsShelf());
}
TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) {
ShelfLayoutManager* shelf = GetShelfLayoutManager();
StatusAreaWidget* status_area_widget =
Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
SystemTray* tray = GetSystemTray();
CreateTestWidget();
shelf->LayoutShelf();
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
for (int i = 0; i < 2; i++) {
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
gfx::Point center =
status_area_widget->GetWindowBoundsInScreen().CenterPoint();
generator.MoveMouseTo(center.x(), center.y());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_TRUE(shelf->IsVisible());
if (!i) {
tray->CloseSystemBubble();
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
} else {
TestItem *item = new TestItem;
tray->AddTrayItem(item);
tray->ShowNotificationView(item);
EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
}
generator.MoveMouseTo(
center.x(), status_area_widget->GetWindowBoundsInScreen().y() - 8);
shelf->UpdateVisibilityState();
if (i) {
EXPECT_TRUE(shelf->IsVisible());
EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
} else {
EXPECT_FALSE(shelf->IsVisible());
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
}
}
}
TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColor) {
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
scoped_ptr<aura::Window> w1(CreateTestWindow());
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
scoped_ptr<aura::Window> w2(CreateTestWindow());
w2->Show();
wm::ActivateWindow(w2.get());
w2->SetBounds(GetShelfLayoutManager()->GetIdealBounds());
EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
w1.reset();
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
}
TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColorAutoHide) {
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget ()->GetBackgroundType());
GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
scoped_ptr<aura::Window> w1(CreateTestWindow());
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
}
TEST_F(ShelfLayoutManagerTest, DoesNotHideInMaximizeMode) {
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
scoped_ptr<aura::Window> w1(CreateTestWindow());
w1->Show();
ShelfLayoutManager* shelf = GetShelfLayoutManager();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
GetShelfLayoutManager()->OnMaximizeModeStarted();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
GetShelfLayoutManager()->OnMaximizeModeEnded();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
}
#if defined(OS_CHROMEOS)
#define MAYBE_StatusAreaHitBoxCoversEdge StatusAreaHitBoxCoversEdge
#else
#define MAYBE_StatusAreaHitBoxCoversEdge DISABLED_StatusAreaHitBoxCoversEdge
#endif
TEST_F(ShelfLayoutManagerTest, MAYBE_StatusAreaHitBoxCoversEdge) {
UpdateDisplay("400x400");
ShelfLayoutManager* shelf = GetShelfLayoutManager();
StatusAreaWidget* status_area_widget =
Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.MoveMouseTo(399,399);
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
generator.ClickLeftButton();
EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
generator.ClickLeftButton();
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
generator.ClickLeftButton();
EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
generator.ClickLeftButton();
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
generator.MoveMouseTo(0, 399);
shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
generator.ClickLeftButton();
EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
generator.ClickLeftButton();
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
}
}