| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/corewm/tooltip_controller.h" | 5 #include "ui/views/corewm/tooltip_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/aura/client/cursor_client.h" | 8 #include "ui/aura/client/cursor_client.h" |
| 9 #include "ui/aura/client/screen_position_client.h" | 9 #include "ui/aura/client/screen_position_client.h" |
| 10 #include "ui/aura/client/tooltip_client.h" | 10 #include "ui/aura/client/tooltip_client.h" |
| 11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
| 12 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/test/aura_test_base.h" | 13 #include "ui/aura/test/aura_test_base.h" |
| 14 #include "ui/aura/test/event_generator.h" | 14 #include "ui/aura/test/event_generator.h" |
| 15 #include "ui/aura/test/test_screen.h" | 15 #include "ui/aura/test/test_screen.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/font.h" | 18 #include "ui/gfx/font.h" |
| 19 #include "ui/gfx/point.h" | 19 #include "ui/gfx/point.h" |
| 20 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
| 21 #include "ui/gfx/screen_type_delegate.h" | 21 #include "ui/gfx/screen_type_delegate.h" |
| 22 #include "ui/gfx/text_elider.h" | 22 #include "ui/gfx/text_elider.h" |
| 23 #include "ui/views/corewm/tooltip_aura.h" | 23 #include "ui/views/corewm/tooltip_aura.h" |
| 24 #include "ui/views/corewm/tooltip_controller_test_helper.h" | 24 #include "ui/views/corewm/tooltip_controller_test_helper.h" |
| 25 #include "ui/views/corewm/wm_state.h" |
| 25 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
| 26 #include "ui/views/widget/tooltip_manager.h" | 27 #include "ui/views/widget/tooltip_manager.h" |
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 28 #include "ui/wm/public/window_types.h" | 29 #include "ui/wm/public/window_types.h" |
| 29 | 30 |
| 30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 31 #include "ui/base/win/scoped_ole_initializer.h" | 32 #include "ui/base/win/scoped_ole_initializer.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 #if !defined(OS_CHROMEOS) | 35 #if !defined(OS_CHROMEOS) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 65 } | 66 } |
| 66 | 67 |
| 67 } // namespace | 68 } // namespace |
| 68 | 69 |
| 69 class TooltipControllerTest : public aura::test::AuraTestBase { | 70 class TooltipControllerTest : public aura::test::AuraTestBase { |
| 70 public: | 71 public: |
| 71 TooltipControllerTest() : view_(NULL) {} | 72 TooltipControllerTest() : view_(NULL) {} |
| 72 virtual ~TooltipControllerTest() {} | 73 virtual ~TooltipControllerTest() {} |
| 73 | 74 |
| 74 virtual void SetUp() OVERRIDE { | 75 virtual void SetUp() OVERRIDE { |
| 76 wm_state_.reset(new views::corewm::WMState); |
| 75 aura::test::AuraTestBase::SetUp(); | 77 aura::test::AuraTestBase::SetUp(); |
| 76 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
| 77 controller_.reset(new TooltipController( | 79 controller_.reset(new TooltipController( |
| 78 scoped_ptr<views::corewm::Tooltip>( | 80 scoped_ptr<views::corewm::Tooltip>( |
| 79 new views::corewm::TooltipAura(gfx::SCREEN_TYPE_ALTERNATE)))); | 81 new views::corewm::TooltipAura(gfx::SCREEN_TYPE_ALTERNATE)))); |
| 80 root_window()->AddPreTargetHandler(controller_.get()); | 82 root_window()->AddPreTargetHandler(controller_.get()); |
| 81 SetTooltipClient(root_window(), controller_.get()); | 83 SetTooltipClient(root_window(), controller_.get()); |
| 82 #endif | 84 #endif |
| 83 widget_.reset(CreateWidget(root_window())); | 85 widget_.reset(CreateWidget(root_window())); |
| 84 widget_->SetContentsView(new View); | 86 widget_->SetContentsView(new View); |
| 85 view_ = new TooltipTestView; | 87 view_ = new TooltipTestView; |
| 86 widget_->GetContentsView()->AddChildView(view_); | 88 widget_->GetContentsView()->AddChildView(view_); |
| 87 view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds()); | 89 view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds()); |
| 88 helper_.reset(new TooltipControllerTestHelper( | 90 helper_.reset(new TooltipControllerTestHelper( |
| 89 GetController(widget_.get()))); | 91 GetController(widget_.get()))); |
| 90 generator_.reset(new aura::test::EventGenerator(GetRootWindow())); | 92 generator_.reset(new aura::test::EventGenerator(GetRootWindow())); |
| 91 } | 93 } |
| 92 | 94 |
| 93 virtual void TearDown() OVERRIDE { | 95 virtual void TearDown() OVERRIDE { |
| 94 #if defined(OS_CHROMEOS) | 96 #if defined(OS_CHROMEOS) |
| 95 root_window()->RemovePreTargetHandler(controller_.get()); | 97 root_window()->RemovePreTargetHandler(controller_.get()); |
| 96 aura::client::SetTooltipClient(root_window(), NULL); | 98 aura::client::SetTooltipClient(root_window(), NULL); |
| 97 controller_.reset(); | 99 controller_.reset(); |
| 98 #endif | 100 #endif |
| 99 generator_.reset(); | 101 generator_.reset(); |
| 100 helper_.reset(); | 102 helper_.reset(); |
| 101 widget_.reset(); | 103 widget_.reset(); |
| 102 aura::test::AuraTestBase::TearDown(); | 104 aura::test::AuraTestBase::TearDown(); |
| 105 wm_state_.reset(); |
| 103 } | 106 } |
| 104 | 107 |
| 105 protected: | 108 protected: |
| 106 aura::Window* GetWindow() { | 109 aura::Window* GetWindow() { |
| 107 return widget_->GetNativeWindow(); | 110 return widget_->GetNativeWindow(); |
| 108 } | 111 } |
| 109 | 112 |
| 110 aura::Window* GetRootWindow() { | 113 aura::Window* GetRootWindow() { |
| 111 return GetWindow()->GetRootWindow(); | 114 return GetWindow()->GetRootWindow(); |
| 112 } | 115 } |
| 113 | 116 |
| 114 TooltipTestView* PrepareSecondView() { | 117 TooltipTestView* PrepareSecondView() { |
| 115 TooltipTestView* view2 = new TooltipTestView; | 118 TooltipTestView* view2 = new TooltipTestView; |
| 116 widget_->GetContentsView()->AddChildView(view2); | 119 widget_->GetContentsView()->AddChildView(view2); |
| 117 view_->SetBounds(0, 0, 100, 100); | 120 view_->SetBounds(0, 0, 100, 100); |
| 118 view2->SetBounds(100, 0, 100, 100); | 121 view2->SetBounds(100, 0, 100, 100); |
| 119 return view2; | 122 return view2; |
| 120 } | 123 } |
| 121 | 124 |
| 122 scoped_ptr<views::Widget> widget_; | 125 scoped_ptr<views::Widget> widget_; |
| 123 TooltipTestView* view_; | 126 TooltipTestView* view_; |
| 124 scoped_ptr<TooltipControllerTestHelper> helper_; | 127 scoped_ptr<TooltipControllerTestHelper> helper_; |
| 125 scoped_ptr<aura::test::EventGenerator> generator_; | 128 scoped_ptr<aura::test::EventGenerator> generator_; |
| 126 | 129 |
| 127 private: | 130 private: |
| 128 scoped_ptr<TooltipController> controller_; | 131 scoped_ptr<TooltipController> controller_; |
| 132 |
| 129 #if defined(OS_WIN) | 133 #if defined(OS_WIN) |
| 130 ui::ScopedOleInitializer ole_initializer_; | 134 ui::ScopedOleInitializer ole_initializer_; |
| 131 #endif | 135 #endif |
| 132 | 136 |
| 137 scoped_ptr<views::corewm::WMState> wm_state_; |
| 138 |
| 133 DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest); | 139 DISALLOW_COPY_AND_ASSIGN(TooltipControllerTest); |
| 134 }; | 140 }; |
| 135 | 141 |
| 136 TEST_F(TooltipControllerTest, ViewTooltip) { | 142 TEST_F(TooltipControllerTest, ViewTooltip) { |
| 137 view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text")); | 143 view_->set_tooltip_text(ASCIIToUTF16("Tooltip Text")); |
| 138 EXPECT_EQ(base::string16(), helper_->GetTooltipText()); | 144 EXPECT_EQ(base::string16(), helper_->GetTooltipText()); |
| 139 EXPECT_EQ(NULL, helper_->GetTooltipWindow()); | 145 EXPECT_EQ(NULL, helper_->GetTooltipWindow()); |
| 140 generator_->MoveMouseToCenterOf(GetWindow()); | 146 generator_->MoveMouseToCenterOf(GetWindow()); |
| 141 | 147 |
| 142 EXPECT_EQ(GetWindow(), GetRootWindow()->GetEventHandlerForPoint( | 148 EXPECT_EQ(GetWindow(), GetRootWindow()->GetEventHandlerForPoint( |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 | 647 |
| 642 EXPECT_EQ( | 648 EXPECT_EQ( |
| 643 widget_->GetNativeWindow()->GetRootWindow()->children().back()->type(), | 649 widget_->GetNativeWindow()->GetRootWindow()->children().back()->type(), |
| 644 ui::wm::WINDOW_TYPE_TOOLTIP); | 650 ui::wm::WINDOW_TYPE_TOOLTIP); |
| 645 } | 651 } |
| 646 #endif | 652 #endif |
| 647 | 653 |
| 648 } // namespace test | 654 } // namespace test |
| 649 } // namespace corewm | 655 } // namespace corewm |
| 650 } // namespace views | 656 } // namespace views |
| OLD | NEW |