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

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

Issue 10442017: Rename GetRootWindow() -> GetPrimaryRootWindow() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git-try -b linux_chromeos,win_aura Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ash/tooltips/tooltip_controller.cc ('k') | ash/wm/activation_controller.cc » ('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 "ash/tooltips/tooltip_controller.h" 7 #include "ash/tooltips/tooltip_controller.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "ui/aura/client/tooltip_client.h" 9 #include "ui/aura/client/tooltip_client.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
(...skipping 29 matching lines...) Expand all
40 40
41 DISALLOW_COPY_AND_ASSIGN(TooltipTestView); 41 DISALLOW_COPY_AND_ASSIGN(TooltipTestView);
42 }; 42 };
43 43
44 views::Widget* CreateNewWidget() { 44 views::Widget* CreateNewWidget() {
45 views::Widget* widget = new views::Widget; 45 views::Widget* widget = new views::Widget;
46 views::Widget::InitParams params; 46 views::Widget::InitParams params;
47 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; 47 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
48 params.accept_events = true; 48 params.accept_events = true;
49 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 49 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
50 params.parent = Shell::GetRootWindow(); 50 params.parent = Shell::GetPrimaryRootWindow();
51 params.child = true; 51 params.child = true;
52 widget->Init(params); 52 widget->Init(params);
53 widget->Show(); 53 widget->Show();
54 return widget; 54 return widget;
55 } 55 }
56 56
57 void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) { 57 void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) {
58 if (!widget->GetContentsView()) { 58 if (!widget->GetContentsView()) {
59 views::View* contents_view = new views::View; 59 views::View* contents_view = new views::View;
60 widget->SetContentsView(contents_view); 60 widget->SetContentsView(contents_view);
61 } 61 }
62 62
63 views::View* contents_view = widget->GetContentsView(); 63 views::View* contents_view = widget->GetContentsView();
64 contents_view->AddChildView(view); 64 contents_view->AddChildView(view);
65 view->SetBounds(contents_view->width(), 0, 100, 100); 65 view->SetBounds(contents_view->width(), 0, 100, 100);
66 gfx::Rect contents_view_bounds = contents_view->bounds(); 66 gfx::Rect contents_view_bounds = contents_view->bounds();
67 contents_view_bounds = contents_view_bounds.Union(view->bounds()); 67 contents_view_bounds = contents_view_bounds.Union(view->bounds());
68 contents_view->SetBoundsRect(contents_view_bounds); 68 contents_view->SetBoundsRect(contents_view_bounds);
69 widget->SetBounds(contents_view_bounds); 69 widget->SetBounds(contents_view_bounds);
70 } 70 }
71 71
72 ash::internal::TooltipController* GetController() { 72 ash::internal::TooltipController* GetController() {
73 return static_cast<ash::internal::TooltipController*>( 73 return static_cast<ash::internal::TooltipController*>(
74 aura::client::GetTooltipClient(Shell::GetRootWindow())); 74 aura::client::GetTooltipClient(Shell::GetPrimaryRootWindow()));
75 } 75 }
76 76
77 gfx::Font GetDefaultFont() { 77 gfx::Font GetDefaultFont() {
78 return ui::ResourceBundle::GetSharedInstance().GetFont( 78 return ui::ResourceBundle::GetSharedInstance().GetFont(
79 ui::ResourceBundle::BaseFont); 79 ui::ResourceBundle::BaseFont);
80 } 80 }
81 81
82 } // namespace 82 } // namespace
83 83
84 class TooltipControllerTest : public AshTestBase { 84 class TooltipControllerTest : public AshTestBase {
(...skipping 24 matching lines...) Expand all
109 int y) { 109 int y) {
110 ash::internal::TooltipController::TrimTooltipToFit(text, max_width, 110 ash::internal::TooltipController::TrimTooltipToFit(text, max_width,
111 line_count, x, y); 111 line_count, x, y);
112 } 112 }
113 113
114 private: 114 private:
115 DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest); 115 DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest);
116 }; 116 };
117 117
118 TEST_F(TooltipControllerTest, NonNullTooltipClient) { 118 TEST_F(TooltipControllerTest, NonNullTooltipClient) {
119 EXPECT_TRUE(aura::client::GetTooltipClient(Shell::GetRootWindow()) != NULL); 119 EXPECT_TRUE(aura::client::GetTooltipClient(Shell::GetPrimaryRootWindow())
120 != NULL);
120 EXPECT_EQ(string16(), GetTooltipText()); 121 EXPECT_EQ(string16(), GetTooltipText());
121 EXPECT_EQ(NULL, GetTooltipWindow()); 122 EXPECT_EQ(NULL, GetTooltipWindow());
122 EXPECT_FALSE(IsTooltipVisible()); 123 EXPECT_FALSE(IsTooltipVisible());
123 } 124 }
124 125
125 TEST_F(TooltipControllerTest, ViewTooltip) { 126 TEST_F(TooltipControllerTest, ViewTooltip) {
126 scoped_ptr<views::Widget> widget(CreateNewWidget()); 127 scoped_ptr<views::Widget> widget(CreateNewWidget());
127 TooltipTestView* view = new TooltipTestView; 128 TooltipTestView* view = new TooltipTestView;
128 AddViewToWidgetAndResize(widget.get(), view); 129 AddViewToWidgetAndResize(widget.get(), view);
129 view->set_tooltip_text(ASCIIToUTF16("Tooltip Text")); 130 view->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
130 EXPECT_EQ(string16(), GetTooltipText()); 131 EXPECT_EQ(string16(), GetTooltipText());
131 EXPECT_EQ(NULL, GetTooltipWindow()); 132 EXPECT_EQ(NULL, GetTooltipWindow());
132 aura::test::EventGenerator generator(Shell::GetRootWindow()); 133 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
133 generator.MoveMouseToCenterOf(widget->GetNativeView()); 134 generator.MoveMouseToCenterOf(widget->GetNativeView());
134 135
135 aura::Window* window = widget->GetNativeView(); 136 aura::Window* window = widget->GetNativeView();
136 EXPECT_EQ(window, Shell::GetRootWindow()->GetEventHandlerForPoint( 137 EXPECT_EQ(window, Shell::GetPrimaryRootWindow()->GetEventHandlerForPoint(
137 generator.current_location())); 138 generator.current_location()));
138 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text"); 139 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
139 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window)); 140 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
140 EXPECT_EQ(string16(), GetTooltipText()); 141 EXPECT_EQ(string16(), GetTooltipText());
141 EXPECT_EQ(window, GetTooltipWindow()); 142 EXPECT_EQ(window, GetTooltipWindow());
142 143
143 // Fire tooltip timer so tooltip becomes visible. 144 // Fire tooltip timer so tooltip becomes visible.
144 FireTooltipTimer(); 145 FireTooltipTimer();
145 146
146 EXPECT_TRUE(IsTooltipVisible()); 147 EXPECT_TRUE(IsTooltipVisible());
(...skipping 12 matching lines...) Expand all
159 view1->set_tooltip_text(ASCIIToUTF16("Tooltip Text")); 160 view1->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
160 EXPECT_EQ(string16(), GetTooltipText()); 161 EXPECT_EQ(string16(), GetTooltipText());
161 EXPECT_EQ(NULL, GetTooltipWindow()); 162 EXPECT_EQ(NULL, GetTooltipWindow());
162 163
163 TooltipTestView* view2 = new TooltipTestView; 164 TooltipTestView* view2 = new TooltipTestView;
164 AddViewToWidgetAndResize(widget.get(), view2); 165 AddViewToWidgetAndResize(widget.get(), view2);
165 166
166 aura::Window* window = widget->GetNativeView(); 167 aura::Window* window = widget->GetNativeView();
167 168
168 // Fire tooltip timer so tooltip becomes visible. 169 // Fire tooltip timer so tooltip becomes visible.
169 aura::test::EventGenerator generator(Shell::GetRootWindow()); 170 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
170 generator.MoveMouseRelativeTo(window, 171 generator.MoveMouseRelativeTo(window,
171 view1->bounds().CenterPoint()); 172 view1->bounds().CenterPoint());
172 FireTooltipTimer(); 173 FireTooltipTimer();
173 EXPECT_TRUE(IsTooltipVisible()); 174 EXPECT_TRUE(IsTooltipVisible());
174 for (int i = 0; i < 50; i++) { 175 for (int i = 0; i < 50; i++) {
175 generator.MoveMouseBy(1, 0); 176 generator.MoveMouseBy(1, 0);
176 EXPECT_TRUE(IsTooltipVisible()); 177 EXPECT_TRUE(IsTooltipVisible());
177 EXPECT_EQ(window, 178 EXPECT_EQ(window,
178 Shell::GetRootWindow()->GetEventHandlerForPoint( 179 Shell::GetPrimaryRootWindow()->GetEventHandlerForPoint(
179 generator.current_location())); 180 generator.current_location()));
180 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text"); 181 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
181 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window)); 182 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
182 EXPECT_EQ(expected_tooltip, GetTooltipText()); 183 EXPECT_EQ(expected_tooltip, GetTooltipText());
183 EXPECT_EQ(window, GetTooltipWindow()); 184 EXPECT_EQ(window, GetTooltipWindow());
184 } 185 }
185 for (int i = 0; i < 50; i++) { 186 for (int i = 0; i < 50; i++) {
186 generator.MoveMouseBy(1, 0); 187 generator.MoveMouseBy(1, 0);
187 EXPECT_FALSE(IsTooltipVisible()); 188 EXPECT_FALSE(IsTooltipVisible());
188 EXPECT_EQ(window, 189 EXPECT_EQ(window,
189 Shell::GetRootWindow()->GetEventHandlerForPoint( 190 Shell::GetPrimaryRootWindow()->GetEventHandlerForPoint(
190 generator.current_location())); 191 generator.current_location()));
191 string16 expected_tooltip; // = "" 192 string16 expected_tooltip; // = ""
192 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window)); 193 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
193 EXPECT_EQ(expected_tooltip, GetTooltipText()); 194 EXPECT_EQ(expected_tooltip, GetTooltipText());
194 EXPECT_EQ(window, GetTooltipWindow()); 195 EXPECT_EQ(window, GetTooltipWindow());
195 } 196 }
196 } 197 }
197 198
198 TEST_F(TooltipControllerTest, EnableOrDisableTooltips) { 199 TEST_F(TooltipControllerTest, EnableOrDisableTooltips) {
199 scoped_ptr<views::Widget> widget(CreateNewWidget()); 200 scoped_ptr<views::Widget> widget(CreateNewWidget());
200 TooltipTestView* view = new TooltipTestView; 201 TooltipTestView* view = new TooltipTestView;
201 AddViewToWidgetAndResize(widget.get(), view); 202 AddViewToWidgetAndResize(widget.get(), view);
202 view->set_tooltip_text(ASCIIToUTF16("Tooltip Text")); 203 view->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
203 EXPECT_EQ(string16(), GetTooltipText()); 204 EXPECT_EQ(string16(), GetTooltipText());
204 EXPECT_EQ(NULL, GetTooltipWindow()); 205 EXPECT_EQ(NULL, GetTooltipWindow());
205 206
206 aura::test::EventGenerator generator(Shell::GetRootWindow()); 207 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
207 generator.MoveMouseRelativeTo(widget->GetNativeView(), 208 generator.MoveMouseRelativeTo(widget->GetNativeView(),
208 view->bounds().CenterPoint()); 209 view->bounds().CenterPoint());
209 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text"); 210 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
210 211
211 // Fire tooltip timer so tooltip becomes visible. 212 // Fire tooltip timer so tooltip becomes visible.
212 FireTooltipTimer(); 213 FireTooltipTimer();
213 EXPECT_TRUE(IsTooltipVisible()); 214 EXPECT_TRUE(IsTooltipVisible());
214 215
215 // Diable tooltips and check again. 216 // Diable tooltips and check again.
216 GetController()->SetTooltipsEnabled(false); 217 GetController()->SetTooltipsEnabled(false);
217 EXPECT_FALSE(IsTooltipVisible()); 218 EXPECT_FALSE(IsTooltipVisible());
218 FireTooltipTimer(); 219 FireTooltipTimer();
219 EXPECT_FALSE(IsTooltipVisible()); 220 EXPECT_FALSE(IsTooltipVisible());
220 221
221 // Enable tooltips back and check again. 222 // Enable tooltips back and check again.
222 GetController()->SetTooltipsEnabled(true); 223 GetController()->SetTooltipsEnabled(true);
223 EXPECT_FALSE(IsTooltipVisible()); 224 EXPECT_FALSE(IsTooltipVisible());
224 FireTooltipTimer(); 225 FireTooltipTimer();
225 EXPECT_TRUE(IsTooltipVisible()); 226 EXPECT_TRUE(IsTooltipVisible());
226 } 227 }
227 228
228 TEST_F(TooltipControllerTest, HideTooltipWhenCursorHidden) { 229 TEST_F(TooltipControllerTest, HideTooltipWhenCursorHidden) {
229 scoped_ptr<views::Widget> widget(CreateNewWidget()); 230 scoped_ptr<views::Widget> widget(CreateNewWidget());
230 TooltipTestView* view = new TooltipTestView; 231 TooltipTestView* view = new TooltipTestView;
231 AddViewToWidgetAndResize(widget.get(), view); 232 AddViewToWidgetAndResize(widget.get(), view);
232 view->set_tooltip_text(ASCIIToUTF16("Tooltip Text")); 233 view->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
233 EXPECT_EQ(string16(), GetTooltipText()); 234 EXPECT_EQ(string16(), GetTooltipText());
234 EXPECT_EQ(NULL, GetTooltipWindow()); 235 EXPECT_EQ(NULL, GetTooltipWindow());
235 236
236 aura::test::EventGenerator generator(Shell::GetRootWindow()); 237 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
237 generator.MoveMouseRelativeTo(widget->GetNativeView(), 238 generator.MoveMouseRelativeTo(widget->GetNativeView(),
238 view->bounds().CenterPoint()); 239 view->bounds().CenterPoint());
239 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text"); 240 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
240 241
241 // Fire tooltip timer so tooltip becomes visible. 242 // Fire tooltip timer so tooltip becomes visible.
242 FireTooltipTimer(); 243 FireTooltipTimer();
243 EXPECT_TRUE(IsTooltipVisible()); 244 EXPECT_TRUE(IsTooltipVisible());
244 245
245 // Hide the cursor and check again. 246 // Hide the cursor and check again.
246 Shell::GetRootWindow()->ShowCursor(false); 247 Shell::GetPrimaryRootWindow()->ShowCursor(false);
247 FireTooltipTimer(); 248 FireTooltipTimer();
248 EXPECT_FALSE(IsTooltipVisible()); 249 EXPECT_FALSE(IsTooltipVisible());
249 250
250 // Show the cursor and re-check. 251 // Show the cursor and re-check.
251 Shell::GetRootWindow()->ShowCursor(true); 252 Shell::GetPrimaryRootWindow()->ShowCursor(true);
252 FireTooltipTimer(); 253 FireTooltipTimer();
253 EXPECT_TRUE(IsTooltipVisible()); 254 EXPECT_TRUE(IsTooltipVisible());
254 } 255 }
255 256
256 TEST_F(TooltipControllerTest, TrimTooltipToFitTests) { 257 TEST_F(TooltipControllerTest, TrimTooltipToFitTests) {
257 string16 tooltip; 258 string16 tooltip;
258 int max_width, line_count, expect_lines; 259 int max_width, line_count, expect_lines;
259 int max_pixel_width = 400; // copied from constants in tooltip_controller.cc 260 int max_pixel_width = 400; // copied from constants in tooltip_controller.cc
260 int max_lines = 10; // copied from constants in tooltip_controller.cc 261 int max_lines = 10; // copied from constants in tooltip_controller.cc
261 gfx::Font font = GetDefaultFont(); 262 gfx::Font font = GetDefaultFont();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 max_width = line_count = -1; 341 max_width = line_count = -1;
341 tooltip = ASCIIToUTF16("Small Tool t\tip"); 342 tooltip = ASCIIToUTF16("Small Tool t\tip");
342 TrimTooltipToFit(&tooltip, &max_width, &line_count, 0, 0); 343 TrimTooltipToFit(&tooltip, &max_width, &line_count, 0, 0);
343 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tool t\tip")), max_width); 344 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tool t\tip")), max_width);
344 EXPECT_EQ(1, line_count); 345 EXPECT_EQ(1, line_count);
345 EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip); 346 EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip);
346 } 347 }
347 348
348 } // namespace test 349 } // namespace test
349 } // namespace ash 350 } // namespace ash
OLDNEW
« no previous file with comments | « ash/tooltips/tooltip_controller.cc ('k') | ash/wm/activation_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698