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 |