Index: ui/views/corewm/tooltip_controller_unittest.cc |
diff --git a/ui/views/corewm/tooltip_controller_unittest.cc b/ui/views/corewm/tooltip_controller_unittest.cc |
index f09a2a0533e92f0f1d25e618914cbc56f33426d4..546022749e98ed923d999abc3e21f31777250a2f 100644 |
--- a/ui/views/corewm/tooltip_controller_unittest.cc |
+++ b/ui/views/corewm/tooltip_controller_unittest.cc |
@@ -671,6 +671,7 @@ class TestTooltip : public Tooltip { |
const base::string16& tooltip_text, |
const gfx::Point& location) OVERRIDE { |
tooltip_text_ = tooltip_text; |
+ location_ = location; |
} |
virtual void Show() OVERRIDE { |
is_visible_ = true; |
@@ -681,10 +682,12 @@ class TestTooltip : public Tooltip { |
virtual bool IsVisible() OVERRIDE { |
return is_visible_; |
} |
+ const gfx::Point& location() { return location_; } |
private: |
bool is_visible_; |
base::string16 tooltip_text_; |
+ gfx::Point location_; |
DISALLOW_COPY_AND_ASSIGN(TestTooltip); |
}; |
@@ -766,6 +769,174 @@ TEST_F(TooltipControllerTest2, CloseOnCancelMode) { |
EXPECT_TRUE(helper_->GetTooltipWindow() == NULL); |
} |
+// Use for tests that need both views and a TestTooltip. |
+class TooltipControllerTest3 : public aura::test::AuraTestBase { |
+ public: |
+ TooltipControllerTest3() : test_tooltip_(new TestTooltip) {} |
+ virtual ~TooltipControllerTest3() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ wm_state_.reset(new wm::WMState); |
+ aura::test::AuraTestBase::SetUp(); |
+ new wm::DefaultActivationClient(root_window()); |
+ |
+ widget_.reset(CreateWidget(root_window())); |
+ widget_->SetContentsView(new View); |
+ view_ = new TooltipTestView; |
+ widget_->GetContentsView()->AddChildView(view_); |
+ view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds()); |
+ |
+ generator_.reset(new aura::test::EventGenerator(GetRootWindow())); |
+ controller_.reset(new TooltipController( |
+ scoped_ptr<views::corewm::Tooltip>(test_tooltip_))); |
+ GetRootWindow()->RemovePreTargetHandler( |
+ static_cast<TooltipController*>(aura::client::GetTooltipClient( |
+ widget_->GetNativeWindow()->GetRootWindow()))); |
+ GetRootWindow()->AddPreTargetHandler(controller_.get()); |
+ helper_.reset(new TooltipControllerTestHelper(controller_.get())); |
+ SetTooltipClient(GetRootWindow(), controller_.get()); |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ GetRootWindow()->RemovePreTargetHandler(controller_.get()); |
+ aura::client::SetTooltipClient(GetRootWindow(), NULL); |
+ |
+ controller_.reset(); |
+ generator_.reset(); |
+ helper_.reset(); |
+ widget_.reset(); |
+ aura::test::AuraTestBase::TearDown(); |
+ wm_state_.reset(); |
+ } |
+ |
+ aura::Window* GetWindow() { return widget_->GetNativeWindow(); } |
+ |
+ protected: |
+ // Owned by |controller_|. |
+ TestTooltip* test_tooltip_; |
+ scoped_ptr<TooltipControllerTestHelper> helper_; |
+ scoped_ptr<aura::test::EventGenerator> generator_; |
+ scoped_ptr<views::Widget> widget_; |
+ TooltipTestView* view_; |
+ |
+ private: |
+ scoped_ptr<TooltipController> controller_; |
+ scoped_ptr<wm::WMState> wm_state_; |
+ |
+#if defined(OS_WIN) |
+ ui::ScopedOleInitializer ole_initializer_; |
+#endif |
+ |
+ aura::Window* GetRootWindow() { return GetWindow()->GetRootWindow(); } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest3); |
+}; |
+ |
+TEST_F(TooltipControllerTest3, TooltipPositionChangesOnTwoViewsWithSameLabel) { |
+ // Owned by |view_|. |
+ // These two views have the same tooltip text |
+ TooltipTestView* v1 = new TooltipTestView; |
+ TooltipTestView* v2 = new TooltipTestView; |
+ // v1_1 is a view inside v1 that has an identical tooltip text to that of v1 |
+ // and v2 |
+ TooltipTestView* v1_1 = new TooltipTestView; |
+ // v2_1 is a view inside v2 that has an identical tooltip text to that of v1 |
+ // and v2 |
+ TooltipTestView* v2_1 = new TooltipTestView; |
+ // v2_2 is a view inside v2 with the tooltip text different from all the |
+ // others |
+ TooltipTestView* v2_2 = new TooltipTestView; |
+ |
+ // Setup all the views' relations |
+ view_->AddChildView(v1); |
+ view_->AddChildView(v2); |
+ v1->AddChildView(v1_1); |
+ v2->AddChildView(v2_1); |
+ v2->AddChildView(v2_2); |
+ const base::string16 reference_string( |
+ base::ASCIIToUTF16("Identical Tooltip Text")); |
+ const base::string16 alternative_string( |
+ base::ASCIIToUTF16("Another Shrubbery")); |
+ v1->set_tooltip_text(reference_string); |
+ v2->set_tooltip_text(reference_string); |
+ v1_1->set_tooltip_text(reference_string); |
+ v2_1->set_tooltip_text(reference_string); |
+ v2_2->set_tooltip_text(alternative_string); |
+ |
+ // Set views' bounds |
+ gfx::Rect view_bounds(view_->GetLocalBounds()); |
+ view_bounds.set_height(view_bounds.height() / 2); |
+ v1->SetBoundsRect(view_bounds); |
+ v1_1->SetBounds(0, 0, 3, 3); |
+ view_bounds.set_y(view_bounds.height()); |
+ v2->SetBoundsRect(view_bounds); |
+ v2_2->SetBounds(view_bounds.width() - 3, view_bounds.height() - 3, 3, 3); |
+ v2_1->SetBounds(0, 0, 3, 3); |
+ |
+ // Test whether a toolbar appears on v1 |
+ gfx::Point center = v1->bounds().CenterPoint(); |
+ generator_->MoveMouseRelativeTo(GetWindow(), center); |
+ helper_->FireTooltipTimer(); |
+ EXPECT_TRUE(helper_->IsTooltipVisible()); |
+ EXPECT_EQ(reference_string, helper_->GetTooltipText()); |
+ gfx::Point tooltip_bounds1 = test_tooltip_->location(); |
+ |
+ // Test whether the toolbar changes position on mouse over v2 |
+ center = v2->bounds().CenterPoint(); |
+ generator_->MoveMouseRelativeTo(GetWindow(), center); |
+ helper_->FireTooltipTimer(); |
+ EXPECT_TRUE(helper_->IsTooltipVisible()); |
+ EXPECT_EQ(reference_string, helper_->GetTooltipText()); |
+ gfx::Point tooltip_bounds2 = test_tooltip_->location(); |
+ |
+ EXPECT_NE(tooltip_bounds1, gfx::Point()); |
+ EXPECT_NE(tooltip_bounds2, gfx::Point()); |
+ EXPECT_NE(tooltip_bounds1, tooltip_bounds2); |
+ |
+ // Test if the toolbar does not change position on encountering a contained |
+ // view with the same tooltip text |
+ center = v2_1->GetLocalBounds().CenterPoint(); |
+ views::View::ConvertPointToTarget(v2_1, view_, ¢er); |
+ generator_->MoveMouseRelativeTo(GetWindow(), center); |
+ helper_->FireTooltipTimer(); |
+ gfx::Point tooltip_bounds2_1 = test_tooltip_->location(); |
+ |
+ EXPECT_NE(tooltip_bounds2, tooltip_bounds2_1); |
+ EXPECT_TRUE(helper_->IsTooltipVisible()); |
+ EXPECT_EQ(reference_string, helper_->GetTooltipText()); |
+ |
+ // Test if the toolbar changes position on encountering a contained |
+ // view with a different tooltip text |
+ center = v2_2->GetLocalBounds().CenterPoint(); |
+ views::View::ConvertPointToTarget(v2_2, view_, ¢er); |
+ generator_->MoveMouseRelativeTo(GetWindow(), center); |
+ helper_->FireTooltipTimer(); |
+ gfx::Point tooltip_bounds2_2 = test_tooltip_->location(); |
+ |
+ EXPECT_NE(tooltip_bounds2_1, tooltip_bounds2_2); |
+ EXPECT_TRUE(helper_->IsTooltipVisible()); |
+ EXPECT_EQ(alternative_string, helper_->GetTooltipText()); |
+ |
+ // Test if moving from a view that is contained by a larger view, both with |
+ // the same tooltip text, does not change tooltip's position. |
+ center = v1_1->GetLocalBounds().CenterPoint(); |
+ views::View::ConvertPointToTarget(v1_1, view_, ¢er); |
+ generator_->MoveMouseRelativeTo(GetWindow(), center); |
+ helper_->FireTooltipTimer(); |
+ gfx::Point tooltip_bounds1_1 = test_tooltip_->location(); |
+ |
+ EXPECT_TRUE(helper_->IsTooltipVisible()); |
+ EXPECT_EQ(reference_string, helper_->GetTooltipText()); |
+ |
+ center = v1->bounds().CenterPoint(); |
+ generator_->MoveMouseRelativeTo(GetWindow(), center); |
+ helper_->FireTooltipTimer(); |
+ tooltip_bounds1 = test_tooltip_->location(); |
+ |
+ EXPECT_NE(tooltip_bounds1_1, tooltip_bounds1); |
+ EXPECT_EQ(reference_string, helper_->GetTooltipText()); |
+} |
+ |
} // namespace test |
} // namespace corewm |
} // namespace views |