OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/accessibility_delegate.h" | 5 #include "ash/accessibility_delegate.h" |
6 #include "ash/drag_drop/drag_drop_controller.h" | 6 #include "ash/drag_drop/drag_drop_controller.h" |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
9 #include "ash/shelf/shelf.h" | 9 #include "ash/shelf/shelf.h" |
10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
14 #include "ash/test/shelf_test_api.h" | 14 #include "ash/test/shelf_test_api.h" |
15 #include "ash/test/shelf_view_test_api.h" | 15 #include "ash/test/shelf_view_test_api.h" |
16 #include "ash/test/shell_test_api.h" | 16 #include "ash/test/shell_test_api.h" |
17 #include "ash/test/test_shelf_delegate.h" | 17 #include "ash/test/test_shelf_delegate.h" |
18 #include "ash/wm/mru_window_tracker.h" | 18 #include "ash/wm/mru_window_tracker.h" |
| 19 #include "ash/wm/overview/window_grid.h" |
19 #include "ash/wm/overview/window_selector.h" | 20 #include "ash/wm/overview/window_selector.h" |
20 #include "ash/wm/overview/window_selector_controller.h" | 21 #include "ash/wm/overview/window_selector_controller.h" |
21 #include "ash/wm/overview/window_selector_item.h" | 22 #include "ash/wm/overview/window_selector_item.h" |
22 #include "ash/wm/window_state.h" | 23 #include "ash/wm/window_state.h" |
23 #include "ash/wm/window_util.h" | 24 #include "ash/wm/window_util.h" |
24 #include "ash/wm/wm_event.h" | 25 #include "ash/wm/wm_event.h" |
25 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
26 #include "base/compiler_specific.h" | 27 #include "base/compiler_specific.h" |
27 #include "base/memory/scoped_vector.h" | 28 #include "base/memory/scoped_vector.h" |
28 #include "base/run_loop.h" | 29 #include "base/run_loop.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 75 |
75 shelf_view_test_.reset(new test::ShelfViewTestAPI( | 76 shelf_view_test_.reset(new test::ShelfViewTestAPI( |
76 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view())); | 77 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view())); |
77 shelf_view_test_->SetAnimationDuration(1); | 78 shelf_view_test_->SetAnimationDuration(1); |
78 } | 79 } |
79 | 80 |
80 aura::Window* CreateWindow(const gfx::Rect& bounds) { | 81 aura::Window* CreateWindow(const gfx::Rect& bounds) { |
81 return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds); | 82 return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds); |
82 } | 83 } |
83 | 84 |
| 85 aura::Window* CreateWindowWithId(const gfx::Rect& bounds, int id) { |
| 86 return CreateTestWindowInShellWithDelegate(&delegate_, id, bounds); |
| 87 } |
84 aura::Window* CreateNonActivatableWindow(const gfx::Rect& bounds) { | 88 aura::Window* CreateNonActivatableWindow(const gfx::Rect& bounds) { |
85 aura::Window* window = CreateWindow(bounds); | 89 aura::Window* window = CreateWindow(bounds); |
86 aura::client::SetActivationDelegate(window, | 90 aura::client::SetActivationDelegate(window, |
87 &non_activatable_activation_delegate_); | 91 &non_activatable_activation_delegate_); |
88 EXPECT_FALSE(ash::wm::CanActivateWindow(window)); | 92 EXPECT_FALSE(ash::wm::CanActivateWindow(window)); |
89 return window; | 93 return window; |
90 } | 94 } |
91 | 95 |
92 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { | 96 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { |
93 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 97 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 transform.TransformRect(&bounds); | 151 transform.TransformRect(&bounds); |
148 return bounds; | 152 return bounds; |
149 } | 153 } |
150 | 154 |
151 void ClickWindow(aura::Window* window) { | 155 void ClickWindow(aura::Window* window) { |
152 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); | 156 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); |
153 gfx::RectF target = GetTransformedBounds(window); | 157 gfx::RectF target = GetTransformedBounds(window); |
154 event_generator.ClickLeftButton(); | 158 event_generator.ClickLeftButton(); |
155 } | 159 } |
156 | 160 |
| 161 void SendKey(ui::KeyboardCode key) { |
| 162 aura::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); |
| 163 event_generator.PressKey(key, 0); |
| 164 event_generator.ReleaseKey(key, 0); |
| 165 } |
| 166 |
157 bool IsSelecting() { | 167 bool IsSelecting() { |
158 return ash::Shell::GetInstance()->window_selector_controller()-> | 168 return ash::Shell::GetInstance()->window_selector_controller()-> |
159 IsSelecting(); | 169 IsSelecting(); |
160 } | 170 } |
161 | 171 |
162 aura::Window* GetFocusedWindow() { | 172 aura::Window* GetFocusedWindow() { |
163 return aura::client::GetFocusClient( | 173 return aura::client::GetFocusClient( |
164 Shell::GetPrimaryRootWindow())->GetFocusedWindow(); | 174 Shell::GetPrimaryRootWindow())->GetFocusedWindow(); |
165 } | 175 } |
166 | 176 |
167 ScopedVector<WindowSelectorItem>* GetWindowItems() { | 177 const std::vector<WindowSelectorItem*>& GetWindowItemsForRoot(int index) { |
168 return &(ash::Shell::GetInstance()->window_selector_controller()-> | 178 return ash::Shell::GetInstance()->window_selector_controller()-> |
169 window_selector_->windows_); | 179 window_selector_->grid_list_[index]->window_list_.get(); |
170 } | 180 } |
171 | 181 |
| 182 const aura::Window* GetSelectedWindow() { |
| 183 WindowSelector* ws = ash::Shell::GetInstance()-> |
| 184 window_selector_controller()->window_selector_.get(); |
| 185 return ws->grid_list_[ws->selected_grid_index_]-> |
| 186 SelectedWindow()->SelectionWindow(); |
| 187 } |
| 188 |
172 views::Widget* GetLabelWidget(ash::WindowSelectorItem* window) { | 189 views::Widget* GetLabelWidget(ash::WindowSelectorItem* window) { |
173 return window->window_label_.get(); | 190 return window->window_label_.get(); |
174 } | 191 } |
175 | 192 |
176 test::ShelfViewTestAPI* shelf_view_test() { | 193 test::ShelfViewTestAPI* shelf_view_test() { |
177 return shelf_view_test_.get(); | 194 return shelf_view_test_.get(); |
178 } | 195 } |
179 | 196 |
180 private: | 197 private: |
181 aura::test::TestWindowDelegate delegate_; | 198 aura::test::TestWindowDelegate delegate_; |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 ASSERT_TRUE(IsSelecting()); | 709 ASSERT_TRUE(IsSelecting()); |
693 RunAllPendingInMessageLoop(); | 710 RunAllPendingInMessageLoop(); |
694 } | 711 } |
695 | 712 |
696 // Test that a label is created under the window on entering overview mode. | 713 // Test that a label is created under the window on entering overview mode. |
697 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) { | 714 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) { |
698 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100))); | 715 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100))); |
699 base::string16 window_title = base::UTF8ToUTF16("My window"); | 716 base::string16 window_title = base::UTF8ToUTF16("My window"); |
700 window->set_title(window_title); | 717 window->set_title(window_title); |
701 ToggleOverview(); | 718 ToggleOverview(); |
702 WindowSelectorItem* window_item = GetWindowItems()->back(); | 719 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); |
703 views::Widget* widget = GetLabelWidget(window_item); | 720 views::Widget* widget = GetLabelWidget(window_item); |
704 // Has the label widget been created? | 721 // Has the label widget been created? |
705 ASSERT_TRUE(widget); | 722 ASSERT_TRUE(widget); |
706 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); | 723 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); |
707 // Verify the label matches the window title. | 724 // Verify the label matches the window title. |
708 EXPECT_EQ(label->text(), window_title); | 725 EXPECT_EQ(label->text(), window_title); |
709 // Labels are located based on target_bounds, not the actual window item | 726 // Labels are located based on target_bounds, not the actual window item |
710 // bounds. | 727 // bounds. |
711 gfx::Rect target_bounds(window_item->target_bounds()); | 728 gfx::Rect target_bounds(window_item->target_bounds()); |
712 gfx::Rect expected_label_bounds(target_bounds.x(), | 729 gfx::Rect expected_label_bounds(target_bounds.x(), |
713 target_bounds.bottom(), | 730 target_bounds.bottom(), |
714 target_bounds.width(), | 731 target_bounds.width(), |
715 label->GetPreferredSize().height()); | 732 label->GetPreferredSize().height()); |
716 gfx::Rect real_label_bounds = widget->GetNativeWindow()->bounds(); | 733 gfx::Rect real_label_bounds = widget->GetNativeWindow()->bounds(); |
717 EXPECT_EQ(widget->GetNativeWindow()->bounds(), real_label_bounds); | 734 EXPECT_EQ(widget->GetNativeWindow()->bounds(), real_label_bounds); |
718 } | 735 } |
719 | 736 |
720 // Tests that a label is created for the active panel in a group of panels in | 737 // Tests that a label is created for the active panel in a group of panels in |
721 // overview mode. | 738 // overview mode. |
722 TEST_F(WindowSelectorTest, CreateLabelUnderPanel) { | 739 TEST_F(WindowSelectorTest, CreateLabelUnderPanel) { |
723 scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100))); | 740 scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100))); |
724 scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100))); | 741 scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100))); |
725 base::string16 panel1_title = base::UTF8ToUTF16("My panel"); | 742 base::string16 panel1_title = base::UTF8ToUTF16("My panel"); |
726 base::string16 panel2_title = base::UTF8ToUTF16("Another panel"); | 743 base::string16 panel2_title = base::UTF8ToUTF16("Another panel"); |
727 panel1->set_title(panel1_title); | 744 panel1->set_title(panel1_title); |
728 panel2->set_title(panel2_title); | 745 panel2->set_title(panel2_title); |
729 wm::ActivateWindow(panel1.get()); | 746 wm::ActivateWindow(panel1.get()); |
730 ToggleOverview(); | 747 ToggleOverview(); |
731 WindowSelectorItem* window_item = GetWindowItems()->back(); | 748 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); |
732 views::Widget* widget = GetLabelWidget(window_item); | 749 views::Widget* widget = GetLabelWidget(window_item); |
733 // Has the label widget been created? | 750 // Has the label widget been created? |
734 ASSERT_TRUE(widget); | 751 ASSERT_TRUE(widget); |
735 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); | 752 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); |
736 // Verify the label matches the active window title. | 753 // Verify the label matches the active window title. |
737 EXPECT_EQ(label->text(), panel1_title); | 754 EXPECT_EQ(label->text(), panel1_title); |
738 } | 755 } |
739 | 756 |
740 // Tests that overview updates the window positions if the display orientation | 757 // Tests that overview updates the window positions if the display orientation |
741 // changes. | 758 // changes. |
(...skipping 21 matching lines...) Expand all Loading... |
763 // bounds. | 780 // bounds. |
764 UpdateDisplay("600x200/r"); | 781 UpdateDisplay("600x200/r"); |
765 EXPECT_EQ("0,0 200x600", root_window->bounds().ToString()); | 782 EXPECT_EQ("0,0 200x600", root_window->bounds().ToString()); |
766 for (ScopedVector<aura::Window>::iterator iter = windows.begin(); | 783 for (ScopedVector<aura::Window>::iterator iter = windows.begin(); |
767 iter != windows.end(); ++iter) { | 784 iter != windows.end(); ++iter) { |
768 EXPECT_TRUE(root_window->bounds().Contains( | 785 EXPECT_TRUE(root_window->bounds().Contains( |
769 ToEnclosingRect(GetTransformedTargetBounds(*iter)))); | 786 ToEnclosingRect(GetTransformedTargetBounds(*iter)))); |
770 } | 787 } |
771 } | 788 } |
772 | 789 |
| 790 // Tests traversing some windows in overview mode with the arrow keys in every |
| 791 // possible direction. |
| 792 TEST_F(WindowSelectorTest, BasicArrowKeyNavigation) { |
| 793 if (!SupportsHostWindowResize()) |
| 794 return; |
| 795 const size_t test_windows = 7; |
| 796 UpdateDisplay("400x300"); |
| 797 ScopedVector<aura::Window> windows; |
| 798 for (size_t i = test_windows; i > 0; i--) |
| 799 windows.push_back(CreateWindowWithId(gfx::Rect(0, 0, 100, 100), i)); |
| 800 |
| 801 ui::KeyboardCode arrow_keys[] = { |
| 802 ui::VKEY_RIGHT, |
| 803 ui::VKEY_DOWN, |
| 804 ui::VKEY_LEFT, |
| 805 ui::VKEY_UP |
| 806 }; |
| 807 // Expected window layout: |
| 808 // +-------+ +-------+ +-------+ |
| 809 // | 1 | | 2 | | 3 | |
| 810 // +-------+ +-------+ +-------+ |
| 811 // +-------+ +-------+ +-------+ |
| 812 // | 4 | | 5 | | 6 | |
| 813 // +-------+ +-------+ +-------+ |
| 814 // +-------+ |
| 815 // | 7 | |
| 816 // +-------+ |
| 817 // Index for each window during a full loop plus wrapping around. |
| 818 int index_path_for_direction[][test_windows + 1] = { |
| 819 {1, 2, 3, 4, 5, 6, 7, 1}, // Right |
| 820 {1, 4, 7, 2, 5, 3, 6, 1}, // Down |
| 821 {7, 6, 5, 4, 3, 2, 1, 7}, // Left |
| 822 {6, 3, 5, 2, 7, 4, 1, 6} // Up |
| 823 }; |
| 824 |
| 825 for (size_t key_index = 0; key_index < arraysize(arrow_keys); key_index++) { |
| 826 ToggleOverview(); |
| 827 for (size_t i = 0; i < test_windows + 1; i++) { |
| 828 SendKey(arrow_keys[key_index]); |
| 829 // TODO(nsatragno): Add a more readable error message by constructing a |
| 830 // string from the window IDs. |
| 831 EXPECT_EQ(GetSelectedWindow()->id(), |
| 832 index_path_for_direction[key_index][i]); |
| 833 } |
| 834 ToggleOverview(); |
| 835 } |
| 836 } |
| 837 |
| 838 // Tests basic selection across multiple monitors. |
| 839 TEST_F(WindowSelectorTest, BasicMultiMonitorArrowKeyNavigation) { |
| 840 if (!SupportsMultipleDisplays()) |
| 841 return; |
| 842 |
| 843 UpdateDisplay("400x400,400x400"); |
| 844 gfx::Rect bounds1(0, 0, 100, 100); |
| 845 gfx::Rect bounds2(450, 0, 100, 100); |
| 846 scoped_ptr<aura::Window> window4(CreateWindow(bounds2)); |
| 847 scoped_ptr<aura::Window> window3(CreateWindow(bounds2)); |
| 848 scoped_ptr<aura::Window> window2(CreateWindow(bounds1)); |
| 849 scoped_ptr<aura::Window> window1(CreateWindow(bounds1)); |
| 850 |
| 851 |
| 852 ToggleOverview(); |
| 853 |
| 854 SendKey(ui::VKEY_RIGHT); |
| 855 EXPECT_EQ(GetSelectedWindow(), window1.get()); |
| 856 SendKey(ui::VKEY_RIGHT); |
| 857 EXPECT_EQ(GetSelectedWindow(), window2.get()); |
| 858 SendKey(ui::VKEY_RIGHT); |
| 859 EXPECT_EQ(GetSelectedWindow(), window3.get()); |
| 860 SendKey(ui::VKEY_RIGHT); |
| 861 EXPECT_EQ(GetSelectedWindow(), window4.get()); |
| 862 } |
| 863 |
773 } // namespace ash | 864 } // namespace ash |
OLD | NEW |