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 1b65eff9263a0190f1aa1a970e2aceae451b58fc..639ea1dc0cfc378b1dc1d99fb2b5a4e3419d8103 100644 |
| --- a/ash/wm/overview/window_selector_unittest.cc |
| +++ b/ash/wm/overview/window_selector_unittest.cc |
| @@ -16,6 +16,7 @@ |
| #include "ash/test/shell_test_api.h" |
| #include "ash/test/test_shelf_delegate.h" |
| #include "ash/wm/mru_window_tracker.h" |
| +#include "ash/wm/overview/window_grid.h" |
| #include "ash/wm/overview/window_selector.h" |
| #include "ash/wm/overview/window_selector_controller.h" |
| #include "ash/wm/overview/window_selector_item.h" |
| @@ -81,6 +82,9 @@ class WindowSelectorTest : public test::AshTestBase { |
| return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds); |
| } |
| + aura::Window* CreateWindowWithId(const gfx::Rect& bounds, int id) { |
| + return CreateTestWindowInShellWithDelegate(&delegate_, id, bounds); |
| + } |
| aura::Window* CreateNonActivatableWindow(const gfx::Rect& bounds) { |
| aura::Window* window = CreateWindow(bounds); |
| aura::client::SetActivationDelegate(window, |
| @@ -154,6 +158,12 @@ class WindowSelectorTest : public test::AshTestBase { |
| event_generator.ClickLeftButton(); |
| } |
| + void SendKey(ui::KeyboardCode key) { |
| + aura::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); |
| + event_generator.PressKey(key, 0); |
| + event_generator.ReleaseKey(key, 0); |
| + } |
| + |
| bool IsSelecting() { |
| return ash::Shell::GetInstance()->window_selector_controller()-> |
| IsSelecting(); |
| @@ -164,11 +174,18 @@ class WindowSelectorTest : public test::AshTestBase { |
| Shell::GetPrimaryRootWindow())->GetFocusedWindow(); |
| } |
| - ScopedVector<WindowSelectorItem>* GetWindowItems() { |
| - return &(ash::Shell::GetInstance()->window_selector_controller()-> |
| - window_selector_->windows_); |
| + const std::vector<WindowSelectorItem*>& GetWindowItemsForRoot(int index) { |
| + return ash::Shell::GetInstance()->window_selector_controller()-> |
| + window_selector_->grid_list_[index]->window_list(); |
| } |
| + const aura::Window* GetSelectedWindow() { |
| + WindowSelector* ws = ash::Shell::GetInstance()-> |
| + window_selector_controller()->window_selector_.get(); |
| + return ws->grid_list_[ws->selected_grid_index_]-> |
| + SelectedWindow()->SelectionWindow(); |
| + } |
| + |
| views::Widget* GetLabelWidget(ash::WindowSelectorItem* window) { |
| return window->window_label_.get(); |
| } |
| @@ -699,7 +716,7 @@ TEST_F(WindowSelectorTest, CreateLabelUnderWindow) { |
| base::string16 window_title = base::UTF8ToUTF16("My window"); |
| window->set_title(window_title); |
| ToggleOverview(); |
| - WindowSelectorItem* window_item = GetWindowItems()->back(); |
| + WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); |
| views::Widget* widget = GetLabelWidget(window_item); |
| // Has the label widget been created? |
| ASSERT_TRUE(widget); |
| @@ -728,7 +745,7 @@ TEST_F(WindowSelectorTest, CreateLabelUnderPanel) { |
| panel2->set_title(panel2_title); |
| wm::ActivateWindow(panel1.get()); |
| ToggleOverview(); |
| - WindowSelectorItem* window_item = GetWindowItems()->back(); |
| + WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); |
| views::Widget* widget = GetLabelWidget(window_item); |
| // Has the label widget been created? |
| ASSERT_TRUE(widget); |
| @@ -770,4 +787,38 @@ TEST_F(WindowSelectorTest, DisplayOrientationChanged) { |
| } |
| } |
| +// Tests traversing some windows in overview mode with the arrow keys in every |
| +// possible direction |
| +TEST_F(WindowSelectorTest, BasicArrowKeyNavigation) { |
| + const size_t test_windows = 7; |
| + UpdateDisplay("400x300"); |
|
flackr
2014/06/05 20:16:32
I think you need to add
if (!SupportsHostWindowRes
Nina
2014/06/05 22:06:23
Done.
|
| + ScopedVector<aura::Window> windows; |
| + for (size_t i = test_windows; i > 0; i--) |
| + windows.push_back(CreateWindowWithId(gfx::Rect(0, 0, 100, 100), i)); |
| + |
| + ui::KeyboardCode arrow_keys[] = { |
| + ui::VKEY_RIGHT, |
| + ui::VKEY_DOWN, |
| + ui::VKEY_LEFT, |
| + ui::VKEY_UP |
| + }; |
| + // Expected index for each window during a full loop plus wrapping around. |
|
flackr
2014/06/05 20:16:32
Can you add a comment with a table showing how the
Nina
2014/06/05 22:06:23
Done.
|
| + int index_path_for_direction[][test_windows + 1] = { |
| + {1, 2, 3, 4, 5, 6, 7, 1}, // Right |
| + {1, 4, 7, 2, 5, 3, 6, 1}, // Down |
| + {7, 6, 5, 4, 3, 2, 1, 7}, // Left |
| + {6, 3, 5, 2, 7, 4, 1, 6} // Up |
| + }; |
| + |
| + for (size_t key_index = 0; key_index < arraysize(arrow_keys); key_index++) { |
| + ToggleOverview(); |
| + for (size_t i = 0; i < test_windows + 1; i++) { |
| + SendKey(arrow_keys[key_index]); |
| + EXPECT_EQ(GetSelectedWindow()->id(), |
| + index_path_for_direction[key_index][i]); |
|
flackr
2014/06/05 20:16:32
nit: The error message on failure would be more re
Nina
2014/06/05 22:06:23
Added TODO
|
| + } |
| + ToggleOverview(); |
| + } |
| +} |
| + |
|
flackr
2014/06/05 20:16:32
Can you add a simple multi monitor test? Even just
Nina
2014/06/05 22:06:23
Done.
|
| } // namespace ash |