| 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" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 CreateParams(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 110 CreateParams(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 111 params.bounds = gfx::Rect(0, 0, 200, 200); | 111 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 112 widget_->Init(params); | 112 widget_->Init(params); |
| 113 } | 113 } |
| 114 void TearDown() override { | 114 void TearDown() override { |
| 115 if (!widget_->IsClosed()) | 115 if (!widget_->IsClosed()) |
| 116 widget_->Close(); | 116 widget_->Close(); |
| 117 views::ViewsTestBase::TearDown(); | 117 views::ViewsTestBase::TearDown(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 protected: |
| 120 views::Widget* widget() { return widget_; } | 121 views::Widget* widget() { return widget_; } |
| 121 | 122 |
| 123 void SetDraggedView(views::View* dragged_view) { |
| 124 widget()->set_dragged_view(dragged_view); |
| 125 } |
| 126 |
| 122 private: | 127 private: |
| 123 // The widget managed by this test. | 128 // The widget managed by this test. |
| 124 views::Widget* widget_; | 129 views::Widget* widget_; |
| 125 | 130 |
| 126 // Web contents need a fake ui thread. | 131 // Web contents need a fake ui thread. |
| 127 content::TestBrowserThread ui_thread_; | 132 content::TestBrowserThread ui_thread_; |
| 128 | 133 |
| 129 DISALLOW_COPY_AND_ASSIGN(ToolbarActionViewUnitTest); | 134 DISALLOW_COPY_AND_ASSIGN(ToolbarActionViewUnitTest); |
| 130 }; | 135 }; |
| 131 | 136 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 controller.ShowPopup(false); | 190 controller.ShowPopup(false); |
| 186 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 191 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 187 controller.HidePopup(); | 192 controller.HidePopup(); |
| 188 | 193 |
| 189 // Show the popup through a user action - the button should be pressed. | 194 // Show the popup through a user action - the button should be pressed. |
| 190 controller.ShowPopup(true); | 195 controller.ShowPopup(true); |
| 191 EXPECT_EQ(views::Button::STATE_PRESSED, view.state()); | 196 EXPECT_EQ(views::Button::STATE_PRESSED, view.state()); |
| 192 controller.HidePopup(); | 197 controller.HidePopup(); |
| 193 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 198 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 194 | 199 |
| 200 // Simulate dragging |view|. Once a drag is started a capture loss should |
| 201 // reset button state. |
| 202 view.SetHotTracked(true); |
| 203 EXPECT_EQ(views::Button::ButtonState::STATE_HOVERED, view.state()); |
| 204 SetDraggedView(&view); |
| 205 widget()->SetCapture(&view); |
| 206 widget()->ReleaseCapture(); |
| 207 EXPECT_EQ(views::Button::ButtonState::STATE_NORMAL, view.state()); |
| 208 SetDraggedView(nullptr); |
| 209 |
| 195 // Ensure that the button's enabled state reflects that of the controller. | 210 // Ensure that the button's enabled state reflects that of the controller. |
| 196 controller.SetEnabled(false); | 211 controller.SetEnabled(false); |
| 197 EXPECT_EQ(views::Button::STATE_DISABLED, view.state()); | 212 EXPECT_EQ(views::Button::STATE_DISABLED, view.state()); |
| 198 controller.SetEnabled(true); | 213 controller.SetEnabled(true); |
| 199 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 214 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 200 | 215 |
| 201 // Ensure that clicking on an otherwise-disabled action optionally opens the | 216 // Ensure that clicking on an otherwise-disabled action optionally opens the |
| 202 // context menu. | 217 // context menu. |
| 203 controller.SetDisabledClickOpensMenu(true); | 218 controller.SetDisabledClickOpensMenu(true); |
| 204 controller.SetEnabled(false); | 219 controller.SetEnabled(false); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 225 // If the view isn't visible, the overflow button should be pressed for | 240 // If the view isn't visible, the overflow button should be pressed for |
| 226 // popups. | 241 // popups. |
| 227 view.SetVisible(false); | 242 view.SetVisible(false); |
| 228 controller.ShowPopup(true); | 243 controller.ShowPopup(true); |
| 229 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 244 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 230 EXPECT_EQ(views::Button::STATE_PRESSED, overflow_button.state()); | 245 EXPECT_EQ(views::Button::STATE_PRESSED, overflow_button.state()); |
| 231 controller.HidePopup(); | 246 controller.HidePopup(); |
| 232 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); | 247 EXPECT_EQ(views::Button::STATE_NORMAL, view.state()); |
| 233 EXPECT_EQ(views::Button::STATE_NORMAL, overflow_button.state()); | 248 EXPECT_EQ(views::Button::STATE_NORMAL, overflow_button.state()); |
| 234 } | 249 } |
| OLD | NEW |