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

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

Issue 10790127: aura: couple of tooltip UX changes: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 8 years, 5 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') | no next file » | 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/cursor_manager.h" 10 #include "ui/aura/cursor_manager.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 94
95 aura::Window* GetTooltipWindow() { 95 aura::Window* GetTooltipWindow() {
96 return GetController()->tooltip_window_; 96 return GetController()->tooltip_window_;
97 } 97 }
98 98
99 void FireTooltipTimer() { 99 void FireTooltipTimer() {
100 GetController()->TooltipTimerFired(); 100 GetController()->TooltipTimerFired();
101 } 101 }
102 102
103 bool IsTooltipTimerRunning() {
104 return GetController()->tooltip_timer_.IsRunning();
105 }
106
107 void FireTooltipShownTimer() {
108 GetController()->tooltip_shown_timer_.Stop();
109 GetController()->TooltipShownTimerFired();
110 }
111
112 bool IsTooltipShownTimerRunning() {
113 return GetController()->tooltip_shown_timer_.IsRunning();
114 }
115
103 bool IsTooltipVisible() { 116 bool IsTooltipVisible() {
104 return GetController()->IsTooltipVisible(); 117 return GetController()->IsTooltipVisible();
105 } 118 }
106 119
107 void TrimTooltipToFit(string16* text, 120 void TrimTooltipToFit(string16* text,
108 int* max_width, 121 int* max_width,
109 int* line_count, 122 int* line_count,
110 int x, 123 int x,
111 int y) { 124 int y) {
112 ash::internal::TooltipController::TrimTooltipToFit(text, max_width, 125 ash::internal::TooltipController::TrimTooltipToFit(text, max_width,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Whitespaces in tooltips are preserved. 354 // Whitespaces in tooltips are preserved.
342 tooltip.clear(); 355 tooltip.clear();
343 max_width = line_count = -1; 356 max_width = line_count = -1;
344 tooltip = ASCIIToUTF16("Small Tool t\tip"); 357 tooltip = ASCIIToUTF16("Small Tool t\tip");
345 TrimTooltipToFit(&tooltip, &max_width, &line_count, 0, 0); 358 TrimTooltipToFit(&tooltip, &max_width, &line_count, 0, 0);
346 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tool t\tip")), max_width); 359 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tool t\tip")), max_width);
347 EXPECT_EQ(1, line_count); 360 EXPECT_EQ(1, line_count);
348 EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip); 361 EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip);
349 } 362 }
350 363
364 TEST_F(TooltipControllerTest, TooltipHidesOnKeyPressAndStaysHiddenUntilChange) {
365 scoped_ptr<views::Widget> widget(CreateNewWidget());
366 TooltipTestView* view1 = new TooltipTestView;
367 AddViewToWidgetAndResize(widget.get(), view1);
368 view1->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 1"));
369 EXPECT_EQ(string16(), GetTooltipText());
370 EXPECT_EQ(NULL, GetTooltipWindow());
371
372 TooltipTestView* view2 = new TooltipTestView;
373 AddViewToWidgetAndResize(widget.get(), view2);
374 view2->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 2"));
375
376 aura::Window* window = widget->GetNativeView();
377
378 // Fire tooltip timer so tooltip becomes visible.
379 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
380 generator.MoveMouseRelativeTo(window,
381 view1->bounds().CenterPoint());
382 FireTooltipTimer();
383 EXPECT_TRUE(IsTooltipVisible());
384 EXPECT_TRUE(IsTooltipShownTimerRunning());
385
386 generator.PressKey(ui::VKEY_1, 0);
387 EXPECT_FALSE(IsTooltipVisible());
388 EXPECT_FALSE(IsTooltipTimerRunning());
389 EXPECT_FALSE(IsTooltipShownTimerRunning());
390
391 // Moving the mouse inside |view1| should not change the state of the tooltip
392 // or the timers.
393 for (int i = 0; i < 50; i++) {
394 generator.MoveMouseBy(1, 0);
395 EXPECT_FALSE(IsTooltipVisible());
396 EXPECT_FALSE(IsTooltipTimerRunning());
397 EXPECT_FALSE(IsTooltipShownTimerRunning());
398 EXPECT_EQ(window,
399 Shell::GetPrimaryRootWindow()->GetEventHandlerForPoint(
400 generator.current_location()));
401 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 1");
402 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
403 EXPECT_EQ(expected_tooltip, GetTooltipText());
404 EXPECT_EQ(window, GetTooltipWindow());
405 }
406
407 // Now we move the mouse on to |view2|. It should re-start the tooltip timer.
408 generator.MoveMouseBy(1, 0);
409 EXPECT_TRUE(IsTooltipTimerRunning());
410 FireTooltipTimer();
411 EXPECT_TRUE(IsTooltipVisible());
412 EXPECT_TRUE(IsTooltipShownTimerRunning());
413 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 2");
414 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
415 EXPECT_EQ(expected_tooltip, GetTooltipText());
416 EXPECT_EQ(window, GetTooltipWindow());
417 }
418
419 TEST_F(TooltipControllerTest, TooltipHidesOnTimeoutAndStaysHiddenUntilChange) {
420 scoped_ptr<views::Widget> widget(CreateNewWidget());
421 TooltipTestView* view1 = new TooltipTestView;
422 AddViewToWidgetAndResize(widget.get(), view1);
423 view1->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 1"));
424 EXPECT_EQ(string16(), GetTooltipText());
425 EXPECT_EQ(NULL, GetTooltipWindow());
426
427 TooltipTestView* view2 = new TooltipTestView;
428 AddViewToWidgetAndResize(widget.get(), view2);
429 view2->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 2"));
430
431 aura::Window* window = widget->GetNativeView();
432
433 // Fire tooltip timer so tooltip becomes visible.
434 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
435 generator.MoveMouseRelativeTo(window,
436 view1->bounds().CenterPoint());
437 FireTooltipTimer();
438 EXPECT_TRUE(IsTooltipVisible());
439 EXPECT_TRUE(IsTooltipShownTimerRunning());
440
441 FireTooltipShownTimer();
442 EXPECT_FALSE(IsTooltipVisible());
443 EXPECT_FALSE(IsTooltipTimerRunning());
444 EXPECT_FALSE(IsTooltipShownTimerRunning());
445
446 // Moving the mouse inside |view1| should not change the state of the tooltip
447 // or the timers.
448 for (int i = 0; i < 50; i++) {
449 generator.MoveMouseBy(1, 0);
450 EXPECT_FALSE(IsTooltipVisible());
451 EXPECT_FALSE(IsTooltipTimerRunning());
452 EXPECT_FALSE(IsTooltipShownTimerRunning());
453 EXPECT_EQ(window,
454 Shell::GetPrimaryRootWindow()->GetEventHandlerForPoint(
455 generator.current_location()));
456 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 1");
457 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
458 EXPECT_EQ(expected_tooltip, GetTooltipText());
459 EXPECT_EQ(window, GetTooltipWindow());
460 }
461
462 // Now we move the mouse on to |view2|. It should re-start the tooltip timer.
463 generator.MoveMouseBy(1, 0);
464 EXPECT_TRUE(IsTooltipTimerRunning());
465 FireTooltipTimer();
466 EXPECT_TRUE(IsTooltipVisible());
467 EXPECT_TRUE(IsTooltipShownTimerRunning());
468 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 2");
469 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
470 EXPECT_EQ(expected_tooltip, GetTooltipText());
471 EXPECT_EQ(window, GetTooltipWindow());
472 }
473
351 } // namespace test 474 } // namespace test
352 } // namespace ash 475 } // namespace ash
OLDNEW
« no previous file with comments | « ash/tooltips/tooltip_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698