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

Side by Side Diff: ui/views/corewm/tooltip_controller_unittest.cc

Issue 213833018: Aura tooltips do not move on mouse move in case of many neighboring views with the same label (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not set unique id along with tooltip text Created 6 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/views/corewm/tooltip_controller.h" 5 #include "ui/views/corewm/tooltip_controller.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/aura/client/cursor_client.h" 8 #include "ui/aura/client/cursor_client.h"
9 #include "ui/aura/client/screen_position_client.h" 9 #include "ui/aura/client/screen_position_client.h"
10 #include "ui/aura/env.h" 10 #include "ui/aura/env.h"
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 TestTooltip() : is_visible_(false) {} 664 TestTooltip() : is_visible_(false) {}
665 virtual ~TestTooltip() {} 665 virtual ~TestTooltip() {}
666 666
667 const base::string16& tooltip_text() const { return tooltip_text_; } 667 const base::string16& tooltip_text() const { return tooltip_text_; }
668 668
669 // Tooltip: 669 // Tooltip:
670 virtual void SetText(aura::Window* window, 670 virtual void SetText(aura::Window* window,
671 const base::string16& tooltip_text, 671 const base::string16& tooltip_text,
672 const gfx::Point& location) OVERRIDE { 672 const gfx::Point& location) OVERRIDE {
673 tooltip_text_ = tooltip_text; 673 tooltip_text_ = tooltip_text;
674 location_ = location;
674 } 675 }
675 virtual void Show() OVERRIDE { 676 virtual void Show() OVERRIDE {
676 is_visible_ = true; 677 is_visible_ = true;
677 } 678 }
678 virtual void Hide() OVERRIDE { 679 virtual void Hide() OVERRIDE {
679 is_visible_ = false; 680 is_visible_ = false;
680 } 681 }
681 virtual bool IsVisible() OVERRIDE { 682 virtual bool IsVisible() OVERRIDE {
682 return is_visible_; 683 return is_visible_;
683 } 684 }
685 const gfx::Point& location() { return location_; }
684 686
685 private: 687 private:
686 bool is_visible_; 688 bool is_visible_;
687 base::string16 tooltip_text_; 689 base::string16 tooltip_text_;
690 gfx::Point location_;
688 691
689 DISALLOW_COPY_AND_ASSIGN(TestTooltip); 692 DISALLOW_COPY_AND_ASSIGN(TestTooltip);
690 }; 693 };
691 694
692 } // namespace 695 } // namespace
693 696
694 // Use for tests that don't depend upon views. 697 // Use for tests that don't depend upon views.
695 class TooltipControllerTest2 : public aura::test::AuraTestBase { 698 class TooltipControllerTest2 : public aura::test::AuraTestBase {
696 public: 699 public:
697 TooltipControllerTest2() : test_tooltip_(new TestTooltip) {} 700 TooltipControllerTest2() : test_tooltip_(new TestTooltip) {}
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 EXPECT_TRUE(helper_->IsTooltipVisible()); 762 EXPECT_TRUE(helper_->IsTooltipVisible());
760 763
761 // Send OnCancelMode event and verify that tooltip becomes invisible and 764 // Send OnCancelMode event and verify that tooltip becomes invisible and
762 // the tooltip window is closed. 765 // the tooltip window is closed.
763 ui::CancelModeEvent event; 766 ui::CancelModeEvent event;
764 helper_->controller()->OnCancelMode(&event); 767 helper_->controller()->OnCancelMode(&event);
765 EXPECT_FALSE(helper_->IsTooltipVisible()); 768 EXPECT_FALSE(helper_->IsTooltipVisible());
766 EXPECT_TRUE(helper_->GetTooltipWindow() == NULL); 769 EXPECT_TRUE(helper_->GetTooltipWindow() == NULL);
767 } 770 }
768 771
772 // Use for tests that need both views and a TestTooltip.
773 class TooltipControllerTest3 : public aura::test::AuraTestBase {
774 public:
775 TooltipControllerTest3() : test_tooltip_(new TestTooltip) {}
776 virtual ~TooltipControllerTest3() {}
777
778 virtual void SetUp() OVERRIDE {
779 wm_state_.reset(new wm::WMState);
780 aura::test::AuraTestBase::SetUp();
781
782 widget_.reset(CreateWidget(root_window()));
783 widget_->SetContentsView(new View);
784 view_ = new TooltipTestView;
785 widget_->GetContentsView()->AddChildView(view_);
786 view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds());
787
788 generator_.reset(new aura::test::EventGenerator(GetRootWindow()));
789 controller_.reset(new TooltipController(
790 scoped_ptr<views::corewm::Tooltip>(test_tooltip_)));
791 GetRootWindow()->RemovePreTargetHandler(
792 static_cast<TooltipController*>(aura::client::GetTooltipClient(
793 widget_->GetNativeWindow()->GetRootWindow())));
794 GetRootWindow()->AddPreTargetHandler(controller_.get());
795 helper_.reset(new TooltipControllerTestHelper(controller_.get()));
796 SetTooltipClient(GetRootWindow(), controller_.get());
797 }
798
799 virtual void TearDown() OVERRIDE {
800 GetRootWindow()->RemovePreTargetHandler(controller_.get());
801 aura::client::SetTooltipClient(GetRootWindow(), NULL);
802
803 controller_.reset();
804 generator_.reset();
805 helper_.reset();
806 widget_.reset();
807 aura::test::AuraTestBase::TearDown();
808 wm_state_.reset();
809 }
810
811 aura::Window* GetWindow() { return widget_->GetNativeWindow(); }
812
813 protected:
814 // Owned by |controller_|.
815 TestTooltip* test_tooltip_;
816 scoped_ptr<TooltipControllerTestHelper> helper_;
817 scoped_ptr<aura::test::EventGenerator> generator_;
818 scoped_ptr<views::Widget> widget_;
819 TooltipTestView* view_;
820
821 private:
822 scoped_ptr<TooltipController> controller_;
823 scoped_ptr<wm::WMState> wm_state_;
824
825 #if defined(OS_WIN)
826 ui::ScopedOleInitializer ole_initializer_;
827 #endif
828
829 aura::Window* GetRootWindow() { return GetWindow()->GetRootWindow(); }
830
831 DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest3);
832 };
833
834 TEST_F(TooltipControllerTest3, TooltipPositionChangesOnTwoViewsWithSameLabel) {
835 // Owned by |view_|.
836 // These two views have the same tooltip text
837 TooltipTestView* v1 = new TooltipTestView;
838 TooltipTestView* v2 = new TooltipTestView;
839 // v1_1 is a view inside v1 that has an identical tooltip text to that of v1
840 // and v2
841 TooltipTestView* v1_1 = new TooltipTestView;
842 // v2_1 is a view inside v2 that has an identical tooltip text to that of v1
843 // and v2
844 TooltipTestView* v2_1 = new TooltipTestView;
845 // v2_2 is a view inside v2 with the tooltip text different from all the
846 // others
847 TooltipTestView* v2_2 = new TooltipTestView;
848
849 // Setup all the views' relations
850 view_->AddChildView(v1);
851 view_->AddChildView(v2);
852 v1->AddChildView(v1_1);
853 v2->AddChildView(v2_1);
854 v2->AddChildView(v2_2);
855 const base::string16 reference_string(
856 base::ASCIIToUTF16("Identical Tooltip Text"));
857 const base::string16 alternative_string(
858 base::ASCIIToUTF16("Another Shrubbery"));
859 v1->set_tooltip_text(reference_string);
860 v2->set_tooltip_text(reference_string);
861 v1_1->set_tooltip_text(reference_string);
862 v2_1->set_tooltip_text(reference_string);
863 v2_2->set_tooltip_text(alternative_string);
864
865 // Set views' bounds
866 gfx::Rect view_bounds(view_->GetLocalBounds());
867 view_bounds.set_height(view_bounds.height() / 2);
868 v1->SetBoundsRect(view_bounds);
869 v1_1->SetBounds(0, 0, 3, 3);
870 view_bounds.set_y(view_bounds.height());
871 v2->SetBoundsRect(view_bounds);
872 v2_2->SetBounds(view_bounds.width() - 3, view_bounds.height() - 3, 3, 3);
873 v2_1->SetBounds(0, 0, 3, 3);
874
875 // Test whether a toolbar appears on v1
876 gfx::Point center = v1->bounds().CenterPoint();
877 generator_->MoveMouseRelativeTo(GetWindow(), center);
878 helper_->FireTooltipTimer();
879 EXPECT_TRUE(helper_->IsTooltipVisible());
880 EXPECT_EQ(reference_string, helper_->GetTooltipText());
881 gfx::Point tooltip_bounds1 = test_tooltip_->location();
882
883 // Test whether the toolbar changes position on mouse over v2
884 center = v2->bounds().CenterPoint();
885 generator_->MoveMouseRelativeTo(GetWindow(), center);
886 helper_->FireTooltipTimer();
887 EXPECT_TRUE(helper_->IsTooltipVisible());
888 EXPECT_EQ(reference_string, helper_->GetTooltipText());
889 gfx::Point tooltip_bounds2 = test_tooltip_->location();
890
891 EXPECT_NE(tooltip_bounds1, gfx::Point());
892 EXPECT_NE(tooltip_bounds2, gfx::Point());
893 EXPECT_NE(tooltip_bounds1, tooltip_bounds2);
894
895 // Test if the toolbar does not change position on encountering a contained
896 // view with the same tooltip text
897 center = v2_1->GetLocalBounds().CenterPoint();
898 views::View::ConvertPointToTarget(v2_1, view_, &center);
899 generator_->MoveMouseRelativeTo(GetWindow(), center);
900 helper_->FireTooltipTimer();
901 gfx::Point tooltip_bounds2_1 = test_tooltip_->location();
902
903 EXPECT_NE(tooltip_bounds2, tooltip_bounds2_1);
904 EXPECT_TRUE(helper_->IsTooltipVisible());
905 EXPECT_EQ(reference_string, helper_->GetTooltipText());
906
907 // Test if the toolbar changes position on encountering a contained
908 // view with a different tooltip text
909 center = v2_2->GetLocalBounds().CenterPoint();
910 views::View::ConvertPointToTarget(v2_2, view_, &center);
911 generator_->MoveMouseRelativeTo(GetWindow(), center);
912 helper_->FireTooltipTimer();
913 gfx::Point tooltip_bounds2_2 = test_tooltip_->location();
914
915 EXPECT_NE(tooltip_bounds2_1, tooltip_bounds2_2);
916 EXPECT_TRUE(helper_->IsTooltipVisible());
917 EXPECT_EQ(alternative_string, helper_->GetTooltipText());
918
919 // Test if moving from a view that is contained by a larger view, both with
920 // the same tooltip text, does not change tooltip's position.
921 center = v1_1->GetLocalBounds().CenterPoint();
922 views::View::ConvertPointToTarget(v1_1, view_, &center);
923 generator_->MoveMouseRelativeTo(GetWindow(), center);
924 helper_->FireTooltipTimer();
925 gfx::Point tooltip_bounds1_1 = test_tooltip_->location();
926
927 EXPECT_TRUE(helper_->IsTooltipVisible());
928 EXPECT_EQ(reference_string, helper_->GetTooltipText());
929
930 center = v1->bounds().CenterPoint();
931 generator_->MoveMouseRelativeTo(GetWindow(), center);
932 helper_->FireTooltipTimer();
933 tooltip_bounds1 = test_tooltip_->location();
934
935 EXPECT_NE(tooltip_bounds1_1, tooltip_bounds1);
936 EXPECT_EQ(reference_string, helper_->GetTooltipText());
937 }
938
769 } // namespace test 939 } // namespace test
770 } // namespace corewm 940 } // namespace corewm
771 } // namespace views 941 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698