Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ash/wm/overview/window_selector_unittest.cc

Issue 251103005: Added arrow key navigation to Overview Mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a bug with panels and changing windows bounds Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 transform.TransformRect(&bounds); 148 transform.TransformRect(&bounds);
148 return bounds; 149 return bounds;
149 } 150 }
150 151
151 void ClickWindow(aura::Window* window) { 152 void ClickWindow(aura::Window* window) {
152 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); 153 aura::test::EventGenerator event_generator(window->GetRootWindow(), window);
153 gfx::RectF target = GetTransformedBounds(window); 154 gfx::RectF target = GetTransformedBounds(window);
154 event_generator.ClickLeftButton(); 155 event_generator.ClickLeftButton();
155 } 156 }
156 157
158 void SendKey(ui::KeyboardCode key) {
159 aura::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow());
160 event_generator.PressKey(key, 0);
161 event_generator.ReleaseKey(key, 0);
162 }
163
157 bool IsSelecting() { 164 bool IsSelecting() {
158 return ash::Shell::GetInstance()->window_selector_controller()-> 165 return ash::Shell::GetInstance()->window_selector_controller()->
159 IsSelecting(); 166 IsSelecting();
160 } 167 }
161 168
162 aura::Window* GetFocusedWindow() { 169 aura::Window* GetFocusedWindow() {
163 return aura::client::GetFocusClient( 170 return aura::client::GetFocusClient(
164 Shell::GetPrimaryRootWindow())->GetFocusedWindow(); 171 Shell::GetPrimaryRootWindow())->GetFocusedWindow();
165 } 172 }
166 173
167 ScopedVector<WindowSelectorItem>* GetWindowItems() { 174 const std::vector<WindowSelectorItem*>& GetWindowItemsForRoot(int index) {
168 return &(ash::Shell::GetInstance()->window_selector_controller()-> 175 return ash::Shell::GetInstance()->window_selector_controller()->
169 window_selector_->windows_); 176 window_selector_->grid_list_[index]->window_list();
170 } 177 }
171 178
179 const aura::Window* GetSelectedWindow() {
180 WindowSelector* ws = ash::Shell::GetInstance()->
181 window_selector_controller()->window_selector_.get();
182 return ws->grid_list_[ws->selected_grid_index_]->
183 SelectedWindow()->SelectionWindow();
184 }
185
172 views::Widget* GetLabelWidget(ash::WindowSelectorItem* window) { 186 views::Widget* GetLabelWidget(ash::WindowSelectorItem* window) {
173 return window->window_label_.get(); 187 return window->window_label_.get();
174 } 188 }
175 189
176 test::ShelfViewTestAPI* shelf_view_test() { 190 test::ShelfViewTestAPI* shelf_view_test() {
177 return shelf_view_test_.get(); 191 return shelf_view_test_.get();
178 } 192 }
179 193
180 private: 194 private:
181 aura::test::TestWindowDelegate delegate_; 195 aura::test::TestWindowDelegate delegate_;
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 ASSERT_TRUE(IsSelecting()); 706 ASSERT_TRUE(IsSelecting());
693 RunAllPendingInMessageLoop(); 707 RunAllPendingInMessageLoop();
694 } 708 }
695 709
696 // Test that a label is created under the window on entering overview mode. 710 // Test that a label is created under the window on entering overview mode.
697 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) { 711 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) {
698 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100))); 712 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100)));
699 base::string16 window_title = base::UTF8ToUTF16("My window"); 713 base::string16 window_title = base::UTF8ToUTF16("My window");
700 window->set_title(window_title); 714 window->set_title(window_title);
701 ToggleOverview(); 715 ToggleOverview();
702 WindowSelectorItem* window_item = GetWindowItems()->back(); 716 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
703 views::Widget* widget = GetLabelWidget(window_item); 717 views::Widget* widget = GetLabelWidget(window_item);
704 // Has the label widget been created? 718 // Has the label widget been created?
705 ASSERT_TRUE(widget); 719 ASSERT_TRUE(widget);
706 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); 720 views::Label* label = static_cast<views::Label*>(widget->GetContentsView());
707 // Verify the label matches the window title. 721 // Verify the label matches the window title.
708 EXPECT_EQ(label->text(), window_title); 722 EXPECT_EQ(label->text(), window_title);
709 // Labels are located based on target_bounds, not the actual window item 723 // Labels are located based on target_bounds, not the actual window item
710 // bounds. 724 // bounds.
711 gfx::Rect target_bounds(window_item->target_bounds()); 725 gfx::Rect target_bounds(window_item->target_bounds());
712 gfx::Rect expected_label_bounds(target_bounds.x(), 726 gfx::Rect expected_label_bounds(target_bounds.x(),
713 target_bounds.bottom(), 727 target_bounds.bottom(),
714 target_bounds.width(), 728 target_bounds.width(),
715 label->GetPreferredSize().height()); 729 label->GetPreferredSize().height());
716 gfx::Rect real_label_bounds = widget->GetNativeWindow()->bounds(); 730 gfx::Rect real_label_bounds = widget->GetNativeWindow()->bounds();
717 EXPECT_EQ(widget->GetNativeWindow()->bounds(), real_label_bounds); 731 EXPECT_EQ(widget->GetNativeWindow()->bounds(), real_label_bounds);
718 } 732 }
719 733
720 // Tests that a label is created for the active panel in a group of panels in 734 // Tests that a label is created for the active panel in a group of panels in
721 // overview mode. 735 // overview mode.
722 TEST_F(WindowSelectorTest, CreateLabelUnderPanel) { 736 TEST_F(WindowSelectorTest, CreateLabelUnderPanel) {
723 scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100))); 737 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))); 738 scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
725 base::string16 panel1_title = base::UTF8ToUTF16("My panel"); 739 base::string16 panel1_title = base::UTF8ToUTF16("My panel");
726 base::string16 panel2_title = base::UTF8ToUTF16("Another panel"); 740 base::string16 panel2_title = base::UTF8ToUTF16("Another panel");
727 panel1->set_title(panel1_title); 741 panel1->set_title(panel1_title);
728 panel2->set_title(panel2_title); 742 panel2->set_title(panel2_title);
729 wm::ActivateWindow(panel1.get()); 743 wm::ActivateWindow(panel1.get());
730 ToggleOverview(); 744 ToggleOverview();
731 WindowSelectorItem* window_item = GetWindowItems()->back(); 745 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
732 views::Widget* widget = GetLabelWidget(window_item); 746 views::Widget* widget = GetLabelWidget(window_item);
733 // Has the label widget been created? 747 // Has the label widget been created?
734 ASSERT_TRUE(widget); 748 ASSERT_TRUE(widget);
735 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); 749 views::Label* label = static_cast<views::Label*>(widget->GetContentsView());
736 // Verify the label matches the active window title. 750 // Verify the label matches the active window title.
737 EXPECT_EQ(label->text(), panel1_title); 751 EXPECT_EQ(label->text(), panel1_title);
738 } 752 }
739 753
740 // Tests that overview updates the window positions if the display orientation 754 // Tests that overview updates the window positions if the display orientation
741 // changes. 755 // changes.
(...skipping 21 matching lines...) Expand all
763 // bounds. 777 // bounds.
764 UpdateDisplay("600x200/r"); 778 UpdateDisplay("600x200/r");
765 EXPECT_EQ("0,0 200x600", root_window->bounds().ToString()); 779 EXPECT_EQ("0,0 200x600", root_window->bounds().ToString());
766 for (ScopedVector<aura::Window>::iterator iter = windows.begin(); 780 for (ScopedVector<aura::Window>::iterator iter = windows.begin();
767 iter != windows.end(); ++iter) { 781 iter != windows.end(); ++iter) {
768 EXPECT_TRUE(root_window->bounds().Contains( 782 EXPECT_TRUE(root_window->bounds().Contains(
769 ToEnclosingRect(GetTransformedTargetBounds(*iter)))); 783 ToEnclosingRect(GetTransformedTargetBounds(*iter))));
770 } 784 }
771 } 785 }
772 786
787 // Tests traversing some windows in overview mode with the arrow keys.
788 TEST_F(WindowSelectorTest, BasicArrowKeyNavigation) {
flackr 2014/06/04 22:25:06 Should probably have a test which tries complete c
Nina 2014/06/05 18:04:36 Check the new test out, I'm sure you're gonna like
flackr 2014/06/05 20:16:32 I do!
789 gfx::Rect bounds(0, 0, 100, 100);
790 scoped_ptr<aura::Window> window4(CreateWindow(bounds));
791 scoped_ptr<aura::Window> window3(CreateWindow(bounds));
792 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
793 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
794 ToggleOverview();
795 SendKey(ui::VKEY_DOWN);
796 EXPECT_EQ(GetSelectedWindow(), window1.get());
797 SendKey(ui::VKEY_RIGHT);
798 EXPECT_EQ(GetSelectedWindow(), window2.get());
799 SendKey(ui::VKEY_RIGHT);
800 EXPECT_EQ(GetSelectedWindow(), window3.get());
801 SendKey(ui::VKEY_LEFT);
802 EXPECT_EQ(GetSelectedWindow(), window2.get());
803 // Wrap the selection.
804 SendKey(ui::VKEY_RIGHT);
805 SendKey(ui::VKEY_RIGHT);
806 SendKey(ui::VKEY_RIGHT);
807 EXPECT_EQ(GetSelectedWindow(), window1.get());
808 ToggleOverview();
809 ToggleOverview();
810 SendKey(ui::VKEY_LEFT);
811 EXPECT_EQ(GetSelectedWindow(), window4.get());
812 }
813
773 } // namespace ash 814 } // namespace ash
OLDNEW
« ash/wm/overview/window_selector.cc ('K') | « ash/wm/overview/window_selector_item.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698