| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/controls/button/custom_button.h" | 5 #include "ui/views/controls/button/custom_button.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 std::unique_ptr<Widget> widget_; | 135 std::unique_ptr<Widget> widget_; |
| 136 TestCustomButton* button_; | 136 TestCustomButton* button_; |
| 137 | 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); | 138 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 // Tests that hover state changes correctly when visiblity/enableness changes. | 141 // Tests that hover state changes correctly when visiblity/enableness changes. |
| 142 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { | 142 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { |
| 143 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); | 143 ui::test::EventGenerator generator(widget()->GetNativeWindow()); |
| 144 | 144 |
| 145 generator.PressLeftButton(); | 145 generator.PressLeftButton(); |
| 146 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); | 146 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
| 147 | 147 |
| 148 generator.ReleaseLeftButton(); | 148 generator.ReleaseLeftButton(); |
| 149 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); | 149 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); |
| 150 | 150 |
| 151 button()->SetEnabled(false); | 151 button()->SetEnabled(false); |
| 152 EXPECT_EQ(CustomButton::STATE_DISABLED, button()->state()); | 152 EXPECT_EQ(CustomButton::STATE_DISABLED, button()->state()); |
| 153 | 153 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); | 185 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); |
| 186 } | 186 } |
| 187 #endif | 187 #endif |
| 188 | 188 |
| 189 // Disabling cursor events occurs for touch events and the Ash magnifier. There | 189 // Disabling cursor events occurs for touch events and the Ash magnifier. There |
| 190 // is no touch on desktop Mac. Tracked in http://crbug.com/445520. | 190 // is no touch on desktop Mac. Tracked in http://crbug.com/445520. |
| 191 #if !defined(OS_MACOSX) || defined(USE_AURA) | 191 #if !defined(OS_MACOSX) || defined(USE_AURA) |
| 192 aura::test::TestCursorClient cursor_client( | 192 aura::test::TestCursorClient cursor_client( |
| 193 widget()->GetNativeView()->GetRootWindow()); | 193 widget()->GetNativeView()->GetRootWindow()); |
| 194 | 194 |
| 195 // In Aura views, no new hover effects are invoked if mouse events | 195 // Mus doesn't support disabling mouse events. |
| 196 // are disabled. | 196 if (!IsMus()) { |
| 197 cursor_client.DisableMouseEvents(); | 197 // In Aura views, no new hover effects are invoked if mouse events |
| 198 // are disabled. |
| 199 cursor_client.DisableMouseEvents(); |
| 198 | 200 |
| 199 button()->SetEnabled(false); | 201 button()->SetEnabled(false); |
| 200 EXPECT_EQ(CustomButton::STATE_DISABLED, button()->state()); | 202 EXPECT_EQ(CustomButton::STATE_DISABLED, button()->state()); |
| 201 | 203 |
| 202 button()->SetEnabled(true); | 204 button()->SetEnabled(true); |
| 203 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); | 205 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); |
| 204 | 206 |
| 205 button()->SetVisible(false); | 207 button()->SetVisible(false); |
| 206 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); | 208 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); |
| 207 | 209 |
| 208 button()->SetVisible(true); | 210 button()->SetVisible(true); |
| 209 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); | 211 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); |
| 212 } |
| 210 #endif // !defined(OS_MACOSX) || defined(USE_AURA) | 213 #endif // !defined(OS_MACOSX) || defined(USE_AURA) |
| 211 } | 214 } |
| 212 | 215 |
| 213 // Tests the different types of NotifyActions. | 216 // Tests the different types of NotifyActions. |
| 214 TEST_F(CustomButtonTest, NotifyAction) { | 217 TEST_F(CustomButtonTest, NotifyAction) { |
| 215 gfx::Point center(10, 10); | 218 gfx::Point center(10, 10); |
| 216 | 219 |
| 217 // By default the button should notify its listener on mouse release. | 220 // By default the button should notify its listener on mouse release. |
| 218 button()->OnMousePressed(ui::MouseEvent( | 221 button()->OnMousePressed(ui::MouseEvent( |
| 219 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 222 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 345 |
| 343 // Tests that pressing a button shows the ink drop and releasing the button | 346 // Tests that pressing a button shows the ink drop and releasing the button |
| 344 // does not hide the ink drop. | 347 // does not hide the ink drop. |
| 345 // Note: Ink drop is not hidden upon release because CustomButton descendants | 348 // Note: Ink drop is not hidden upon release because CustomButton descendants |
| 346 // may enter a different ink drop state. | 349 // may enter a different ink drop state. |
| 347 TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) { | 350 TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) { |
| 348 gfx::Point old_cursor = display::Screen::GetScreen()->GetCursorScreenPoint(); | 351 gfx::Point old_cursor = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 349 TestInkDrop* ink_drop = new TestInkDrop(); | 352 TestInkDrop* ink_drop = new TestInkDrop(); |
| 350 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); | 353 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 351 | 354 |
| 352 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); | 355 ui::test::EventGenerator generator(widget()->GetNativeWindow()); |
| 353 generator.set_current_location(gfx::Point(50, 50)); | 356 generator.set_current_location(gfx::Point(50, 50)); |
| 354 generator.PressLeftButton(); | 357 generator.PressLeftButton(); |
| 355 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); | 358 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 356 | 359 |
| 357 generator.ReleaseLeftButton(); | 360 generator.ReleaseLeftButton(); |
| 358 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); | 361 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 359 } | 362 } |
| 360 | 363 |
| 361 // Tests that pressing a button shows and releasing capture hides ink drop. | 364 // Tests that pressing a button shows and releasing capture hides ink drop. |
| 362 // Releasing capture should also reset PRESSED button state to NORMAL. | 365 // Releasing capture should also reset PRESSED button state to NORMAL. |
| 363 TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) { | 366 TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) { |
| 364 gfx::Point old_cursor = display::Screen::GetScreen()->GetCursorScreenPoint(); | 367 gfx::Point old_cursor = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 365 TestInkDrop* ink_drop = new TestInkDrop(); | 368 TestInkDrop* ink_drop = new TestInkDrop(); |
| 366 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); | 369 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 367 | 370 |
| 368 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); | 371 ui::test::EventGenerator generator(widget()->GetNativeWindow()); |
| 369 generator.set_current_location(gfx::Point(50, 50)); | 372 generator.set_current_location(gfx::Point(50, 50)); |
| 370 generator.PressLeftButton(); | 373 generator.PressLeftButton(); |
| 371 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); | 374 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 372 | 375 |
| 373 EXPECT_EQ(Button::ButtonState::STATE_PRESSED, button()->state()); | 376 EXPECT_EQ(Button::ButtonState::STATE_PRESSED, button()->state()); |
| 374 SetDraggedView(button()); | 377 SetDraggedView(button()); |
| 375 widget()->SetCapture(button()); | 378 widget()->SetCapture(button()); |
| 376 widget()->ReleaseCapture(); | 379 widget()->ReleaseCapture(); |
| 377 SetDraggedView(nullptr); | 380 SetDraggedView(nullptr); |
| 378 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 381 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 button()->OnMouseDragged(ui::MouseEvent( | 519 button()->OnMouseDragged(ui::MouseEvent( |
| 517 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 520 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 518 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 521 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 519 | 522 |
| 520 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 523 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 521 | 524 |
| 522 SetDraggedView(nullptr); | 525 SetDraggedView(nullptr); |
| 523 } | 526 } |
| 524 | 527 |
| 525 } // namespace views | 528 } // namespace views |
| OLD | NEW |