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

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 Rob's nits 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 716 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::Widget* widget = GetLabelWidget(window_item);
741 // Has the label widget been created? 741 // Has the label widget been created?
742 ASSERT_TRUE(widget); 742 ASSERT_TRUE(widget);
743 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); 743 views::Label* label = static_cast<views::Label*>(widget->GetContentsView());
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(),
751 target_bounds.width(), 757 target_bounds.width(),
752 label->GetPreferredSize().height()); 758 label->GetPreferredSize().height());
753 gfx::Rect real_label_bounds = widget->GetNativeWindow()->bounds(); 759 gfx::Rect real_label_bounds = widget->GetNativeWindow()->bounds();
754 EXPECT_EQ(widget->GetNativeWindow()->bounds(), real_label_bounds); 760 EXPECT_EQ(widget->GetNativeWindow()->bounds(), real_label_bounds);
755 } 761 }
756 762
757 // Tests that a label is created for the active panel in a group of panels in 763 // Tests that a label is created for the active panel in a group of panels in
758 // overview mode. 764 // overview mode.
759 TEST_F(WindowSelectorTest, CreateLabelUnderPanel) { 765 TEST_F(WindowSelectorTest, CreateLabelUnderPanel) {
760 scoped_ptr<aura::Window> panel1(CreatePanelWindow(gfx::Rect(0, 0, 100, 100))); 766 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))); 767 scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
762 base::string16 panel1_title = base::UTF8ToUTF16("My panel"); 768 base::string16 panel1_title = base::UTF8ToUTF16("My panel");
763 base::string16 panel2_title = base::UTF8ToUTF16("Another panel"); 769 base::string16 panel2_title = base::UTF8ToUTF16("Another panel");
764 panel1->set_title(panel1_title); 770 base::string16 updated_panel1_title = base::UTF8ToUTF16("WebDriver Torso");
765 panel2->set_title(panel2_title); 771 base::string16 updated_panel2_title = base::UTF8ToUTF16("Da panel");
772 panel1->SetTitle(panel1_title);
773 panel2->SetTitle(panel2_title);
766 wm::ActivateWindow(panel1.get()); 774 wm::ActivateWindow(panel1.get());
767 ToggleOverview(); 775 ToggleOverview();
768 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); 776 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
769 views::Widget* widget = GetLabelWidget(window_item); 777 views::Widget* widget = GetLabelWidget(window_item);
770 // Has the label widget been created? 778 // Has the label widget been created?
771 ASSERT_TRUE(widget); 779 ASSERT_TRUE(widget);
772 views::Label* label = static_cast<views::Label*>(widget->GetContentsView()); 780 views::Label* label = static_cast<views::Label*>(widget->GetContentsView());
773 // Verify the label matches the active window title. 781 // Verify the label matches the active window title.
774 EXPECT_EQ(label->text(), panel1_title); 782 EXPECT_EQ(label->text(), panel1_title);
783 // Verify that updating the title also updates the label.
784 panel1->SetTitle(updated_panel1_title);
785 EXPECT_EQ(label->text(), updated_panel1_title);
786 // After destroying the first panel, the title should match the second panel.
787 panel1.reset();
788 EXPECT_EQ(label->text(), panel2_title);
789 // Also test updating the title on the second panel.
790 panel2->SetTitle(updated_panel2_title);
791 EXPECT_EQ(label->text(), updated_panel2_title);
775 } 792 }
776 793
777 // Tests that overview updates the window positions if the display orientation 794 // Tests that overview updates the window positions if the display orientation
778 // changes. 795 // changes.
779 TEST_F(WindowSelectorTest, DisplayOrientationChanged) { 796 TEST_F(WindowSelectorTest, DisplayOrientationChanged) {
780 if (!SupportsHostWindowResize()) 797 if (!SupportsHostWindowResize())
781 return; 798 return;
782 799
783 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); 800 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
784 UpdateDisplay("600x200"); 801 UpdateDisplay("600x200");
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 // cause selection to end. 958 // cause selection to end.
942 TEST_F(WindowSelectorTest, CloseButtonOnPanels) { 959 TEST_F(WindowSelectorTest, CloseButtonOnPanels) {
943 scoped_ptr<views::Widget> widget1(CreatePanelWindowWidget( 960 scoped_ptr<views::Widget> widget1(CreatePanelWindowWidget(
944 gfx::Rect(0, 0, 300, 100))); 961 gfx::Rect(0, 0, 300, 100)));
945 scoped_ptr<views::Widget> widget2(CreatePanelWindowWidget( 962 scoped_ptr<views::Widget> widget2(CreatePanelWindowWidget(
946 gfx::Rect(100, 0, 100, 100))); 963 gfx::Rect(100, 0, 100, 100)));
947 aura::Window* window1 = widget1->GetNativeWindow(); 964 aura::Window* window1 = widget1->GetNativeWindow();
948 aura::Window* window2 = widget2->GetNativeWindow(); 965 aura::Window* window2 = widget2->GetNativeWindow();
949 base::string16 panel1_title = base::UTF8ToUTF16("Panel 1"); 966 base::string16 panel1_title = base::UTF8ToUTF16("Panel 1");
950 base::string16 panel2_title = base::UTF8ToUTF16("Panel 2"); 967 base::string16 panel2_title = base::UTF8ToUTF16("Panel 2");
951 window1->set_title(panel1_title); 968 window1->SetTitle(panel1_title);
952 window2->set_title(panel2_title); 969 window2->SetTitle(panel2_title);
953 wm::ActivateWindow(window1); 970 wm::ActivateWindow(window1);
954 ToggleOverview(); 971 ToggleOverview();
955 972
956 gfx::RectF bounds1 = GetTransformedBoundsInRootWindow(window1); 973 gfx::RectF bounds1 = GetTransformedBoundsInRootWindow(window1);
957 gfx::Point point1(bounds1.top_right().x() - 1, bounds1.top_right().y() - 1); 974 gfx::Point point1(bounds1.top_right().x() - 1, bounds1.top_right().y() - 1);
958 aura::test::EventGenerator event_generator1(window1->GetRootWindow(), point1); 975 aura::test::EventGenerator event_generator1(window1->GetRootWindow(), point1);
959 976
960 EXPECT_FALSE(widget1->IsClosed()); 977 EXPECT_FALSE(widget1->IsClosed());
961 event_generator1.ClickLeftButton(); 978 event_generator1.ClickLeftButton();
962 EXPECT_TRUE(widget1->IsClosed()); 979 EXPECT_TRUE(widget1->IsClosed());
(...skipping 13 matching lines...) Expand all
976 aura::test::EventGenerator event_generator2(window2->GetRootWindow(), point2); 993 aura::test::EventGenerator event_generator2(window2->GetRootWindow(), point2);
977 994
978 EXPECT_FALSE(widget2->IsClosed()); 995 EXPECT_FALSE(widget2->IsClosed());
979 event_generator2.ClickLeftButton(); 996 event_generator2.ClickLeftButton();
980 EXPECT_TRUE(widget2->IsClosed()); 997 EXPECT_TRUE(widget2->IsClosed());
981 RunAllPendingInMessageLoop(); 998 RunAllPendingInMessageLoop();
982 EXPECT_FALSE(IsSelecting()); 999 EXPECT_FALSE(IsSelecting());
983 } 1000 }
984 1001
985 } // namespace ash 1002 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698