summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-21 12:33:31 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-21 12:33:31 +0000
commita7eb0183946f145e0438918789afdfc76d5fa819 (patch)
tree38ef53021fe36bf2a24c805d0f15ce7a8202a62c /ui
parentcff28407f2720287045f3eddbb0ba69c0a8c394b (diff)
downloadchromium_src-a7eb0183946f145e0438918789afdfc76d5fa819.zip
chromium_src-a7eb0183946f145e0438918789afdfc76d5fa819.tar.gz
chromium_src-a7eb0183946f145e0438918789afdfc76d5fa819.tar.bz2
aura: Fix tooltips that were broken in a previous change. Also add tests.
BUG=none TEST=added new test Review URL: http://codereview.chromium.org/9006035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura_shell/aura_shell.gyp1
-rw-r--r--ui/aura_shell/shell.cc2
-rw-r--r--ui/aura_shell/tooltip_controller.h7
-rw-r--r--ui/aura_shell/tooltip_controller_unittest.cc179
4 files changed, 189 insertions, 0 deletions
diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp
index 1f86119..8d23b0c 100644
--- a/ui/aura_shell/aura_shell.gyp
+++ b/ui/aura_shell/aura_shell.gyp
@@ -178,6 +178,7 @@
'test/test_activation_delegate.h',
'test/test_shell_delegate.cc',
'test/test_shell_delegate.h',
+ 'tooltip_controller_unittest.cc',
'toplevel_layout_manager_unittest.cc',
'toplevel_window_event_filter_unittest.cc',
'workspace_controller_unittest.cc',
diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc
index 087a315..de891c8 100644
--- a/ui/aura_shell/shell.cc
+++ b/ui/aura_shell/shell.cc
@@ -130,6 +130,7 @@ Shell::~Shell() {
// TooltipController needs a valid shell instance. We delete it before
// deleting the shell |instance_|.
RemoveRootWindowEventFilter(tooltip_controller_.get());
+ aura::client::SetTooltipClient(NULL);
// Make sure we delete WorkspaceController before launcher is
// deleted as it has a reference to launcher model.
@@ -207,6 +208,7 @@ void Shell::Init() {
// Initialize TooltipController.
tooltip_controller_.reset(new internal::TooltipController);
AddRootWindowEventFilter(tooltip_controller_.get());
+ aura::client::SetTooltipClient(tooltip_controller_.get());
// Initialize drag drop controller.
drag_drop_controller_.reset(new internal::DragDropController);
diff --git a/ui/aura_shell/tooltip_controller.h b/ui/aura_shell/tooltip_controller.h
index c84f48d..bc56b43 100644
--- a/ui/aura_shell/tooltip_controller.h
+++ b/ui/aura_shell/tooltip_controller.h
@@ -23,6 +23,11 @@ class Window;
}
namespace aura_shell {
+
+namespace test {
+class TooltipControllerTest;
+} // namespace test
+
namespace internal {
// TooltipController provides tooltip functionality for aura shell.
@@ -48,6 +53,8 @@ class AURA_SHELL_EXPORT TooltipController : public aura::client::TooltipClient,
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
private:
+ friend class aura_shell::test::TooltipControllerTest;
+
class Tooltip;
void TooltipTimerFired();
diff --git a/ui/aura_shell/tooltip_controller_unittest.cc b/ui/aura_shell/tooltip_controller_unittest.cc
new file mode 100644
index 0000000..c9db815
--- /dev/null
+++ b/ui/aura_shell/tooltip_controller_unittest.cc
@@ -0,0 +1,179 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/utf_string_conversions.h"
+#include "ui/aura/client/tooltip_client.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/window.h"
+#include "ui/aura_shell/test/aura_shell_test_base.h"
+#include "ui/aura_shell/tooltip_controller.h"
+#include "ui/gfx/point.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget.h"
+
+namespace aura_shell {
+namespace test {
+
+namespace {
+
+class TooltipTestView : public views::View {
+ public:
+ TooltipTestView() : views::View() {
+ }
+
+ void set_tooltip_text(string16 tooltip_text) { tooltip_text_ = tooltip_text; }
+
+ // Overridden from views::View
+ bool GetTooltipText(const gfx::Point& p, string16* tooltip) const {
+ *tooltip = tooltip_text_;
+ return true;
+ }
+
+ private:
+ string16 tooltip_text_;
+
+ DISALLOW_COPY_AND_ASSIGN(TooltipTestView);
+};
+
+views::Widget* CreateNewWidget() {
+ views::Widget* widget = new views::Widget;
+ views::Widget::InitParams params;
+ params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
+ params.accept_events = true;
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ params.parent = aura::RootWindow::GetInstance();
+ params.child = true;
+ widget->Init(params);
+ widget->Show();
+ return widget;
+}
+
+void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) {
+ if (!widget->GetContentsView()) {
+ views::View* contents_view = new views::View;
+ widget->SetContentsView(contents_view);
+ }
+
+ views::View* contents_view = widget->GetContentsView();
+ contents_view->AddChildView(view);
+ view->SetBounds(contents_view->width(), 0, 100, 100);
+ gfx::Rect contents_view_bounds = contents_view->bounds();
+ contents_view_bounds = contents_view_bounds.Union(view->bounds());
+ contents_view->SetBoundsRect(contents_view_bounds);
+ widget->SetBounds(contents_view_bounds);
+}
+
+aura_shell::internal::TooltipController* GetController() {
+ return static_cast<aura_shell::internal::TooltipController*>(
+ aura::client::GetTooltipClient());
+}
+
+void SimulateMouseMoveAtPoint(const gfx::Point& point) {
+ aura::MouseEvent event(ui::ET_MOUSE_MOVED, point, 0);
+ aura::RootWindow::GetInstance()->DispatchMouseEvent(&event);
+}
+
+} // namespace
+
+class TooltipControllerTest : public AuraShellTestBase {
+ public:
+ TooltipControllerTest() {}
+ virtual ~TooltipControllerTest() {}
+
+ string16 GetTooltipText() {
+ return GetController()->tooltip_text_;
+ }
+
+ aura::Window* GetTooltipWindow() {
+ return GetController()->tooltip_window_;
+ }
+
+ void FireTooltipTimer() {
+ GetController()->TooltipTimerFired();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest);
+};
+
+TEST_F(TooltipControllerTest, NonNullTooltipClient) {
+ EXPECT_TRUE(aura::client::GetTooltipClient() != NULL);
+ EXPECT_EQ(ASCIIToUTF16(""), GetTooltipText());
+ EXPECT_EQ(NULL, GetTooltipWindow());
+}
+
+TEST_F(TooltipControllerTest, ViewTooltip) {
+ views::Widget* widget = CreateNewWidget();
+ TooltipTestView* view = new TooltipTestView;
+ AddViewToWidgetAndResize(widget, view);
+ view->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
+ EXPECT_EQ(ASCIIToUTF16(""), GetTooltipText());
+ EXPECT_EQ(NULL, GetTooltipWindow());
+
+ gfx::Point point = gfx::Rect(view->bounds()).CenterPoint();
+ SimulateMouseMoveAtPoint(point);
+ aura::Window* window = widget->GetNativeView();
+ EXPECT_EQ(window,
+ aura::RootWindow::GetInstance()->GetEventHandlerForPoint(point));
+ EXPECT_TRUE(aura::client::GetTooltipText(window) != NULL);
+ string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
+ EXPECT_EQ(expected_tooltip, *aura::client::GetTooltipText(window));
+ EXPECT_EQ(ASCIIToUTF16(""), GetTooltipText());
+ EXPECT_EQ(window, GetTooltipWindow());
+
+ // Fire tooltip timer so tooltip becomes visible.
+ FireTooltipTimer();
+
+ point.Offset(1, 0);
+ SimulateMouseMoveAtPoint(point);
+
+ EXPECT_TRUE(aura::client::GetTooltipText(window) != NULL);
+ EXPECT_EQ(expected_tooltip, *aura::client::GetTooltipText(window));
+ EXPECT_EQ(expected_tooltip, GetTooltipText());
+ EXPECT_EQ(window, GetTooltipWindow());
+}
+
+TEST_F(TooltipControllerTest, TooltipsInMultipleViews) {
+ views::Widget* widget = CreateNewWidget();
+ TooltipTestView* view1 = new TooltipTestView;
+ AddViewToWidgetAndResize(widget, view1);
+ view1->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
+ EXPECT_EQ(ASCIIToUTF16(""), GetTooltipText());
+ EXPECT_EQ(NULL, GetTooltipWindow());
+
+ TooltipTestView* view2 = new TooltipTestView;
+ AddViewToWidgetAndResize(widget, view2);
+
+ aura::Window* window = widget->GetNativeView();
+ gfx::Point point = gfx::Rect(view1->bounds()).CenterPoint();
+
+ // Fire tooltip timer so tooltip becomes visible.
+ SimulateMouseMoveAtPoint(point);
+ FireTooltipTimer();
+ for (int i = 0; i < 50; i++) {
+ point.Offset(1, 0);
+ SimulateMouseMoveAtPoint(point);
+ EXPECT_EQ(window,
+ aura::RootWindow::GetInstance()->GetEventHandlerForPoint(point));
+ EXPECT_TRUE(aura::client::GetTooltipText(window) != NULL);
+ string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
+ EXPECT_EQ(expected_tooltip, *aura::client::GetTooltipText(window));
+ EXPECT_EQ(expected_tooltip, GetTooltipText());
+ EXPECT_EQ(window, GetTooltipWindow());
+ }
+ for (int i = 0; i < 50; i++) {
+ point.Offset(1, 0);
+ SimulateMouseMoveAtPoint(point);
+ EXPECT_EQ(window,
+ aura::RootWindow::GetInstance()->GetEventHandlerForPoint(point));
+ EXPECT_TRUE(aura::client::GetTooltipText(window) != NULL);
+ string16 expected_tooltip = ASCIIToUTF16("");
+ EXPECT_EQ(expected_tooltip, *aura::client::GetTooltipText(window));
+ EXPECT_EQ(expected_tooltip, GetTooltipText());
+ EXPECT_EQ(window, GetTooltipWindow());
+ }
+}
+
+} // namespace test
+} // namespace aura_shell