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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/tooltips/tooltip_controller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/tooltips/tooltip_controller_unittest.cc
diff --git a/ash/tooltips/tooltip_controller_unittest.cc b/ash/tooltips/tooltip_controller_unittest.cc
index 1665f1a5afdf33ff527ae92a4af3afd419e2b42b..c1febfd25bf934f55d22bc29f15e2f2d2b99f8d0 100644
--- a/ash/tooltips/tooltip_controller_unittest.cc
+++ b/ash/tooltips/tooltip_controller_unittest.cc
@@ -100,6 +100,19 @@ class TooltipControllerTest : public AshTestBase {
GetController()->TooltipTimerFired();
}
+ bool IsTooltipTimerRunning() {
+ return GetController()->tooltip_timer_.IsRunning();
+ }
+
+ void FireTooltipShownTimer() {
+ GetController()->tooltip_shown_timer_.Stop();
+ GetController()->TooltipShownTimerFired();
+ }
+
+ bool IsTooltipShownTimerRunning() {
+ return GetController()->tooltip_shown_timer_.IsRunning();
+ }
+
bool IsTooltipVisible() {
return GetController()->IsTooltipVisible();
}
@@ -348,5 +361,115 @@ TEST_F(TooltipControllerTest, TrimTooltipToFitTests) {
EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip);
}
+TEST_F(TooltipControllerTest, TooltipHidesOnKeyPressAndStaysHiddenUntilChange) {
+ scoped_ptr<views::Widget> widget(CreateNewWidget());
+ TooltipTestView* view1 = new TooltipTestView;
+ AddViewToWidgetAndResize(widget.get(), view1);
+ view1->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 1"));
+ EXPECT_EQ(string16(), GetTooltipText());
+ EXPECT_EQ(NULL, GetTooltipWindow());
+
+ TooltipTestView* view2 = new TooltipTestView;
+ AddViewToWidgetAndResize(widget.get(), view2);
+ view2->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 2"));
+
+ aura::Window* window = widget->GetNativeView();
+
+ // Fire tooltip timer so tooltip becomes visible.
+ aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
+ generator.MoveMouseRelativeTo(window,
+ view1->bounds().CenterPoint());
+ FireTooltipTimer();
+ EXPECT_TRUE(IsTooltipVisible());
+ EXPECT_TRUE(IsTooltipShownTimerRunning());
+
+ generator.PressKey(ui::VKEY_1, 0);
+ EXPECT_FALSE(IsTooltipVisible());
+ EXPECT_FALSE(IsTooltipTimerRunning());
+ EXPECT_FALSE(IsTooltipShownTimerRunning());
+
+ // Moving the mouse inside |view1| should not change the state of the tooltip
+ // or the timers.
+ for (int i = 0; i < 50; i++) {
+ generator.MoveMouseBy(1, 0);
+ EXPECT_FALSE(IsTooltipVisible());
+ EXPECT_FALSE(IsTooltipTimerRunning());
+ EXPECT_FALSE(IsTooltipShownTimerRunning());
+ EXPECT_EQ(window,
+ Shell::GetPrimaryRootWindow()->GetEventHandlerForPoint(
+ generator.current_location()));
+ string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 1");
+ EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
+ EXPECT_EQ(expected_tooltip, GetTooltipText());
+ EXPECT_EQ(window, GetTooltipWindow());
+ }
+
+ // Now we move the mouse on to |view2|. It should re-start the tooltip timer.
+ generator.MoveMouseBy(1, 0);
+ EXPECT_TRUE(IsTooltipTimerRunning());
+ FireTooltipTimer();
+ EXPECT_TRUE(IsTooltipVisible());
+ EXPECT_TRUE(IsTooltipShownTimerRunning());
+ string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 2");
+ EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
+ EXPECT_EQ(expected_tooltip, GetTooltipText());
+ EXPECT_EQ(window, GetTooltipWindow());
+}
+
+TEST_F(TooltipControllerTest, TooltipHidesOnTimeoutAndStaysHiddenUntilChange) {
+ scoped_ptr<views::Widget> widget(CreateNewWidget());
+ TooltipTestView* view1 = new TooltipTestView;
+ AddViewToWidgetAndResize(widget.get(), view1);
+ view1->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 1"));
+ EXPECT_EQ(string16(), GetTooltipText());
+ EXPECT_EQ(NULL, GetTooltipWindow());
+
+ TooltipTestView* view2 = new TooltipTestView;
+ AddViewToWidgetAndResize(widget.get(), view2);
+ view2->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 2"));
+
+ aura::Window* window = widget->GetNativeView();
+
+ // Fire tooltip timer so tooltip becomes visible.
+ aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
+ generator.MoveMouseRelativeTo(window,
+ view1->bounds().CenterPoint());
+ FireTooltipTimer();
+ EXPECT_TRUE(IsTooltipVisible());
+ EXPECT_TRUE(IsTooltipShownTimerRunning());
+
+ FireTooltipShownTimer();
+ EXPECT_FALSE(IsTooltipVisible());
+ EXPECT_FALSE(IsTooltipTimerRunning());
+ EXPECT_FALSE(IsTooltipShownTimerRunning());
+
+ // Moving the mouse inside |view1| should not change the state of the tooltip
+ // or the timers.
+ for (int i = 0; i < 50; i++) {
+ generator.MoveMouseBy(1, 0);
+ EXPECT_FALSE(IsTooltipVisible());
+ EXPECT_FALSE(IsTooltipTimerRunning());
+ EXPECT_FALSE(IsTooltipShownTimerRunning());
+ EXPECT_EQ(window,
+ Shell::GetPrimaryRootWindow()->GetEventHandlerForPoint(
+ generator.current_location()));
+ string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 1");
+ EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
+ EXPECT_EQ(expected_tooltip, GetTooltipText());
+ EXPECT_EQ(window, GetTooltipWindow());
+ }
+
+ // Now we move the mouse on to |view2|. It should re-start the tooltip timer.
+ generator.MoveMouseBy(1, 0);
+ EXPECT_TRUE(IsTooltipTimerRunning());
+ FireTooltipTimer();
+ EXPECT_TRUE(IsTooltipVisible());
+ EXPECT_TRUE(IsTooltipShownTimerRunning());
+ string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 2");
+ EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
+ EXPECT_EQ(expected_tooltip, GetTooltipText());
+ EXPECT_EQ(window, GetTooltipWindow());
+}
+
} // namespace test
} // namespace ash
« 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