| 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 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_ | 5 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_ | |
| 7 | |
| 8 #include "ui/views/animation/square_ink_drop_animation.h" | |
| 9 | 6 |
| 10 #include <memory> | 7 #include <memory> |
| 11 | 8 |
| 12 #include "base/macros.h" | 9 #include "base/macros.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/gfx/geometry/point.h" | 11 #include "ui/gfx/geometry/point.h" |
| 15 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/gfx/geometry/size_f.h" | 13 #include "ui/gfx/geometry/size_f.h" |
| 17 #include "ui/views/animation/ink_drop_animation_observer.h" | 14 #include "ui/views/animation/ink_drop_ripple_observer.h" |
| 18 #include "ui/views/animation/ink_drop_state.h" | 15 #include "ui/views/animation/ink_drop_state.h" |
| 19 #include "ui/views/animation/test/square_ink_drop_animation_test_api.h" | 16 #include "ui/views/animation/test/square_ink_drop_ripple_test_api.h" |
| 20 #include "ui/views/animation/test/test_ink_drop_animation_observer.h" | 17 #include "ui/views/animation/test/test_ink_drop_ripple_observer.h" |
| 21 | 18 |
| 22 namespace views { | 19 namespace views { |
| 23 namespace test { | 20 namespace test { |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 using PaintedShape = views::test::SquareInkDropAnimationTestApi::PaintedShape; | 24 using PaintedShape = views::test::SquareInkDropRippleTestApi::PaintedShape; |
| 28 | 25 |
| 29 // Transforms a copy of |point| with |transform| and returns it. | 26 // Transforms a copy of |point| with |transform| and returns it. |
| 30 gfx::Point TransformPoint(const gfx::Transform& transform, | 27 gfx::Point TransformPoint(const gfx::Transform& transform, |
| 31 const gfx::Point& point) { | 28 const gfx::Point& point) { |
| 32 gfx::Point transformed_point = point; | 29 gfx::Point transformed_point = point; |
| 33 transform.TransformPoint(&transformed_point); | 30 transform.TransformPoint(&transformed_point); |
| 34 return transformed_point; | 31 return transformed_point; |
| 35 } | 32 } |
| 36 | 33 |
| 37 class SquareInkDropAnimationCalculateTransformsTest : public testing::Test { | 34 class SquareInkDropRippleCalculateTransformsTest : public testing::Test { |
| 38 public: | 35 public: |
| 39 SquareInkDropAnimationCalculateTransformsTest(); | 36 SquareInkDropRippleCalculateTransformsTest(); |
| 40 ~SquareInkDropAnimationCalculateTransformsTest() override; | 37 ~SquareInkDropRippleCalculateTransformsTest() override; |
| 41 | 38 |
| 42 protected: | 39 protected: |
| 43 // Half the width/height of the drawn ink drop. | 40 // Half the width/height of the drawn ink drop. |
| 44 static const int kHalfDrawnSize; | 41 static const int kHalfDrawnSize; |
| 45 | 42 |
| 46 // The full width/height of the drawn ink drop. | 43 // The full width/height of the drawn ink drop. |
| 47 static const int kDrawnSize; | 44 static const int kDrawnSize; |
| 48 | 45 |
| 49 // The radius of the rounded rectangle corners. | 46 // The radius of the rounded rectangle corners. |
| 50 static const int kTransformedRadius; | 47 static const int kTransformedRadius; |
| 51 | 48 |
| 52 // Half the width/height of the transformed ink drop. | 49 // Half the width/height of the transformed ink drop. |
| 53 static const int kHalfTransformedSize; | 50 static const int kHalfTransformedSize; |
| 54 | 51 |
| 55 // The full width/height of the transformed ink drop. | 52 // The full width/height of the transformed ink drop. |
| 56 static const int kTransformedSize; | 53 static const int kTransformedSize; |
| 57 | 54 |
| 58 // Constant points in the drawn space that will be transformed. | 55 // Constant points in the drawn space that will be transformed. |
| 59 static const gfx::Point kDrawnCenterPoint; | 56 static const gfx::Point kDrawnCenterPoint; |
| 60 static const gfx::Point kDrawnMidLeftPoint; | 57 static const gfx::Point kDrawnMidLeftPoint; |
| 61 static const gfx::Point kDrawnMidRightPoint; | 58 static const gfx::Point kDrawnMidRightPoint; |
| 62 static const gfx::Point kDrawnTopMidPoint; | 59 static const gfx::Point kDrawnTopMidPoint; |
| 63 static const gfx::Point kDrawnBottomMidPoint; | 60 static const gfx::Point kDrawnBottomMidPoint; |
| 64 | 61 |
| 65 // The test target. | 62 // The test target. |
| 66 SquareInkDropAnimation ink_drop_animation_; | 63 SquareInkDropRipple ink_drop_ripple_; |
| 67 | 64 |
| 68 // Provides internal access to the test target. | 65 // Provides internal access to the test target. |
| 69 SquareInkDropAnimationTestApi test_api_; | 66 SquareInkDropRippleTestApi test_api_; |
| 70 | 67 |
| 71 // The gfx::Transforms collection that is populated via the | 68 // The gfx::Transforms collection that is populated via the |
| 72 // Calculate*Transforms() calls. | 69 // Calculate*Transforms() calls. |
| 73 SquareInkDropAnimationTestApi::InkDropTransforms transforms_; | 70 SquareInkDropRippleTestApi::InkDropTransforms transforms_; |
| 74 | 71 |
| 75 private: | 72 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(SquareInkDropAnimationCalculateTransformsTest); | 73 DISALLOW_COPY_AND_ASSIGN(SquareInkDropRippleCalculateTransformsTest); |
| 77 }; | 74 }; |
| 78 | 75 |
| 79 const int SquareInkDropAnimationCalculateTransformsTest::kHalfDrawnSize = 5; | 76 const int SquareInkDropRippleCalculateTransformsTest::kHalfDrawnSize = 5; |
| 80 const int SquareInkDropAnimationCalculateTransformsTest::kDrawnSize = | 77 const int SquareInkDropRippleCalculateTransformsTest::kDrawnSize = |
| 81 2 * kHalfDrawnSize; | 78 2 * kHalfDrawnSize; |
| 82 | 79 |
| 83 const int SquareInkDropAnimationCalculateTransformsTest::kTransformedRadius = | 80 const int SquareInkDropRippleCalculateTransformsTest::kTransformedRadius = 10; |
| 84 10; | 81 const int SquareInkDropRippleCalculateTransformsTest::kHalfTransformedSize = |
| 85 const int SquareInkDropAnimationCalculateTransformsTest::kHalfTransformedSize = | |
| 86 100; | 82 100; |
| 87 const int SquareInkDropAnimationCalculateTransformsTest::kTransformedSize = | 83 const int SquareInkDropRippleCalculateTransformsTest::kTransformedSize = |
| 88 2 * kHalfTransformedSize; | 84 2 * kHalfTransformedSize; |
| 89 | 85 |
| 90 const gfx::Point | 86 const gfx::Point SquareInkDropRippleCalculateTransformsTest::kDrawnCenterPoint = |
| 91 SquareInkDropAnimationCalculateTransformsTest::kDrawnCenterPoint = | 87 gfx::Point(kHalfDrawnSize, kHalfDrawnSize); |
| 92 gfx::Point(kHalfDrawnSize, kHalfDrawnSize); | |
| 93 | 88 |
| 94 const gfx::Point | 89 const gfx::Point |
| 95 SquareInkDropAnimationCalculateTransformsTest::kDrawnMidLeftPoint = | 90 SquareInkDropRippleCalculateTransformsTest::kDrawnMidLeftPoint = |
| 96 gfx::Point(0, kHalfDrawnSize); | 91 gfx::Point(0, kHalfDrawnSize); |
| 97 | 92 |
| 98 const gfx::Point | 93 const gfx::Point |
| 99 SquareInkDropAnimationCalculateTransformsTest::kDrawnMidRightPoint = | 94 SquareInkDropRippleCalculateTransformsTest::kDrawnMidRightPoint = |
| 100 gfx::Point(kDrawnSize, kHalfDrawnSize); | 95 gfx::Point(kDrawnSize, kHalfDrawnSize); |
| 101 | 96 |
| 102 const gfx::Point | 97 const gfx::Point SquareInkDropRippleCalculateTransformsTest::kDrawnTopMidPoint = |
| 103 SquareInkDropAnimationCalculateTransformsTest::kDrawnTopMidPoint = | 98 gfx::Point(kHalfDrawnSize, 0); |
| 104 gfx::Point(kHalfDrawnSize, 0); | |
| 105 | 99 |
| 106 const gfx::Point | 100 const gfx::Point |
| 107 SquareInkDropAnimationCalculateTransformsTest::kDrawnBottomMidPoint = | 101 SquareInkDropRippleCalculateTransformsTest::kDrawnBottomMidPoint = |
| 108 gfx::Point(kHalfDrawnSize, kDrawnSize); | 102 gfx::Point(kHalfDrawnSize, kDrawnSize); |
| 109 | 103 |
| 110 SquareInkDropAnimationCalculateTransformsTest:: | 104 SquareInkDropRippleCalculateTransformsTest:: |
| 111 SquareInkDropAnimationCalculateTransformsTest() | 105 SquareInkDropRippleCalculateTransformsTest() |
| 112 : ink_drop_animation_(gfx::Size(kDrawnSize, kDrawnSize), | 106 : ink_drop_ripple_(gfx::Size(kDrawnSize, kDrawnSize), |
| 113 2, | 107 2, |
| 114 gfx::Size(kHalfDrawnSize, kHalfDrawnSize), | 108 gfx::Size(kHalfDrawnSize, kHalfDrawnSize), |
| 115 1, | 109 1, |
| 116 gfx::Point(), | 110 gfx::Point(), |
| 117 SK_ColorBLACK), | 111 SK_ColorBLACK), |
| 118 test_api_(&ink_drop_animation_) {} | 112 test_api_(&ink_drop_ripple_) {} |
| 119 | 113 |
| 120 SquareInkDropAnimationCalculateTransformsTest:: | 114 SquareInkDropRippleCalculateTransformsTest:: |
| 121 ~SquareInkDropAnimationCalculateTransformsTest() {} | 115 ~SquareInkDropRippleCalculateTransformsTest() {} |
| 122 | 116 |
| 123 } // namespace | 117 } // namespace |
| 124 | 118 |
| 125 TEST_F(SquareInkDropAnimationCalculateTransformsTest, | 119 TEST_F(SquareInkDropRippleCalculateTransformsTest, |
| 126 TransformedPointsUsingTransformsFromCalculateCircleTransforms) { | 120 TransformedPointsUsingTransformsFromCalculateCircleTransforms) { |
| 127 test_api_.CalculateCircleTransforms( | 121 test_api_.CalculateCircleTransforms( |
| 128 gfx::Size(kTransformedSize, kTransformedSize), &transforms_); | 122 gfx::Size(kTransformedSize, kTransformedSize), &transforms_); |
| 129 | 123 |
| 130 struct { | 124 struct { |
| 131 PaintedShape shape; | 125 PaintedShape shape; |
| 132 gfx::Point center_point; | 126 gfx::Point center_point; |
| 133 gfx::Point mid_left_point; | 127 gfx::Point mid_left_point; |
| 134 gfx::Point mid_right_point; | 128 gfx::Point mid_right_point; |
| 135 gfx::Point top_mid_point; | 129 gfx::Point top_mid_point; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 TransformPoint(transform, kDrawnMidLeftPoint)); | 167 TransformPoint(transform, kDrawnMidLeftPoint)); |
| 174 EXPECT_EQ(test_cases[i].mid_right_point, | 168 EXPECT_EQ(test_cases[i].mid_right_point, |
| 175 TransformPoint(transform, kDrawnMidRightPoint)); | 169 TransformPoint(transform, kDrawnMidRightPoint)); |
| 176 EXPECT_EQ(test_cases[i].top_mid_point, | 170 EXPECT_EQ(test_cases[i].top_mid_point, |
| 177 TransformPoint(transform, kDrawnTopMidPoint)); | 171 TransformPoint(transform, kDrawnTopMidPoint)); |
| 178 EXPECT_EQ(test_cases[i].bottom_mid_point, | 172 EXPECT_EQ(test_cases[i].bottom_mid_point, |
| 179 TransformPoint(transform, kDrawnBottomMidPoint)); | 173 TransformPoint(transform, kDrawnBottomMidPoint)); |
| 180 } | 174 } |
| 181 } | 175 } |
| 182 | 176 |
| 183 TEST_F(SquareInkDropAnimationCalculateTransformsTest, | 177 TEST_F(SquareInkDropRippleCalculateTransformsTest, |
| 184 TransformedPointsUsingTransformsFromCalculateRectTransforms) { | 178 TransformedPointsUsingTransformsFromCalculateRectTransforms) { |
| 185 test_api_.CalculateRectTransforms( | 179 test_api_.CalculateRectTransforms( |
| 186 gfx::Size(kTransformedSize, kTransformedSize), kTransformedRadius, | 180 gfx::Size(kTransformedSize, kTransformedSize), kTransformedRadius, |
| 187 &transforms_); | 181 &transforms_); |
| 188 | 182 |
| 189 const int x_offset = kHalfTransformedSize - kTransformedRadius; | 183 const int x_offset = kHalfTransformedSize - kTransformedRadius; |
| 190 const int y_offset = kHalfTransformedSize - kTransformedRadius; | 184 const int y_offset = kHalfTransformedSize - kTransformedRadius; |
| 191 | 185 |
| 192 struct { | 186 struct { |
| 193 PaintedShape shape; | 187 PaintedShape shape; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 TransformPoint(transform, kDrawnMidRightPoint)); | 232 TransformPoint(transform, kDrawnMidRightPoint)); |
| 239 EXPECT_EQ(test_cases[i].top_mid_point, | 233 EXPECT_EQ(test_cases[i].top_mid_point, |
| 240 TransformPoint(transform, kDrawnTopMidPoint)); | 234 TransformPoint(transform, kDrawnTopMidPoint)); |
| 241 EXPECT_EQ(test_cases[i].bottom_mid_point, | 235 EXPECT_EQ(test_cases[i].bottom_mid_point, |
| 242 TransformPoint(transform, kDrawnBottomMidPoint)); | 236 TransformPoint(transform, kDrawnBottomMidPoint)); |
| 243 } | 237 } |
| 244 } | 238 } |
| 245 | 239 |
| 246 } // namespace test | 240 } // namespace test |
| 247 } // namespace views | 241 } // namespace views |
| 248 | |
| 249 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_ | |
| OLD | NEW |