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