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

Side by Side Diff: ash/tooltips/tooltip_controller_unittest.cc

Issue 2643973002: Revert of Remove unnecessary spin in ToolTipController (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | ui/views/corewm/tooltip_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/shell.h" 5 #include "ash/shell.h"
6 #include "ash/test/ash_test_base.h" 6 #include "ash/test/ash_test_base.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/aura/env.h" 8 #include "ui/aura/env.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/aura/window_event_dispatcher.h" 10 #include "ui/aura/window_event_dispatcher.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 AddViewToWidgetAndResize(widget.get(), view); 102 AddViewToWidgetAndResize(widget.get(), view);
103 view->set_tooltip_text(base::ASCIIToUTF16("Tooltip Text")); 103 view->set_tooltip_text(base::ASCIIToUTF16("Tooltip Text"));
104 EXPECT_EQ(base::string16(), helper_->GetTooltipText()); 104 EXPECT_EQ(base::string16(), helper_->GetTooltipText());
105 EXPECT_EQ(NULL, helper_->GetTooltipWindow()); 105 EXPECT_EQ(NULL, helper_->GetTooltipWindow());
106 106
107 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 107 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
108 generator.MoveMouseRelativeTo(widget->GetNativeView(), 108 generator.MoveMouseRelativeTo(widget->GetNativeView(),
109 view->bounds().CenterPoint()); 109 view->bounds().CenterPoint());
110 base::string16 expected_tooltip = base::ASCIIToUTF16("Tooltip Text"); 110 base::string16 expected_tooltip = base::ASCIIToUTF16("Tooltip Text");
111 111
112 // Mouse event triggers tooltip update so it becomes visible. 112 // Fire tooltip timer so tooltip becomes visible.
113 helper_->FireTooltipTimer();
113 EXPECT_TRUE(helper_->IsTooltipVisible()); 114 EXPECT_TRUE(helper_->IsTooltipVisible());
114 115
115 // Disable mouse event which hides the cursor and check again. 116 // Hide the cursor and check again.
116 ash::Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); 117 ash::Shell::GetInstance()->cursor_manager()->DisableMouseEvents();
117 RunAllPendingInMessageLoop(); 118 helper_->FireTooltipTimer();
118 EXPECT_FALSE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
119 helper_->UpdateIfRequired();
120 EXPECT_FALSE(helper_->IsTooltipVisible()); 119 EXPECT_FALSE(helper_->IsTooltipVisible());
121 120
122 // Enable mouse event which shows the cursor and re-check. 121 // Show the cursor and re-check.
122 RunAllPendingInMessageLoop();
123 ash::Shell::GetInstance()->cursor_manager()->EnableMouseEvents(); 123 ash::Shell::GetInstance()->cursor_manager()->EnableMouseEvents();
124 RunAllPendingInMessageLoop(); 124 RunAllPendingInMessageLoop();
125 EXPECT_TRUE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible()); 125 helper_->FireTooltipTimer();
126 helper_->UpdateIfRequired();
127 EXPECT_TRUE(helper_->IsTooltipVisible()); 126 EXPECT_TRUE(helper_->IsTooltipVisible());
128 } 127 }
129 128
130 TEST_F(TooltipControllerTest, TooltipsOnMultiDisplayShouldNotCrash) { 129 TEST_F(TooltipControllerTest, TooltipsOnMultiDisplayShouldNotCrash) {
131 if (!SupportsMultipleDisplays()) 130 if (!SupportsMultipleDisplays())
132 return; 131 return;
133 132
134 UpdateDisplay("1000x600,600x400"); 133 UpdateDisplay("1000x600,600x400");
135 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 134 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
136 std::unique_ptr<views::Widget> widget1( 135 std::unique_ptr<views::Widget> widget1(
137 CreateNewWidgetWithBoundsOn(0, gfx::Rect(10, 10, 100, 100))); 136 CreateNewWidgetWithBoundsOn(0, gfx::Rect(10, 10, 100, 100)));
138 TooltipTestView* view1 = new TooltipTestView; 137 TooltipTestView* view1 = new TooltipTestView;
139 AddViewToWidgetAndResize(widget1.get(), view1); 138 AddViewToWidgetAndResize(widget1.get(), view1);
140 view1->set_tooltip_text(base::ASCIIToUTF16("Tooltip Text for view 1")); 139 view1->set_tooltip_text(base::ASCIIToUTF16("Tooltip Text for view 1"));
141 EXPECT_EQ(widget1->GetNativeView()->GetRootWindow(), root_windows[0]); 140 EXPECT_EQ(widget1->GetNativeView()->GetRootWindow(), root_windows[0]);
142 141
143 std::unique_ptr<views::Widget> widget2( 142 std::unique_ptr<views::Widget> widget2(
144 CreateNewWidgetWithBoundsOn(1, gfx::Rect(1200, 10, 100, 100))); 143 CreateNewWidgetWithBoundsOn(1, gfx::Rect(1200, 10, 100, 100)));
145 TooltipTestView* view2 = new TooltipTestView; 144 TooltipTestView* view2 = new TooltipTestView;
146 AddViewToWidgetAndResize(widget2.get(), view2); 145 AddViewToWidgetAndResize(widget2.get(), view2);
147 view2->set_tooltip_text(base::ASCIIToUTF16("Tooltip Text for view 2")); 146 view2->set_tooltip_text(base::ASCIIToUTF16("Tooltip Text for view 2"));
148 EXPECT_EQ(widget2->GetNativeView()->GetRootWindow(), root_windows[1]); 147 EXPECT_EQ(widget2->GetNativeView()->GetRootWindow(), root_windows[1]);
149 148
150 // Show tooltip on second display. 149 // Show tooltip on second display.
151 ui::test::EventGenerator generator(root_windows[1]); 150 ui::test::EventGenerator generator(root_windows[1]);
152 generator.MoveMouseRelativeTo(widget2->GetNativeView(), 151 generator.MoveMouseRelativeTo(widget2->GetNativeView(),
153 view2->bounds().CenterPoint()); 152 view2->bounds().CenterPoint());
153 helper_->FireTooltipTimer();
154 EXPECT_TRUE(helper_->IsTooltipVisible()); 154 EXPECT_TRUE(helper_->IsTooltipVisible());
155 155
156 // Get rid of secondary display. This destroy's the tooltip's aura window. If 156 // Get rid of secondary display. This destroy's the tooltip's aura window. If
157 // we have handled this case, we will not crash in the following statement. 157 // we have handled this case, we will not crash in the following statement.
158 UpdateDisplay("1000x600"); 158 UpdateDisplay("1000x600");
159 #if !defined(OS_WIN) 159 #if !defined(OS_WIN)
160 // TODO(cpu): Detangle the window destruction notification. Currently 160 // TODO(cpu): Detangle the window destruction notification. Currently
161 // the TooltipController::OnWindowDestroyed is not being called then the 161 // the TooltipController::OnWindowDestroyed is not being called then the
162 // display is torn down so the tooltip is is still there. 162 // display is torn down so the tooltip is is still there.
163 EXPECT_FALSE(helper_->IsTooltipVisible()); 163 EXPECT_FALSE(helper_->IsTooltipVisible());
164 #endif 164 #endif
165 EXPECT_EQ(widget2->GetNativeView()->GetRootWindow(), root_windows[0]); 165 EXPECT_EQ(widget2->GetNativeView()->GetRootWindow(), root_windows[0]);
166 166
167 // The tooltip should create a new aura window for itself, so we should still 167 // The tooltip should create a new aura window for itself, so we should still
168 // be able to show tooltips on the primary display. 168 // be able to show tooltips on the primary display.
169 ui::test::EventGenerator generator1(root_windows[0]); 169 ui::test::EventGenerator generator1(root_windows[0]);
170 generator1.MoveMouseRelativeTo(widget1->GetNativeView(), 170 generator1.MoveMouseRelativeTo(widget1->GetNativeView(),
171 view1->bounds().CenterPoint()); 171 view1->bounds().CenterPoint());
172 helper_->FireTooltipTimer();
172 EXPECT_TRUE(helper_->IsTooltipVisible()); 173 EXPECT_TRUE(helper_->IsTooltipVisible());
173 } 174 }
174 175
175 } // namespace test 176 } // namespace test
176 } // namespace ash 177 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/views/corewm/tooltip_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698