| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 6 |
| 5 #include "base/macros.h" | 7 #include "base/macros.h" |
| 6 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 8 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/scoped_task_scheduler.h" | 12 #include "base/test/scoped_task_scheduler.h" |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" | 13 #include "chrome/browser/sessions/session_tab_helper.h" |
| 12 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" | 14 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" |
| 13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 14 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "content/public/test/test_web_contents_factory.h" | 18 #include "content/public/test/test_web_contents_factory.h" |
| 18 #include "ui/accessibility/ax_node_data.h" | 19 #include "ui/accessibility/ax_node_data.h" |
| 19 #include "ui/events/test/event_generator.h" | 20 #include "ui/events/test/event_generator.h" |
| 20 #include "ui/views/test/views_test_base.h" | 21 #include "ui/views/test/views_test_base.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // A test delegate for a toolbar action view. | 25 // A test delegate for a toolbar action view. |
| 25 class TestToolbarActionViewDelegate : public ToolbarActionView::Delegate { | 26 class TestToolbarActionViewDelegate : public ToolbarActionView::Delegate { |
| 26 public: | 27 public: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 92 |
| 92 bool opened_menu_; | 93 bool opened_menu_; |
| 93 | 94 |
| 94 DISALLOW_COPY_AND_ASSIGN(OpenMenuListener); | 95 DISALLOW_COPY_AND_ASSIGN(OpenMenuListener); |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 } // namespace | 98 } // namespace |
| 98 | 99 |
| 99 class ToolbarActionViewUnitTest : public views::ViewsTestBase { | 100 class ToolbarActionViewUnitTest : public views::ViewsTestBase { |
| 100 public: | 101 public: |
| 101 ToolbarActionViewUnitTest() | 102 ToolbarActionViewUnitTest() : widget_(nullptr) {} |
| 102 : widget_(nullptr), | |
| 103 ui_thread_(content::BrowserThread::UI, message_loop()), | |
| 104 scoped_task_scheduler_(base::MessageLoop::current()) {} | |
| 105 ~ToolbarActionViewUnitTest() override {} | 103 ~ToolbarActionViewUnitTest() override {} |
| 106 | 104 |
| 107 void SetUp() override { | 105 void SetUp() override { |
| 108 views::ViewsTestBase::SetUp(); | 106 views::ViewsTestBase::SetUp(); |
| 109 | 107 |
| 110 widget_ = new views::Widget; | 108 widget_ = new views::Widget; |
| 111 views::Widget::InitParams params = | 109 views::Widget::InitParams params = |
| 112 CreateParams(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 110 CreateParams(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 113 params.bounds = gfx::Rect(0, 0, 200, 200); | 111 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 114 widget_->Init(params); | 112 widget_->Init(params); |
| 115 } | 113 } |
| 116 void TearDown() override { | 114 void TearDown() override { |
| 117 if (!widget_->IsClosed()) | 115 if (!widget_->IsClosed()) |
| 118 widget_->Close(); | 116 widget_->Close(); |
| 119 views::ViewsTestBase::TearDown(); | 117 views::ViewsTestBase::TearDown(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 views::Widget* widget() { return widget_; } | 120 views::Widget* widget() { return widget_; } |
| 123 | 121 |
| 124 private: | 122 private: |
| 123 // Web contents need a UI thread and a TaskScheduler. |
| 124 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 125 |
| 125 // The widget managed by this test. | 126 // The widget managed by this test. |
| 126 views::Widget* widget_; | 127 views::Widget* widget_; |
| 127 | 128 |
| 128 // Web contents need a UI thread and a TaskScheduler. | |
| 129 content::TestBrowserThread ui_thread_; | |
| 130 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(ToolbarActionViewUnitTest); | 129 DISALLOW_COPY_AND_ASSIGN(ToolbarActionViewUnitTest); |
| 133 }; | 130 }; |
| 134 | 131 |
| 135 // A MenuButton subclass that provides access to some MenuButton internals. | 132 // A MenuButton subclass that provides access to some MenuButton internals. |
| 136 class TestToolbarActionView : public ToolbarActionView { | 133 class TestToolbarActionView : public ToolbarActionView { |
| 137 public: | 134 public: |
| 138 TestToolbarActionView(ToolbarActionViewController* view_controller, | 135 TestToolbarActionView(ToolbarActionViewController* view_controller, |
| 139 Delegate* delegate) | 136 Delegate* delegate) |
| 140 : ToolbarActionView(view_controller, delegate) {} | 137 : ToolbarActionView(view_controller, delegate) {} |
| 141 | 138 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // If the view isn't visible, the overflow button should be pressed for | 278 // If the view isn't visible, the overflow button should be pressed for |
| 282 // popups. | 279 // popups. |
| 283 view.SetVisible(false); | 280 view.SetVisible(false); |
| 284 controller.ShowPopup(true); | 281 controller.ShowPopup(true); |
| 285 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 282 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 286 EXPECT_EQ(views::Button::STATE_PRESSED, overflow_button.state()); | 283 EXPECT_EQ(views::Button::STATE_PRESSED, overflow_button.state()); |
| 287 controller.HidePopup(); | 284 controller.HidePopup(); |
| 288 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 285 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 289 EXPECT_EQ(views::Button::STATE_NORMAL, overflow_button.state()); | 286 EXPECT_EQ(views::Button::STATE_NORMAL, overflow_button.state()); |
| 290 } | 287 } |
| OLD | NEW |