summaryrefslogtreecommitdiffstats
path: root/ash/wm/overview/window_selector_unittest.cc
diff options
context:
space:
mode:
authornsatragno@chromium.org <nsatragno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 00:01:00 +0000
committernsatragno@chromium.org <nsatragno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 00:01:00 +0000
commit2c5136075caa507a32bae7db5e2fcfc46fdaf4ea (patch)
tree58d419278965f014a006ef4cb499e0b45d5037b4 /ash/wm/overview/window_selector_unittest.cc
parent75d5416d69fab472c33b2b9b23e5cc9f211d5c28 (diff)
downloadchromium_src-2c5136075caa507a32bae7db5e2fcfc46fdaf4ea.zip
chromium_src-2c5136075caa507a32bae7db5e2fcfc46fdaf4ea.tar.gz
chromium_src-2c5136075caa507a32bae7db5e2fcfc46fdaf4ea.tar.bz2
Reland "Update the window labels if they change in overview mode."
Original issue: 331643004 Fixed: use of pointer after being freed in test. Update the window labels if they change in overview mode. This code adds a function to a WindowObserver that notfies it of a window title change, allowing to update the label in overview mode dynamically. BUG=387130 TBR=flackr@chromium.org, sky@chromium.org TEST=WindowSelectorTest.CreateLabelUnderWindow Review URL: https://codereview.chromium.org/352363002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280176 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm/overview/window_selector_unittest.cc')
-rw-r--r--ash/wm/overview/window_selector_unittest.cc59
1 files changed, 39 insertions, 20 deletions
diff --git a/ash/wm/overview/window_selector_unittest.cc b/ash/wm/overview/window_selector_unittest.cc
index 4ca0713..d482f55 100644
--- a/ash/wm/overview/window_selector_unittest.cc
+++ b/ash/wm/overview/window_selector_unittest.cc
@@ -206,8 +206,8 @@ class WindowSelectorTest : public test::AshTestBase {
return window->close_button_.get();
}
- views::Widget* GetLabelWidget(ash::WindowSelectorItem* window) {
- return window->window_label_.get();
+ views::Label* GetLabelView(ash::WindowSelectorItem* window) {
+ return window->window_label_view_;
}
// Tests that a window is contained within a given WindowSelectorItem, and
@@ -747,24 +747,31 @@ TEST_F(WindowSelectorTest, DISABLED_DragDropInProgress) {
TEST_F(WindowSelectorTest, CreateLabelUnderWindow) {
scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100)));
base::string16 window_title = base::UTF8ToUTF16("My window");
- window->set_title(window_title);
+ window->SetTitle(window_title);
ToggleOverview();
WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
- views::Widget* widget = GetLabelWidget(window_item);
- // Has the label widget been created?
- ASSERT_TRUE(widget);
- views::Label* label = static_cast<views::Label*>(widget->GetContentsView());
+ views::Label* label = GetLabelView(window_item);
+ // Has the label view been created?
+ ASSERT_TRUE(label);
+
// Verify the label matches the window title.
EXPECT_EQ(label->text(), window_title);
+
+ // Update the window title and check that the label is updated, too.
+ base::string16 updated_title = base::UTF8ToUTF16("Updated title");
+ window->SetTitle(updated_title);
+ EXPECT_EQ(label->text(), updated_title);
+
// Labels are located based on target_bounds, not the actual window item
// bounds.
gfx::Rect target_bounds(window_item->target_bounds());
gfx::Rect expected_label_bounds(target_bounds.x(),
- target_bounds.bottom(),
+ target_bounds.bottom() - label->
+ GetPreferredSize().height(),
target_bounds.width(),
label->GetPreferredSize().height());
- gfx::Rect real_label_bounds = widget->GetNativeWindow()->bounds();
- EXPECT_EQ(widget->GetNativeWindow()->bounds(), real_label_bounds);
+ gfx::Rect real_label_bounds = label->GetWidget()->GetNativeWindow()->bounds();
+ EXPECT_EQ(real_label_bounds, expected_label_bounds);
}
// Tests that a label is created for the active panel in a group of panels in
@@ -774,17 +781,29 @@ TEST_F(WindowSelectorTest, CreateLabelUnderPanel) {
scoped_ptr<aura::Window> panel2(CreatePanelWindow(gfx::Rect(0, 0, 100, 100)));
base::string16 panel1_title = base::UTF8ToUTF16("My panel");
base::string16 panel2_title = base::UTF8ToUTF16("Another panel");
- panel1->set_title(panel1_title);
- panel2->set_title(panel2_title);
+ base::string16 updated_panel1_title = base::UTF8ToUTF16("WebDriver Torso");
+ base::string16 updated_panel2_title = base::UTF8ToUTF16("Da panel");
+ panel1->SetTitle(panel1_title);
+ panel2->SetTitle(panel2_title);
wm::ActivateWindow(panel1.get());
ToggleOverview();
WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back();
- views::Widget* widget = GetLabelWidget(window_item);
- // Has the label widget been created?
- ASSERT_TRUE(widget);
- views::Label* label = static_cast<views::Label*>(widget->GetContentsView());
+ views::Label* label = GetLabelView(window_item);
+ // Has the label view been created?
+ ASSERT_TRUE(label);
+
// Verify the label matches the active window title.
EXPECT_EQ(label->text(), panel1_title);
+ // Verify that updating the title also updates the label.
+ panel1->SetTitle(updated_panel1_title);
+ EXPECT_EQ(label->text(), updated_panel1_title);
+ // After destroying the first panel, the label should match the second panel.
+ panel1.reset();
+ label = GetLabelView(window_item);
+ EXPECT_EQ(label->text(), panel2_title);
+ // Also test updating the title on the second panel.
+ panel2->SetTitle(updated_panel2_title);
+ EXPECT_EQ(label->text(), updated_panel2_title);
}
// Tests that overview updates the window positions if the display orientation
@@ -961,8 +980,8 @@ TEST_F(WindowSelectorTest, CloseButtonOnPanels) {
aura::Window* window2 = widget2->GetNativeWindow();
base::string16 panel1_title = base::UTF8ToUTF16("Panel 1");
base::string16 panel2_title = base::UTF8ToUTF16("Panel 2");
- window1->set_title(panel1_title);
- window2->set_title(panel2_title);
+ window1->SetTitle(panel1_title);
+ window2->SetTitle(panel2_title);
wm::ActivateWindow(window1);
ToggleOverview();
@@ -980,8 +999,8 @@ TEST_F(WindowSelectorTest, CloseButtonOnPanels) {
EXPECT_TRUE(window_item->Contains(window2));
EXPECT_TRUE(GetCloseButton(window_item)->IsVisible());
- views::Widget* widget = GetLabelWidget(window_item);
- views::Label* label = static_cast<views::Label*>(widget->GetContentsView());
+
+ views::Label* label = GetLabelView(window_item);
EXPECT_EQ(label->text(), panel2_title);
gfx::RectF bounds2 = GetTransformedBoundsInRootWindow(window2);