| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/animation/ink_drop_host_view.h" | 5 #include "ui/views/animation/ink_drop_host_view.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 10 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
| 11 #include "ui/events/event_utils.h" | 11 #include "ui/events/event_utils.h" |
| 12 #include "ui/gfx/color_palette.h" |
| 12 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
| 13 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/views/animation/test/ink_drop_host_view_test_api.h" | 15 #include "ui/views/animation/test/ink_drop_host_view_test_api.h" |
| 15 | 16 |
| 16 namespace views { | 17 namespace views { |
| 17 namespace test { | 18 namespace test { |
| 18 using InkDropMode = InkDropHostViewTestApi::InkDropMode; | 19 using InkDropMode = InkDropHostViewTestApi::InkDropMode; |
| 19 | 20 |
| 21 class InkDropHostViewColor : public InkDropHostView { |
| 22 protected: |
| 23 SkColor GetInkDropBaseColor() const override { |
| 24 return gfx::kPlaceholderColor; |
| 25 } |
| 26 }; |
| 27 |
| 20 class InkDropHostViewTest : public testing::Test { | 28 class InkDropHostViewTest : public testing::Test { |
| 21 public: | 29 public: |
| 22 InkDropHostViewTest(); | 30 InkDropHostViewTest(); |
| 23 ~InkDropHostViewTest() override; | 31 ~InkDropHostViewTest() override; |
| 24 | 32 |
| 25 protected: | 33 protected: |
| 26 // Test target. | 34 // Test target. |
| 27 InkDropHostView host_view_; | 35 InkDropHostViewColor host_view_; |
| 28 | 36 |
| 29 // Provides internal access to |host_view_| test target. | 37 // Provides internal access to |host_view_| test target. |
| 30 InkDropHostViewTestApi test_api_; | 38 InkDropHostViewTestApi test_api_; |
| 31 | 39 |
| 32 private: | 40 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(InkDropHostViewTest); | 41 DISALLOW_COPY_AND_ASSIGN(InkDropHostViewTest); |
| 34 }; | 42 }; |
| 35 | 43 |
| 36 InkDropHostViewTest::InkDropHostViewTest() : test_api_(&host_view_) {} | 44 InkDropHostViewTest::InkDropHostViewTest() : test_api_(&host_view_) {} |
| 37 | 45 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 EXPECT_TRUE(test_api_.HasGestureHandler()); | 77 EXPECT_TRUE(test_api_.HasGestureHandler()); |
| 70 | 78 |
| 71 // Enabling gesture handler the second time should just work (no crash). | 79 // Enabling gesture handler the second time should just work (no crash). |
| 72 test_api_.SetInkDropMode(InkDropMode::ON); | 80 test_api_.SetInkDropMode(InkDropMode::ON); |
| 73 EXPECT_TRUE(test_api_.HasGestureHandler()); | 81 EXPECT_TRUE(test_api_.HasGestureHandler()); |
| 74 | 82 |
| 75 test_api_.SetInkDropMode(InkDropMode::OFF); | 83 test_api_.SetInkDropMode(InkDropMode::OFF); |
| 76 EXPECT_FALSE(test_api_.HasGestureHandler()); | 84 EXPECT_FALSE(test_api_.HasGestureHandler()); |
| 77 } | 85 } |
| 78 | 86 |
| 87 #if defined(OS_WIN) |
| 88 TEST_F(InkDropHostViewTest, NoInkDropOnTouchOrGestureEvents) { |
| 89 host_view_.SetSize(gfx::Size(20, 20)); |
| 90 |
| 91 test_api_.SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER); |
| 92 |
| 93 // Ensure the target ink drop is in the expected state. |
| 94 EXPECT_EQ(test_api_.ink_drop()->GetTargetInkDropState(), |
| 95 InkDropState::HIDDEN); |
| 96 |
| 97 ui::TouchEvent touch_event(ui::ET_TOUCH_PRESSED, gfx::Point(5, 6), 1, |
| 98 ui::EventTimeForNow()); |
| 99 |
| 100 test_api_.AnimateInkDrop(InkDropState::ACTION_PENDING, &touch_event); |
| 101 EXPECT_EQ(test_api_.ink_drop()->GetTargetInkDropState(), |
| 102 InkDropState::HIDDEN); |
| 103 |
| 104 test_api_.AnimateInkDrop(InkDropState::ALTERNATE_ACTION_PENDING, |
| 105 &touch_event); |
| 106 EXPECT_EQ(test_api_.ink_drop()->GetTargetInkDropState(), |
| 107 InkDropState::HIDDEN); |
| 108 |
| 109 ui::GestureEvent gesture_event(5.0f, 6.0f, 0, ui::EventTimeForNow(), |
| 110 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 111 |
| 112 test_api_.AnimateInkDrop(InkDropState::ACTION_PENDING, &gesture_event); |
| 113 EXPECT_EQ(test_api_.ink_drop()->GetTargetInkDropState(), |
| 114 InkDropState::HIDDEN); |
| 115 |
| 116 test_api_.AnimateInkDrop(InkDropState::ALTERNATE_ACTION_PENDING, |
| 117 &gesture_event); |
| 118 EXPECT_EQ(test_api_.ink_drop()->GetTargetInkDropState(), |
| 119 InkDropState::HIDDEN); |
| 120 } |
| 121 |
| 122 TEST_F(InkDropHostViewTest, DismissInkDropOnTouchOrGestureEvents) { |
| 123 host_view_.SetSize(gfx::Size(20, 20)); |
| 124 |
| 125 test_api_.SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER); |
| 126 |
| 127 // Ensure the target ink drop is in the expected state. |
| 128 EXPECT_EQ(test_api_.ink_drop()->GetTargetInkDropState(), |
| 129 InkDropState::HIDDEN); |
| 130 |
| 131 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, gfx::Point(5, 6), |
| 132 gfx::Point(5, 6), ui::EventTimeForNow(), |
| 133 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 134 |
| 135 test_api_.AnimateInkDrop(InkDropState::ACTION_PENDING, &mouse_event); |
| 136 EXPECT_EQ(test_api_.ink_drop()->GetTargetInkDropState(), |
| 137 InkDropState::ACTION_PENDING); |
| 138 |
| 139 ui::TouchEvent touch_event(ui::ET_TOUCH_PRESSED, gfx::Point(5, 6), 1, |
| 140 ui::EventTimeForNow()); |
| 141 |
| 142 test_api_.AnimateInkDrop(InkDropState::ACTION_TRIGGERED, &touch_event); |
| 143 EXPECT_EQ(test_api_.ink_drop()->GetTargetInkDropState(), |
| 144 InkDropState::ACTION_TRIGGERED); |
| 145 } |
| 146 #endif |
| 147 |
| 79 } // namespace test | 148 } // namespace test |
| 80 } // namespace views | 149 } // namespace views |
| OLD | NEW |