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

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

Issue 331643004: Update the window labels if they change in overview mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Sky's comments 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "ash/accessibility_delegate.h" 7 #include "ash/accessibility_delegate.h"
8 #include "ash/drag_drop/drag_drop_controller.h" 8 #include "ash/drag_drop/drag_drop_controller.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/screen_util.h" 10 #include "ash/screen_util.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 WindowSelector* ws = ash::Shell::GetInstance()-> 199 WindowSelector* ws = ash::Shell::GetInstance()->
200 window_selector_controller()->window_selector_.get(); 200 window_selector_controller()->window_selector_.get();
201 return ws->grid_list_[ws->selected_grid_index_]-> 201 return ws->grid_list_[ws->selected_grid_index_]->
202 SelectedWindow()->SelectionWindow(); 202 SelectedWindow()->SelectionWindow();
203 } 203 }
204 204
205 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) { 205 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) {
206 return window->close_button_.get(); 206 return window->close_button_.get();
207 } 207 }
208 208
209 views::Widget* GetLabelWidget(ash::WindowSelectorItem* window) { 209 views::Label* GetLabelView(ash::WindowSelectorItem* window) {
210 return window->window_label_.get(); 210 return window->window_label_view_;
211 } 211 }
212 212
213 test::ShelfViewTestAPI* shelf_view_test() { 213 test::ShelfViewTestAPI* shelf_view_test() {
214 return shelf_view_test_.get(); 214 return shelf_view_test_.get();
215 } 215 }
216 216
217 private: 217 private:
218 aura::test::TestWindowDelegate delegate_; 218 aura::test::TestWindowDelegate delegate_;
219 NonActivatableActivationDelegate non_activatable_activation_delegate_; 219 NonActivatableActivationDelegate non_activatable_activation_delegate_;
220 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_; 220 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_;
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 RunAllPendingInMessageLoop(); 727 RunAllPendingInMessageLoop();
728 EXPECT_FALSE(drag_canceled_by_test); 728 EXPECT_FALSE(drag_canceled_by_test);
729 ASSERT_TRUE(IsSelecting()); 729 ASSERT_TRUE(IsSelecting());
730 RunAllPendingInMessageLoop(); 730 RunAllPendingInMessageLoop();
731 } 731 }
732 732
733 // Test that a label is created under the window on entering overview mode. 733 // Test that a label is created under the window on entering overview mode.
734 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) { 734 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) {
735 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100))); 735 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100)));
736 base::string16 window_title = base::UTF8ToUTF16("My window"); 736 base::string16 window_title = base::UTF8ToUTF16("My window");
737 window->set_title(window_title); 737 window->SetTitle(window_title);
738 ToggleOverview(); 738 ToggleOverview();
739 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); 739 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
740 views::Widget* widget = GetLabelWidget(window_item); 740 views::Label* label = GetLabelView(window_item);
741 // Has the label widget been created? 741 // Has the label view been created?
742 ASSERT_TRUE(widget); 742 ASSERT_TRUE(label);
743 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); 743
744 // Verify the label matches the window title. 744 // Verify the label matches the window title.
745 EXPECT_EQ(label->text(), window_title); 745 EXPECT_EQ(label->text(), window_title);
746
747 // Update the window title and check that the label is updated, too.
748 base::string16 updated_title = base::UTF8ToUTF16("Updated title");
749 window->SetTitle(updated_title);
750 EXPECT_EQ(label->text(), updated_title);
751
746 // Labels are located based on target_bounds, not the actual window item 752 // Labels are located based on target_bounds, not the actual window item
747 // bounds. 753 // bounds.
748 gfx::Rect target_bounds(window_item->target_bounds()); 754 gfx::Rect target_bounds(window_item->target_bounds());
749 gfx::Rect expected_label_bounds(target_bounds.x(), 755 gfx::Rect expected_label_bounds(target_bounds.x(),
750 target_bounds.bottom(), 756 target_bounds.bottom() - label->
757 GetPreferredSize().height(),
751 target_bounds.width(), 758 target_bounds.width(),
752 label->GetPreferredSize().height()); 759 label->GetPreferredSize().height());
753 gfx::Rect real_label_bounds = widget->GetNativeWindow()->bounds(); 760 gfx::Rect real_label_bounds = label->GetWidget()->GetNativeWindow()->bounds();
754 EXPECT_EQ(widget->GetNativeWindow()->bounds(), real_label_bounds); 761 EXPECT_EQ(real_label_bounds, expected_label_bounds);
Nina 2014/06/25 19:54:40 This was a NO-OP before... I realized and changed
755 } 762 }
756 763
757 // Tests that a label is created for the active panel in a group of panels in 764 // Tests that a label is created for the active panel in a group of panels in
758 // overview mode. 765 // overview mode.
759 TEST_F(WindowSelectorTest, CreateLabelUnderPanel) { 766 TEST_F(WindowSelectorTest, CreateLabelUnderPanel) {
760 scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100))); 767 scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
761 scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100))); 768 scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
762 base::string16 panel1_title = base::UTF8ToUTF16("My panel"); 769 base::string16 panel1_title = base::UTF8ToUTF16("My panel");
763 base::string16 panel2_title = base::UTF8ToUTF16("Another panel"); 770 base::string16 panel2_title = base::UTF8ToUTF16("Another panel");
764 panel1->set_title(panel1_title); 771 base::string16 updated_panel1_title = base::UTF8ToUTF16("WebDriver Torso");
765 panel2->set_title(panel2_title); 772 base::string16 updated_panel2_title = base::UTF8ToUTF16("Da panel");
773 panel1->SetTitle(panel1_title);
774 panel2->SetTitle(panel2_title);
766 wm::ActivateWindow(panel1.get()); 775 wm::ActivateWindow(panel1.get());
767 ToggleOverview(); 776 ToggleOverview();
768 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); 777 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
769 views::Widget* widget = GetLabelWidget(window_item); 778 views::Label* label = GetLabelView(window_item);
770 // Has the label widget been created? 779 // Has the label view been created?
771 ASSERT_TRUE(widget); 780 ASSERT_TRUE(label);
772 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); 781
773 // Verify the label matches the active window title. 782 // Verify the label matches the active window title.
774 EXPECT_EQ(label->text(), panel1_title); 783 EXPECT_EQ(label->text(), panel1_title);
784 // Verify that updating the title also updates the label.
785 panel1->SetTitle(updated_panel1_title);
786 EXPECT_EQ(label->text(), updated_panel1_title);
787 // After destroying the first panel, the title should match the second panel.
788 panel1.reset();
789 EXPECT_EQ(label->text(), panel2_title);
790 // Also test updating the title on the second panel.
791 panel2->SetTitle(updated_panel2_title);
792 EXPECT_EQ(label->text(), updated_panel2_title);
775 } 793 }
776 794
777 // Tests that overview updates the window positions if the display orientation 795 // Tests that overview updates the window positions if the display orientation
778 // changes. 796 // changes.
779 TEST_F(WindowSelectorTest, DisplayOrientationChanged) { 797 TEST_F(WindowSelectorTest, DisplayOrientationChanged) {
780 if (!SupportsHostWindowResize()) 798 if (!SupportsHostWindowResize())
781 return; 799 return;
782 800
783 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); 801 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
784 UpdateDisplay("600x200"); 802 UpdateDisplay("600x200");
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 // cause selection to end. 959 // cause selection to end.
942 TEST_F(WindowSelectorTest, CloseButtonOnPanels) { 960 TEST_F(WindowSelectorTest, CloseButtonOnPanels) {
943 scoped_ptr<views::Widget> widget1(CreatePanelWindowWidget( 961 scoped_ptr<views::Widget> widget1(CreatePanelWindowWidget(
944 gfx::Rect(0, 0, 300, 100))); 962 gfx::Rect(0, 0, 300, 100)));
945 scoped_ptr<views::Widget> widget2(CreatePanelWindowWidget( 963 scoped_ptr<views::Widget> widget2(CreatePanelWindowWidget(
946 gfx::Rect(100, 0, 100, 100))); 964 gfx::Rect(100, 0, 100, 100)));
947 aura::Window* window1 = widget1->GetNativeWindow(); 965 aura::Window* window1 = widget1->GetNativeWindow();
948 aura::Window* window2 = widget2->GetNativeWindow(); 966 aura::Window* window2 = widget2->GetNativeWindow();
949 base::string16 panel1_title = base::UTF8ToUTF16("Panel 1"); 967 base::string16 panel1_title = base::UTF8ToUTF16("Panel 1");
950 base::string16 panel2_title = base::UTF8ToUTF16("Panel 2"); 968 base::string16 panel2_title = base::UTF8ToUTF16("Panel 2");
951 window1->set_title(panel1_title); 969 window1->SetTitle(panel1_title);
952 window2->set_title(panel2_title); 970 window2->SetTitle(panel2_title);
953 wm::ActivateWindow(window1); 971 wm::ActivateWindow(window1);
954 ToggleOverview(); 972 ToggleOverview();
955 973
956 gfx::RectF bounds1 = GetTransformedBoundsInRootWindow(window1); 974 gfx::RectF bounds1 = GetTransformedBoundsInRootWindow(window1);
957 gfx::Point point1(bounds1.top_right().x() - 1, bounds1.top_right().y() - 1); 975 gfx::Point point1(bounds1.top_right().x() - 1, bounds1.top_right().y() - 1);
958 aura::test::EventGenerator event_generator1(window1->GetRootWindow(), point1); 976 aura::test::EventGenerator event_generator1(window1->GetRootWindow(), point1);
959 977
960 EXPECT_FALSE(widget1->IsClosed()); 978 EXPECT_FALSE(widget1->IsClosed());
961 event_generator1.ClickLeftButton(); 979 event_generator1.ClickLeftButton();
962 EXPECT_TRUE(widget1->IsClosed()); 980 EXPECT_TRUE(widget1->IsClosed());
963 RunAllPendingInMessageLoop(); 981 RunAllPendingInMessageLoop();
964 EXPECT_TRUE(IsSelecting()); 982 EXPECT_TRUE(IsSelecting());
965 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).front(); 983 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).front();
966 EXPECT_FALSE(window_item->empty()); 984 EXPECT_FALSE(window_item->empty());
967 EXPECT_TRUE(window_item->Contains(window2)); 985 EXPECT_TRUE(window_item->Contains(window2));
968 EXPECT_TRUE(GetCloseButton(window_item)->IsVisible()); 986 EXPECT_TRUE(GetCloseButton(window_item)->IsVisible());
969 987
970 views::Widget* widget = GetLabelWidget(window_item); 988
971 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); 989 views::Label* label = GetLabelView(window_item);
972 EXPECT_EQ(label->text(), panel2_title); 990 EXPECT_EQ(label->text(), panel2_title);
973 991
974 gfx::RectF bounds2 = GetTransformedBoundsInRootWindow(window2); 992 gfx::RectF bounds2 = GetTransformedBoundsInRootWindow(window2);
975 gfx::Point point2(bounds2.top_right().x() - 1, bounds2.top_right().y() - 1); 993 gfx::Point point2(bounds2.top_right().x() - 1, bounds2.top_right().y() - 1);
976 aura::test::EventGenerator event_generator2(window2->GetRootWindow(), point2); 994 aura::test::EventGenerator event_generator2(window2->GetRootWindow(), point2);
977 995
978 EXPECT_FALSE(widget2->IsClosed()); 996 EXPECT_FALSE(widget2->IsClosed());
979 event_generator2.ClickLeftButton(); 997 event_generator2.ClickLeftButton();
980 EXPECT_TRUE(widget2->IsClosed()); 998 EXPECT_TRUE(widget2->IsClosed());
981 RunAllPendingInMessageLoop(); 999 RunAllPendingInMessageLoop();
982 EXPECT_FALSE(IsSelecting()); 1000 EXPECT_FALSE(IsSelecting());
983 } 1001 }
984 1002
985 } // namespace ash 1003 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698