OLD | NEW |
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 FireTooltipTimer(); | 218 FireTooltipTimer(); |
219 EXPECT_FALSE(IsTooltipVisible()); | 219 EXPECT_FALSE(IsTooltipVisible()); |
220 | 220 |
221 // Enable tooltips back and check again. | 221 // Enable tooltips back and check again. |
222 GetController()->SetTooltipsEnabled(true); | 222 GetController()->SetTooltipsEnabled(true); |
223 EXPECT_FALSE(IsTooltipVisible()); | 223 EXPECT_FALSE(IsTooltipVisible()); |
224 FireTooltipTimer(); | 224 FireTooltipTimer(); |
225 EXPECT_TRUE(IsTooltipVisible()); | 225 EXPECT_TRUE(IsTooltipVisible()); |
226 } | 226 } |
227 | 227 |
| 228 TEST_F(TooltipControllerTest, HideTooltipWhenCursorHidden) { |
| 229 scoped_ptr<views::Widget> widget(CreateNewWidget()); |
| 230 TooltipTestView* view = new TooltipTestView; |
| 231 AddViewToWidgetAndResize(widget.get(), view); |
| 232 view->set_tooltip_text(ASCIIToUTF16("Tooltip Text")); |
| 233 EXPECT_EQ(ASCIIToUTF16(""), GetTooltipText()); |
| 234 EXPECT_EQ(NULL, GetTooltipWindow()); |
| 235 |
| 236 aura::test::EventGenerator generator(Shell::GetRootWindow()); |
| 237 generator.MoveMouseRelativeTo(widget->GetNativeView(), |
| 238 view->bounds().CenterPoint()); |
| 239 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text"); |
| 240 |
| 241 // Fire tooltip timer so tooltip becomes visible. |
| 242 FireTooltipTimer(); |
| 243 EXPECT_TRUE(IsTooltipVisible()); |
| 244 |
| 245 // Hide the cursor and check again. |
| 246 Shell::GetRootWindow()->ShowCursor(false); |
| 247 FireTooltipTimer(); |
| 248 EXPECT_FALSE(IsTooltipVisible()); |
| 249 |
| 250 // Show the cursor and re-check. |
| 251 Shell::GetRootWindow()->ShowCursor(true); |
| 252 FireTooltipTimer(); |
| 253 EXPECT_TRUE(IsTooltipVisible()); |
| 254 } |
| 255 |
228 TEST_F(TooltipControllerTest, TrimTooltipToFitTests) { | 256 TEST_F(TooltipControllerTest, TrimTooltipToFitTests) { |
229 string16 tooltip; | 257 string16 tooltip; |
230 int max_width, line_count, expect_lines; | 258 int max_width, line_count, expect_lines; |
231 int max_pixel_width = 400; // copied from constants in tooltip_controller.cc | 259 int max_pixel_width = 400; // copied from constants in tooltip_controller.cc |
232 int max_lines = 10; // copied from constants in tooltip_controller.cc | 260 int max_lines = 10; // copied from constants in tooltip_controller.cc |
233 gfx::Font font = GetDefaultFont(); | 261 gfx::Font font = GetDefaultFont(); |
234 size_t tooltip_len; | 262 size_t tooltip_len; |
235 | 263 |
236 // Error in computed size vs. expected size should not be greater than the | 264 // Error in computed size vs. expected size should not be greater than the |
237 // size of the longest word. | 265 // size of the longest word. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 max_width = line_count = -1; | 340 max_width = line_count = -1; |
313 tooltip = ASCIIToUTF16("Small Tool t\tip"); | 341 tooltip = ASCIIToUTF16("Small Tool t\tip"); |
314 TrimTooltipToFit(&tooltip, &max_width, &line_count, 0, 0); | 342 TrimTooltipToFit(&tooltip, &max_width, &line_count, 0, 0); |
315 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tool t\tip")), max_width); | 343 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tool t\tip")), max_width); |
316 EXPECT_EQ(1, line_count); | 344 EXPECT_EQ(1, line_count); |
317 EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip); | 345 EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip); |
318 } | 346 } |
319 | 347 |
320 } // namespace test | 348 } // namespace test |
321 } // namespace ash | 349 } // namespace ash |
OLD | NEW |