tooltip_controller_unittest.cc revision 116680a4aac90f2aa7413d9095a592090648e557
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/corewm/tooltip_controller.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/cursor_client.h"
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/client/screen_position_client.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/env.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/test/aura_test_base.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/test/event_generator.h"
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/test/test_screen.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/aura/test/test_window_delegate.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/window.h"
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/font.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/point.h"
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/gfx/screen.h"
214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/gfx/screen_type_delegate.h"
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/gfx/text_elider.h"
234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/views/corewm/tooltip_aura.h"
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/corewm/tooltip_controller_test_helper.h"
256d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "ui/views/test/desktop_test_views_delegate.h"
266d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "ui/views/test/test_views_delegate.h"
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/view.h"
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/views/widget/tooltip_manager.h"
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/widget.h"
305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ui/wm/core/default_activation_client.h"
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/wm_state.h"
32effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/tooltip_client.h"
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/wm/public/window_types.h"
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/win/scoped_ole_initializer.h"
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if !defined(OS_CHROMEOS)
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_screen.h"
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::ASCIIToUTF16;
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace views {
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace corewm {
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test {
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)views::Widget* CreateWidget(aura::Window* root) {
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::Widget* widget = new views::Widget;
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::Widget::InitParams params;
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.accept_events = true;
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_CHROMEOS)
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.parent = root;
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.native_widget = new DesktopNativeWidgetAura(widget);
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.bounds = gfx::Rect(0, 0, 200, 100);
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget->Init(params);
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget->Show();
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return widget;
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TooltipController* GetController(Widget* widget) {
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return static_cast<TooltipController*>(
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      aura::client::GetTooltipClient(
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          widget->GetNativeWindow()->GetRootWindow()));
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TooltipControllerTest : public aura::test::AuraTestBase {
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TooltipControllerTest() : view_(NULL) {}
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TooltipControllerTest() {}
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetUp() OVERRIDE {
826d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#if defined(OS_CHROMEOS)
836d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    views_delegate_.reset(new TestViewsDelegate);
846d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#else
856d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    views_delegate_.reset(new DesktopTestViewsDelegate);
866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#endif
876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::test::AuraTestBase::SetUp();
895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    new wm::DefaultActivationClient(root_window());
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_CHROMEOS)
914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    controller_.reset(new TooltipController(
924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          scoped_ptr<views::corewm::Tooltip>(
934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)              new views::corewm::TooltipAura(gfx::SCREEN_TYPE_ALTERNATE))));
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    root_window()->AddPreTargetHandler(controller_.get());
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    SetTooltipClient(root_window(), controller_.get());
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    widget_.reset(CreateWidget(root_window()));
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    widget_->SetContentsView(new View);
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    view_ = new TooltipTestView;
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    widget_->GetContentsView()->AddChildView(view_);
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds());
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    helper_.reset(new TooltipControllerTestHelper(
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                      GetController(widget_.get())));
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    generator_.reset(new aura::test::EventGenerator(GetRootWindow()));
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void TearDown() OVERRIDE {
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_CHROMEOS)
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    root_window()->RemovePreTargetHandler(controller_.get());
110f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    aura::client::SetTooltipClient(root_window(), NULL);
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    controller_.reset();
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    generator_.reset();
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    helper_.reset();
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    widget_.reset();
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::test::AuraTestBase::TearDown();
1176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    views_delegate_.reset();
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::Window* GetWindow() {
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return widget_->GetNativeWindow();
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* GetRootWindow() {
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return GetWindow()->GetRootWindow();
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TooltipTestView* PrepareSecondView() {
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    TooltipTestView* view2 = new TooltipTestView;
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    widget_->GetContentsView()->AddChildView(view2);
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    view_->SetBounds(0, 0, 100, 100);
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    view2->SetBounds(100, 0, 100, 100);
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return view2;
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<views::Widget> widget_;
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TooltipTestView* view_;
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<TooltipControllerTestHelper> helper_;
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<aura::test::EventGenerator> generator_;
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<TooltipController> controller_;
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1456d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  scoped_ptr<views::TestViewsDelegate> views_delegate_;
1466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ui::ScopedOleInitializer ole_initializer_;
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest);
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(TooltipControllerTest, ViewTooltip) {
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(NULL, helper_->GetTooltipWindow());
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->MoveMouseToCenterOf(GetWindow());
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(GetWindow(), GetRootWindow()->GetEventHandlerForPoint(
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      generator_->current_location()));
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(GetWindow()));
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(GetWindow(), helper_->GetTooltipWindow());
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->MoveMouseBy(1, 0);
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(GetWindow()));
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(GetWindow(), helper_->GetTooltipWindow());
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(TooltipControllerTest, TooltipsInMultipleViews) {
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(NULL, helper_->GetTooltipWindow());
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  PrepareSecondView();
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::Window* window = GetWindow();
1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root_window = GetRootWindow();
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->MoveMouseRelativeTo(window, view_->bounds().CenterPoint());
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (int i = 0; i < 49; ++i) {
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    generator_->MoveMouseBy(1, 0);
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_TRUE(helper_->IsTooltipVisible());
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(window, root_window->GetEventHandlerForPoint(
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            generator_->current_location()));
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(window, helper_->GetTooltipWindow());
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (int i = 0; i < 49; ++i) {
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    generator_->MoveMouseBy(1, 0);
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_FALSE(helper_->IsTooltipVisible());
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(window, root_window->GetEventHandlerForPoint(
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            generator_->current_location()));
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::string16 expected_tooltip;  // = ""
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(window, helper_->GetTooltipWindow());
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(TooltipControllerTest, EnableOrDisableTooltips) {
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(NULL, helper_->GetTooltipWindow());
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), view_->bounds().CenterPoint());
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Disable tooltips and check again.
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->controller()->SetTooltipsEnabled(false);
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Enable tooltips back and check again.
2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->controller()->SetTooltipsEnabled(true);
2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verifies tooltip isn't shown if tooltip text consists entirely of whitespace.
2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(TooltipControllerTest, DontShowEmptyTooltips) {
2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  view_->set_tooltip_text(ASCIIToUTF16("                     "));
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
2431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_EQ(NULL, helper_->GetTooltipWindow());
2441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), view_->bounds().CenterPoint());
2461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  helper_->FireTooltipTimer();
2481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
2491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(TooltipControllerTest, TooltipHidesOnKeyPressAndStaysHiddenUntilChange) {
2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 1"));
2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(NULL, helper_->GetTooltipWindow());
2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TooltipTestView* view2 = PrepareSecondView();
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  view2->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 2"));
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::Window* window = GetWindow();
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->MoveMouseRelativeTo(window, view_->bounds().CenterPoint());
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipShownTimerRunning());
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->PressKey(ui::VKEY_1, 0);
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipTimerRunning());
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipShownTimerRunning());
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Moving the mouse inside |view1| should not change the state of the tooltip
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // or the timers.
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (int i = 0; i < 49; i++) {
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    generator_->MoveMouseBy(1, 0);
2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_FALSE(helper_->IsTooltipVisible());
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_FALSE(helper_->IsTooltipTimerRunning());
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_FALSE(helper_->IsTooltipShownTimerRunning());
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(window,
2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              GetRootWindow()->GetEventHandlerForPoint(
2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  generator_->current_location()));
2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 1");
2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(window, helper_->GetTooltipWindow());
2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Now we move the mouse on to |view2|. It should re-start the tooltip timer.
2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->MoveMouseBy(1, 0);
2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipTimerRunning());
2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipShownTimerRunning());
2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 2");
2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(window, helper_->GetTooltipWindow());
2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(TooltipControllerTest, TooltipHidesOnTimeoutAndStaysHiddenUntilChange) {
3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 1"));
3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(NULL, helper_->GetTooltipWindow());
3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TooltipTestView* view2 = PrepareSecondView();
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  view2->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 2"));
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::Window* window = GetWindow();
3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->MoveMouseRelativeTo(window, view_->bounds().CenterPoint());
3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipShownTimerRunning());
3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipShownTimer();
3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipTimerRunning());
3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipShownTimerRunning());
3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Moving the mouse inside |view1| should not change the state of the tooltip
3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // or the timers.
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (int i = 0; i < 49; ++i) {
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    generator_->MoveMouseBy(1, 0);
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_FALSE(helper_->IsTooltipVisible());
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_FALSE(helper_->IsTooltipTimerRunning());
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_FALSE(helper_->IsTooltipShownTimerRunning());
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(window, GetRootWindow()->GetEventHandlerForPoint(
3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  generator_->current_location()));
3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 1");
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(window, helper_->GetTooltipWindow());
3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Now we move the mouse on to |view2|. It should re-start the tooltip timer.
3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  generator_->MoveMouseBy(1, 0);
3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipTimerRunning());
3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  helper_->FireTooltipTimer();
3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipShownTimerRunning());
3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 2");
3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(expected_tooltip, helper_->GetTooltipText());
3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(window, helper_->GetTooltipWindow());
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
348424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Verifies a mouse exit event hides the tooltips.
349424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)TEST_F(TooltipControllerTest, HideOnExit) {
350424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
351424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  generator_->MoveMouseToCenterOf(GetWindow());
3525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
353424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(GetWindow()));
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
355424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(GetWindow(), helper_->GetTooltipWindow());
356424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
357424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
358424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  helper_->FireTooltipTimer();
359424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
360424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
361424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  generator_->SendMouseExit();
362424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
363424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
364424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(TooltipControllerTest, ReshowOnClickAfterEnterExit) {
3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Owned by |view_|.
3675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  TooltipTestView* v1 = new TooltipTestView;
3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  TooltipTestView* v2 = new TooltipTestView;
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  view_->AddChildView(v1);
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  view_->AddChildView(v2);
3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Rect view_bounds(view_->GetLocalBounds());
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  view_bounds.set_height(view_bounds.height() / 2);
3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  v1->SetBoundsRect(view_bounds);
3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  view_bounds.set_y(view_bounds.height());
3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  v2->SetBoundsRect(view_bounds);
3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::string16 v1_tt(ASCIIToUTF16("v1"));
3775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::string16 v2_tt(ASCIIToUTF16("v2"));
3785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  v1->set_tooltip_text(v1_tt);
3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  v2->set_tooltip_text(v2_tt);
3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Point v1_point(1, 1);
3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  View::ConvertPointToWidget(v1, &v1_point);
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), v1_point);
3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  helper_->FireTooltipTimer();
3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(v1_tt, helper_->GetTooltipText());
3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Press the mouse, move to v2 and back to v1.
3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator_->ClickLeftButton();
3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Point v2_point(1, 1);
3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  View::ConvertPointToWidget(v2, &v2_point);
3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), v2_point);
3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), v1_point);
3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  helper_->FireTooltipTimer();
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(v1_tt, helper_->GetTooltipText());
4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace {
4041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Returns the index of |window| in its parent's children.
4061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)int IndexInParent(const aura::Window* window) {
4071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window::Windows::const_iterator i =
4081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      std::find(window->parent()->children().begin(),
4091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                window->parent()->children().end(),
4101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                window);
4111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return i == window->parent()->children().end() ? -1 :
4121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      static_cast<int>(i - window->parent()->children().begin());
4131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
4141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TestScreenPositionClient : public aura::client::ScreenPositionClient {
4161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
4171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestScreenPositionClient() {}
4181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~TestScreenPositionClient() {}
4191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // ScreenPositionClient overrides:
4211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void ConvertPointToScreen(const aura::Window* window,
4221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                    gfx::Point* point) OVERRIDE {
4231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
4241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void ConvertPointFromScreen(const aura::Window* window,
4251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                      gfx::Point* point) OVERRIDE {
4261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
4271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void ConvertHostPointToScreen(aura::Window* root_gwindow,
4281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                        gfx::Point* point) OVERRIDE {
4291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    NOTREACHED();
4301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
4311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void SetBounds(aura::Window* window,
4321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                         const gfx::Rect& bounds,
4331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                         const gfx::Display& display) OVERRIDE {
4341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    window->SetBounds(bounds);
4351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
4361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
4381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestScreenPositionClient);
4391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
4401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace
4421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TooltipControllerCaptureTest : public TooltipControllerTest {
4441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
4451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TooltipControllerCaptureTest() {}
4461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~TooltipControllerCaptureTest() {}
4471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
4491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    TooltipControllerTest::SetUp();
4501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    aura::client::SetScreenPositionClient(GetRootWindow(),
4511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                          &screen_position_client_);
4521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if !defined(OS_CHROMEOS)
4531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    desktop_screen_.reset(CreateDesktopScreen());
4541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
4551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                   desktop_screen_.get());
4561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif
4571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
4581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
4601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if !defined(OS_CHROMEOS)
4611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen());
4621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    desktop_screen_.reset();
4631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif
4641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    aura::client::SetScreenPositionClient(GetRootWindow(), NULL);
4651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    TooltipControllerTest::TearDown();
4661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
4671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
4691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestScreenPositionClient screen_position_client_;
4701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<gfx::Screen> desktop_screen_;
4711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TooltipControllerCaptureTest);
4731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
4741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verifies when capture is released the TooltipController resets state.
476116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Flaky on all builders.  http://crbug.com/388268
477116680a4aac90f2aa7413d9095a592090648e557Ben MurdochTEST_F(TooltipControllerCaptureTest, DISABLED_CloseOnCaptureLost) {
4781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  view_->GetWidget()->SetCapture(view_);
479c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  RunAllPendingInMessageLoop();
4801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
4811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  generator_->MoveMouseToCenterOf(GetWindow());
4825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
4831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(GetWindow()));
4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(base::string16(), helper_->GetTooltipText());
4851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_EQ(GetWindow(), helper_->GetTooltipWindow());
4861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
4881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  helper_->FireTooltipTimer();
4891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
4911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  view_->GetWidget()->ReleaseCapture();
4921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
4931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(helper_->GetTooltipWindow() == NULL);
4941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
4951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Disabled on linux as DesktopScreenX11::GetWindowAtScreenPoint() doesn't
4971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// consider z-order.
4981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
4991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define MAYBE_Capture DISABLED_Capture
5001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#else
5011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define MAYBE_Capture Capture
5021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif
5031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verifies the correct window is found for tooltips when there is a capture.
5041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(TooltipControllerCaptureTest, MAYBE_Capture) {
5055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::string16 tooltip_text(ASCIIToUTF16("1"));
5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::string16 tooltip_text2(ASCIIToUTF16("2"));
5071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget_->SetBounds(gfx::Rect(0, 0, 200, 200));
5091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  view_->set_tooltip_text(tooltip_text);
5101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<views::Widget> widget2(CreateWidget(root_window()));
5121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget2->SetContentsView(new View);
5131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TooltipTestView* view2 = new TooltipTestView;
5141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget2->GetContentsView()->AddChildView(view2);
5151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  view2->set_tooltip_text(tooltip_text2);
5161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget2->SetBounds(gfx::Rect(0, 0, 200, 200));
5171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  view2->SetBoundsRect(widget2->GetContentsView()->GetLocalBounds());
5181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget_->SetCapture(view_);
5201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(widget_->HasCapture());
5211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget2->Show();
5221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_GE(IndexInParent(widget2->GetNativeWindow()),
5231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            IndexInParent(widget_->GetNativeWindow()));
5241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  generator_->MoveMouseRelativeTo(widget_->GetNativeWindow(),
5261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                  view_->bounds().CenterPoint());
5271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipTimerRunning());
5291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  helper_->FireTooltipTimer();
5301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Even though the mouse is over a window with a tooltip it shouldn't be
5311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // picked up because the windows don't have the same value for
5321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // |TooltipManager::kGroupingPropertyKey|.
5331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(helper_->GetTooltipText().empty());
5341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Now make both the windows have same transient value for
5361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // kGroupingPropertyKey. In this case the tooltip should be picked up from
5371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // |widget2| (because the mouse is over it).
5381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  const int grouping_key = 1;
5391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget_->SetNativeWindowProperty(TooltipManager::kGroupingPropertyKey,
5401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                   reinterpret_cast<void*>(grouping_key));
5411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget2->SetNativeWindowProperty(TooltipManager::kGroupingPropertyKey,
5421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                   reinterpret_cast<void*>(grouping_key));
5431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  generator_->MoveMouseBy(1, 10);
5441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipTimerRunning());
5451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  helper_->FireTooltipTimer();
5461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_EQ(tooltip_text2, helper_->GetTooltipText());
5471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  widget2.reset();
5491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
5501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace {
5525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TestTooltip : public Tooltip {
5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  TestTooltip() : is_visible_(false) {}
5565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~TestTooltip() {}
5575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::string16& tooltip_text() const { return tooltip_text_; }
5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Tooltip:
5615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetText(aura::Window* window,
5625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       const base::string16& tooltip_text,
5635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       const gfx::Point& location) OVERRIDE {
5645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    tooltip_text_ = tooltip_text;
565f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    location_ = location;
5665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Show() OVERRIDE {
5685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    is_visible_ = true;
5695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
5705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Hide() OVERRIDE {
5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    is_visible_ = false;
5725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
5735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool IsVisible() OVERRIDE {
5745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return is_visible_;
5755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
576f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const gfx::Point& location() { return location_; }
5775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
5795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool is_visible_;
5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 tooltip_text_;
581f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point location_;
5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestTooltip);
5845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
5855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace
5875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use for tests that don't depend upon views.
5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TooltipControllerTest2 : public aura::test::AuraTestBase {
5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  TooltipControllerTest2() : test_tooltip_(new TestTooltip) {}
5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~TooltipControllerTest2() {}
5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
595a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    wm_state_.reset(new wm::WMState);
5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    aura::test::AuraTestBase::SetUp();
5975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    new wm::DefaultActivationClient(root_window());
5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    controller_.reset(new TooltipController(
599a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                          scoped_ptr<corewm::Tooltip>(test_tooltip_)));
6005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    root_window()->AddPreTargetHandler(controller_.get());
6015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    SetTooltipClient(root_window(), controller_.get());
6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    helper_.reset(new TooltipControllerTestHelper(controller_.get()));
6035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    generator_.reset(new aura::test::EventGenerator(root_window()));
6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    root_window()->RemovePreTargetHandler(controller_.get());
6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    aura::client::SetTooltipClient(root_window(), NULL);
6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    controller_.reset();
6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    generator_.reset();
6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    helper_.reset();
6125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    aura::test::AuraTestBase::TearDown();
6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    wm_state_.reset();
6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected:
6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Owned by |controller_|.
6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  TestTooltip* test_tooltip_;
6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<TooltipControllerTestHelper> helper_;
6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::test::EventGenerator> generator_;
6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
6235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<TooltipController> controller_;
624a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  scoped_ptr<wm::WMState> wm_state_;
6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest2);
6275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
6285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(TooltipControllerTest2, VerifyLeadingTrailingWhitespaceStripped) {
6305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::test::TestWindowDelegate test_delegate;
6315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window(
6325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      CreateNormalWindow(100, root_window(), &test_delegate));
6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  window->SetBounds(gfx::Rect(0, 0, 300, 300));
6345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 tooltip_text(ASCIIToUTF16(" \nx  "));
6355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::client::SetTooltipText(window.get(), &tooltip_text);
6365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator_->MoveMouseToCenterOf(window.get());
6375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  helper_->FireTooltipTimer();
6385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ASCIIToUTF16("x"), test_tooltip_->tooltip_text());
6395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Verifies that tooltip is hidden and tooltip window closed upon cancel mode.
6425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(TooltipControllerTest2, CloseOnCancelMode) {
6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::test::TestWindowDelegate test_delegate;
6445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window(
6455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      CreateNormalWindow(100, root_window(), &test_delegate));
6465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  window->SetBounds(gfx::Rect(0, 0, 300, 300));
6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 tooltip_text(ASCIIToUTF16("Tooltip Text"));
6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::client::SetTooltipText(window.get(), &tooltip_text);
6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator_->MoveMouseToCenterOf(window.get());
6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Fire tooltip timer so tooltip becomes visible.
6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  helper_->FireTooltipTimer();
6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
6545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Send OnCancelMode event and verify that tooltip becomes invisible and
6565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the tooltip window is closed.
6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ui::CancelModeEvent event;
6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  helper_->controller()->OnCancelMode(&event);
6595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(helper_->IsTooltipVisible());
6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(helper_->GetTooltipWindow() == NULL);
6615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
663f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Use for tests that need both views and a TestTooltip.
664f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class TooltipControllerTest3 : public aura::test::AuraTestBase {
665f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) public:
666f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  TooltipControllerTest3() : test_tooltip_(new TestTooltip) {}
667f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual ~TooltipControllerTest3() {}
668f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
669f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
670f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    wm_state_.reset(new wm::WMState);
671f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    aura::test::AuraTestBase::SetUp();
672f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    new wm::DefaultActivationClient(root_window());
673f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
674f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    widget_.reset(CreateWidget(root_window()));
675f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    widget_->SetContentsView(new View);
676f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    view_ = new TooltipTestView;
677f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    widget_->GetContentsView()->AddChildView(view_);
678f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds());
679f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
680f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    generator_.reset(new aura::test::EventGenerator(GetRootWindow()));
681f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    controller_.reset(new TooltipController(
682f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        scoped_ptr<views::corewm::Tooltip>(test_tooltip_)));
683f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    GetRootWindow()->RemovePreTargetHandler(
684f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        static_cast<TooltipController*>(aura::client::GetTooltipClient(
685f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)            widget_->GetNativeWindow()->GetRootWindow())));
686f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    GetRootWindow()->AddPreTargetHandler(controller_.get());
687f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    helper_.reset(new TooltipControllerTestHelper(controller_.get()));
688f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    SetTooltipClient(GetRootWindow(), controller_.get());
689f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
690f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
691f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
692f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    GetRootWindow()->RemovePreTargetHandler(controller_.get());
693f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    aura::client::SetTooltipClient(GetRootWindow(), NULL);
694f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
695f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    controller_.reset();
696f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    generator_.reset();
697f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    helper_.reset();
698f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    widget_.reset();
699f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    aura::test::AuraTestBase::TearDown();
700f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    wm_state_.reset();
701f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
702f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
703f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  aura::Window* GetWindow() { return widget_->GetNativeWindow(); }
704f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
705f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) protected:
706f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Owned by |controller_|.
707f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  TestTooltip* test_tooltip_;
708f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<TooltipControllerTestHelper> helper_;
709f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<aura::test::EventGenerator> generator_;
710f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<views::Widget> widget_;
711f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  TooltipTestView* view_;
712f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
713f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) private:
714f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<TooltipController> controller_;
715f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<wm::WMState> wm_state_;
716f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
717f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#if defined(OS_WIN)
718f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ui::ScopedOleInitializer ole_initializer_;
719f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#endif
720f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
721f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  aura::Window* GetRootWindow() { return GetWindow()->GetRootWindow(); }
722f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
723f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest3);
724f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)};
725f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
726f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)TEST_F(TooltipControllerTest3, TooltipPositionChangesOnTwoViewsWithSameLabel) {
727f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Owned by |view_|.
728f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // These two views have the same tooltip text
729f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  TooltipTestView* v1 = new TooltipTestView;
730f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  TooltipTestView* v2 = new TooltipTestView;
731f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // v1_1 is a view inside v1 that has an identical tooltip text to that of v1
732f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // and v2
733f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  TooltipTestView* v1_1 = new TooltipTestView;
734f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // v2_1 is a view inside v2 that has an identical tooltip text to that of v1
735f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // and v2
736f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  TooltipTestView* v2_1 = new TooltipTestView;
737f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // v2_2 is a view inside v2 with the tooltip text different from all the
738f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // others
739f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  TooltipTestView* v2_2 = new TooltipTestView;
740f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
741f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Setup all the views' relations
742f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  view_->AddChildView(v1);
743f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  view_->AddChildView(v2);
744f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v1->AddChildView(v1_1);
745f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v2->AddChildView(v2_1);
746f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v2->AddChildView(v2_2);
747f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const base::string16 reference_string(
748f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      base::ASCIIToUTF16("Identical Tooltip Text"));
749f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const base::string16 alternative_string(
750f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      base::ASCIIToUTF16("Another Shrubbery"));
751f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v1->set_tooltip_text(reference_string);
752f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v2->set_tooltip_text(reference_string);
753f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v1_1->set_tooltip_text(reference_string);
754f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v2_1->set_tooltip_text(reference_string);
755f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v2_2->set_tooltip_text(alternative_string);
756f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
757f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Set views' bounds
758f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Rect view_bounds(view_->GetLocalBounds());
759f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  view_bounds.set_height(view_bounds.height() / 2);
760f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v1->SetBoundsRect(view_bounds);
761f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v1_1->SetBounds(0, 0, 3, 3);
762f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  view_bounds.set_y(view_bounds.height());
763f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v2->SetBoundsRect(view_bounds);
764f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v2_2->SetBounds(view_bounds.width() - 3, view_bounds.height() - 3, 3, 3);
765f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  v2_1->SetBounds(0, 0, 3, 3);
766f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
767f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Test whether a toolbar appears on v1
768f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point center = v1->bounds().CenterPoint();
769f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), center);
770f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  helper_->FireTooltipTimer();
771f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
772f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(reference_string, helper_->GetTooltipText());
773f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point tooltip_bounds1 = test_tooltip_->location();
774f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
775f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Test whether the toolbar changes position on mouse over v2
776f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  center = v2->bounds().CenterPoint();
777f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), center);
778f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  helper_->FireTooltipTimer();
779f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
780f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(reference_string, helper_->GetTooltipText());
781f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point tooltip_bounds2 = test_tooltip_->location();
782f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
783f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_NE(tooltip_bounds1, gfx::Point());
784f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_NE(tooltip_bounds2, gfx::Point());
785f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_NE(tooltip_bounds1, tooltip_bounds2);
786f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
787f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Test if the toolbar does not change position on encountering a contained
788f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // view with the same tooltip text
789f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  center = v2_1->GetLocalBounds().CenterPoint();
790f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  views::View::ConvertPointToTarget(v2_1, view_, &center);
791f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), center);
792f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  helper_->FireTooltipTimer();
793f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point tooltip_bounds2_1 = test_tooltip_->location();
794f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
795f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_NE(tooltip_bounds2, tooltip_bounds2_1);
796f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
797f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(reference_string, helper_->GetTooltipText());
798f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
799f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Test if the toolbar changes position on encountering a contained
800f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // view with a different tooltip text
801f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  center = v2_2->GetLocalBounds().CenterPoint();
802f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  views::View::ConvertPointToTarget(v2_2, view_, &center);
803f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), center);
804f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  helper_->FireTooltipTimer();
805f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point tooltip_bounds2_2 = test_tooltip_->location();
806f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
807f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_NE(tooltip_bounds2_1, tooltip_bounds2_2);
808f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
809f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(alternative_string, helper_->GetTooltipText());
810f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
811f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Test if moving from a view that is contained by a larger view, both with
812f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // the same tooltip text, does not change tooltip's position.
813f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  center = v1_1->GetLocalBounds().CenterPoint();
814f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  views::View::ConvertPointToTarget(v1_1, view_, &center);
815f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), center);
816f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  helper_->FireTooltipTimer();
817f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point tooltip_bounds1_1 = test_tooltip_->location();
818f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
819f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(helper_->IsTooltipVisible());
820f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(reference_string, helper_->GetTooltipText());
821f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
822f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  center = v1->bounds().CenterPoint();
823f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  generator_->MoveMouseRelativeTo(GetWindow(), center);
824f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  helper_->FireTooltipTimer();
825f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  tooltip_bounds1 = test_tooltip_->location();
826f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
827f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_NE(tooltip_bounds1_1, tooltip_bounds1);
828f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(reference_string, helper_->GetTooltipText());
829f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
830f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
8312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace test
8322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace corewm
8332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace views
834