Chromium Code Reviews| Index: ash/wm/overview/window_selector_unittest.cc |
| diff --git a/ash/wm/overview/window_selector_unittest.cc b/ash/wm/overview/window_selector_unittest.cc |
| index 3ae60cc9458fe43d0e98bf248766d50a35c5a3ed..51c19bf4e2b6fb382c221c86aafd106325f2c1c5 100644 |
| --- a/ash/wm/overview/window_selector_unittest.cc |
| +++ b/ash/wm/overview/window_selector_unittest.cc |
| @@ -35,6 +35,7 @@ |
| #include "base/run_loop.h" |
| #include "base/strings/string_piece.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/test/user_action_tester.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/cursor_client.h" |
| #include "ui/aura/client/focus_client.h" |
| @@ -58,6 +59,8 @@ |
| namespace ash { |
| namespace { |
| +const char kActiveWindowChanged[] = "WindowSelector_ActiveWindowChanged"; |
| + |
| class NonActivatableActivationDelegate |
| : public aura::client::ActivationDelegate { |
| public: |
| @@ -89,6 +92,12 @@ class WindowSelectorTest : public test::AshTestBase { |
| shelf_view_test_->SetAnimationDuration(1); |
| } |
| + aura::Window* CreateWindowWithType(const gfx::Rect& bounds, |
| + ui::wm::WindowType type) { |
| + return CreateTestWindowInShellWithDelegateAndType(&delegate_, type, -1, |
| + bounds); |
| + } |
| + |
| aura::Window* CreateWindow(const gfx::Rect& bounds) { |
| return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds); |
| } |
| @@ -219,6 +228,12 @@ class WindowSelectorTest : public test::AshTestBase { |
| GetTargetTransform().IsIdentity(); |
| } |
| + aura::Window* initially_active_window() { |
| + return ash::Shell::GetInstance() |
| + ->window_selector_controller() |
| + ->initially_active_window_; |
| + } |
| + |
| views::Widget* GetCloseButton(ash::WindowSelectorItem* window) { |
| return &(window->close_button_widget_); |
| } |
| @@ -374,6 +389,118 @@ TEST_F(WindowSelectorTest, BasicGesture) { |
| EXPECT_EQ(window2.get(), GetFocusedWindow()); |
| } |
| +// Tests that the user action defined by |kActiveWindowChanged| is recorded |
| +// when a normal window is active upon entering overview mode and a different |
| +// normal window is active upon exiting overview mode. |
| +TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionChanged) { |
| + base::UserActionTester user_action_tester; |
| + gfx::Rect bounds(0, 0, 400, 400); |
| + scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| + scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| + wm::ActivateWindow(window1.get()); |
| + ASSERT_EQ(window1.get(), GetFocusedWindow()); |
| + ToggleOverview(); |
| + ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| + window2.get()); |
| + generator.GestureTapAt( |
| + gfx::ToEnclosingRect(GetTransformedTargetBounds(window2.get())) |
| + .CenterPoint()); |
| + ASSERT_EQ(window2.get(), GetFocusedWindow()); |
| + EXPECT_EQ(1, user_action_tester.GetActionCount(kActiveWindowChanged)); |
| +} |
| + |
| +// Tests that the user action defined by |kActiveWindowChanged| is not recorded |
| +// when the window that is active upon entering overview mode remains |
| +// active upon exiting overview mode. |
| +TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionNoChange) { |
| + base::UserActionTester user_action_tester; |
| + gfx::Rect bounds(0, 0, 400, 400); |
| + scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| + scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| + wm::ActivateWindow(window1.get()); |
| + ASSERT_EQ(window1.get(), GetFocusedWindow()); |
| + ToggleOverview(); |
| + ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| + window1.get()); |
| + generator.GestureTapAt( |
| + gfx::ToEnclosingRect(GetTransformedTargetBounds(window1.get())) |
| + .CenterPoint()); |
| + ASSERT_EQ(window1.get(), GetFocusedWindow()); |
| + EXPECT_EQ(0, user_action_tester.GetActionCount(kActiveWindowChanged)); |
| +} |
| + |
| +// Tests that the user action defined by |kActiveWindowChanged| is not recorded |
| +// when the window that is active upon entering overview mode is a popup, even |
| +// a normal window is active upon exiting overview mode. |
| +TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionPopupWindow) { |
| + base::UserActionTester user_action_tester; |
| + gfx::Rect bounds(0, 0, 400, 400); |
| + scoped_ptr<aura::Window> window1( |
| + CreateWindowWithType(bounds, ui::wm::WINDOW_TYPE_POPUP)); |
| + scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| + wm::ActivateWindow(window1.get()); |
| + ASSERT_EQ(window1.get(), GetFocusedWindow()); |
| + ToggleOverview(); |
| + ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| + window2.get()); |
| + generator.GestureTapAt( |
| + gfx::ToEnclosingRect(GetTransformedTargetBounds(window2.get())) |
| + .CenterPoint()); |
| + ASSERT_EQ(window2.get(), GetFocusedWindow()); |
| + EXPECT_EQ(0, user_action_tester.GetActionCount(kActiveWindowChanged)); |
| +} |
| + |
| +// Tests that the user action defined by |kActiveWindowChanged| is not recorded |
| +// when the oply open window is closed while in overview mode. |
|
bruthig
2015/05/12 17:37:38
Sp? "oply"
tdanderson
2015/05/14 01:36:32
Done.
|
| +TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionWindowClose) { |
| + base::UserActionTester user_action_tester; |
| + scoped_ptr<views::Widget> widget = |
| + CreateWindowWidget(gfx::Rect(0, 0, 400, 400)); |
| + |
| + ToggleOverview(); |
| + |
| + aura::Window* window = widget->GetNativeWindow(); |
| + gfx::RectF bounds = GetTransformedBoundsInRootWindow(window); |
| + gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1); |
| + ui::test::EventGenerator event_generator(window->GetRootWindow(), point); |
| + |
| + ASSERT_FALSE(widget->IsClosed()); |
| + event_generator.ClickLeftButton(); |
| + ASSERT_TRUE(widget->IsClosed()); |
| + EXPECT_EQ(0, user_action_tester.GetActionCount(kActiveWindowChanged)); |
| +} |
| + |
| +// Tests that if a normal window is active upon entering overview mode, the |
| +// member |initially_active_window_| should be set to this window while |
| +// overview mode is active and cleared upon exiting overview mode. |
| +TEST_F(WindowSelectorTest, InitiallyActiveWindowSetInOverviewMode) { |
| + gfx::Rect bounds(0, 0, 400, 400); |
| + scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| + wm::ActivateWindow(window1.get()); |
| + ASSERT_EQ(window1.get(), GetFocusedWindow()); |
| + ToggleOverview(); |
| + ASSERT_TRUE(IsSelecting()); |
| + EXPECT_EQ(window1.get(), initially_active_window()); |
| + ToggleOverview(); |
| + ASSERT_FALSE(IsSelecting()); |
| + EXPECT_EQ(nullptr, initially_active_window()); |
| +} |
| + |
| +// Tests that if a popup window is active upon entering overview mode, the |
| +// member |initially_active_window_| should not be set upon entering overview |
| +// mode. |
| +TEST_F(WindowSelectorTest, InitiallyActiveWindowNotSetForPopup) { |
| + gfx::Rect bounds(0, 0, 400, 400); |
| + scoped_ptr<aura::Window> window1( |
| + CreateWindowWithType(bounds, ui::wm::WINDOW_TYPE_POPUP)); |
| + scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| + wm::ActivateWindow(window1.get()); |
| + ASSERT_EQ(window1.get(), GetFocusedWindow()); |
| + ToggleOverview(); |
| + ASSERT_TRUE(IsSelecting()); |
| + EXPECT_EQ(nullptr, initially_active_window()); |
| +} |
| + |
| // Tests that we do not crash and overview mode remains engaged if the desktop |
| // is tapped while a finger is already down over a window. |
| TEST_F(WindowSelectorTest, NoCrashWithDesktopTap) { |