| 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/sessions/session_tab_helper.h" | 9 #include "chrome/browser/sessions/session_tab_helper.h" |
| 10 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" | 10 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" |
| 11 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 11 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 12 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 12 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 15 #include "content/public/test/test_web_contents_factory.h" | 15 #include "content/public/test/test_web_contents_factory.h" |
| 16 #include "ui/accessibility/ax_view_state.h" | 16 #include "ui/accessibility/ax_view_state.h" |
| 17 #include "ui/events/test/event_generator.h" | 17 #include "ui/events/test/event_generator.h" |
| 18 #include "ui/views/animation/test/test_ink_drop_delegate.h" |
| 18 #include "ui/views/test/views_test_base.h" | 19 #include "ui/views/test/views_test_base.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // A test delegate for a toolbar action view. | 23 // A test delegate for a toolbar action view. |
| 23 class TestToolbarActionViewDelegate : public ToolbarActionView::Delegate { | 24 class TestToolbarActionViewDelegate : public ToolbarActionView::Delegate { |
| 24 public: | 25 public: |
| 25 TestToolbarActionViewDelegate() : shown_in_menu_(false), | 26 TestToolbarActionViewDelegate() : shown_in_menu_(false), |
| 26 overflow_reference_view_(nullptr), | 27 overflow_reference_view_(nullptr), |
| 27 web_contents_(nullptr) {} | 28 web_contents_(nullptr) {} |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 private: | 123 private: |
| 123 // The widget managed by this test. | 124 // The widget managed by this test. |
| 124 views::Widget* widget_; | 125 views::Widget* widget_; |
| 125 | 126 |
| 126 // Web contents need a fake ui thread. | 127 // Web contents need a fake ui thread. |
| 127 content::TestBrowserThread ui_thread_; | 128 content::TestBrowserThread ui_thread_; |
| 128 | 129 |
| 129 DISALLOW_COPY_AND_ASSIGN(ToolbarActionViewUnitTest); | 130 DISALLOW_COPY_AND_ASSIGN(ToolbarActionViewUnitTest); |
| 130 }; | 131 }; |
| 131 | 132 |
| 133 // A MenuButton subclass that provides access to some MenuButton internals. |
| 134 class TestToolbarActionView : public ToolbarActionView { |
| 135 public: |
| 136 TestToolbarActionView(ToolbarActionViewController* view_controller, |
| 137 Delegate* delegate) |
| 138 : ToolbarActionView(view_controller, delegate) {} |
| 139 |
| 140 ~TestToolbarActionView() override {} |
| 141 |
| 142 // Accessors to protected ToolbarActionView methods. |
| 143 void set_ink_drop_delegate(views::InkDropDelegate* ink_drop_delegate) { |
| 144 ToolbarActionView::set_ink_drop_delegate(ink_drop_delegate); |
| 145 } |
| 146 |
| 147 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(TestToolbarActionView); |
| 149 }; |
| 150 |
| 151 // Verifies there is no crash when a ToolbarActionView with an InkDropDelegate |
| 152 // is destroyed while holding a |pressed_lock_|. |
| 153 TEST_F(ToolbarActionViewUnitTest, |
| 154 NoCrashWhenDestroyingToolbarActionViewThatHasAPressedLock) { |
| 155 TestToolbarActionViewController controller("fake controller"); |
| 156 TestToolbarActionViewDelegate action_view_delegate; |
| 157 |
| 158 // Create a new toolbar action view. |
| 159 scoped_ptr<ToolbarActionView> view( |
| 160 new ToolbarActionView(&controller, &action_view_delegate)); |
| 161 view->set_owned_by_client(); |
| 162 view->SetBoundsRect(gfx::Rect(0, 0, 200, 20)); |
| 163 widget()->SetContentsView(view.get()); |
| 164 widget()->Show(); |
| 165 |
| 166 controller.ShowPopup(true); |
| 167 |
| 168 view.reset(); |
| 169 } |
| 170 |
| 171 // Verifies the InkDropAnimation used by the ToolbarActionView doesn't fail a |
| 172 // DCHECK for an unsupported transition from ACTIVATED to ACTION_PENDING. |
| 173 TEST_F(ToolbarActionViewUnitTest, |
| 174 NoCrashWhenPressingMouseOnToolbarActionViewThatHasAPressedLock) { |
| 175 TestToolbarActionViewController controller("fake controller"); |
| 176 TestToolbarActionViewDelegate action_view_delegate; |
| 177 |
| 178 // Create a new toolbar action view. |
| 179 ToolbarActionView view(&controller, &action_view_delegate); |
| 180 view.set_owned_by_client(); |
| 181 view.SetBoundsRect(gfx::Rect(0, 0, 200, 20)); |
| 182 widget()->SetContentsView(&view); |
| 183 widget()->Show(); |
| 184 |
| 185 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| 186 |
| 187 controller.ShowPopup(true); |
| 188 generator.PressLeftButton(); |
| 189 } |
| 190 |
| 132 // Test the basic ui of a ToolbarActionView and that it responds correctly to | 191 // Test the basic ui of a ToolbarActionView and that it responds correctly to |
| 133 // a controller's state. | 192 // a controller's state. |
| 134 TEST_F(ToolbarActionViewUnitTest, BasicToolbarActionViewTest) { | 193 TEST_F(ToolbarActionViewUnitTest, BasicToolbarActionViewTest) { |
| 135 TestingProfile profile; | 194 TestingProfile profile; |
| 136 | 195 |
| 137 // ViewsTestBase initializees the aura environment, so the factory shouldn't. | 196 // ViewsTestBase initializes the aura environment, so the factory shouldn't. |
| 138 content::TestWebContentsFactory web_contents_factory; | 197 content::TestWebContentsFactory web_contents_factory; |
| 139 | 198 |
| 140 TestToolbarActionViewController controller("fake controller"); | 199 TestToolbarActionViewController controller("fake controller"); |
| 141 TestToolbarActionViewDelegate action_view_delegate; | 200 TestToolbarActionViewDelegate action_view_delegate; |
| 142 | 201 |
| 143 // Configure the test controller and delegate. | 202 // Configure the test controller and delegate. |
| 144 base::string16 name = base::ASCIIToUTF16("name"); | 203 base::string16 name = base::ASCIIToUTF16("name"); |
| 145 controller.SetAccessibleName(name); | 204 controller.SetAccessibleName(name); |
| 146 base::string16 tooltip = base::ASCIIToUTF16("tooltip"); | 205 base::string16 tooltip = base::ASCIIToUTF16("tooltip"); |
| 147 controller.SetTooltip(tooltip); | 206 controller.SetTooltip(tooltip); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // If the view isn't visible, the overflow button should be pressed for | 284 // If the view isn't visible, the overflow button should be pressed for |
| 226 // popups. | 285 // popups. |
| 227 view.SetVisible(false); | 286 view.SetVisible(false); |
| 228 controller.ShowPopup(true); | 287 controller.ShowPopup(true); |
| 229 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 288 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 230 EXPECT_EQ(views::Button::STATE_PRESSED, overflow_button.state()); | 289 EXPECT_EQ(views::Button::STATE_PRESSED, overflow_button.state()); |
| 231 controller.HidePopup(); | 290 controller.HidePopup(); |
| 232 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 291 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 233 EXPECT_EQ(views::Button::STATE_NORMAL, overflow_button.state()); | 292 EXPECT_EQ(views::Button::STATE_NORMAL, overflow_button.state()); |
| 234 } | 293 } |
| OLD | NEW |