| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 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 | 
|  | 3 // found in the LICENSE file. | 
|  | 4 | 
|  | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_ | 
|  | 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_ | 
|  | 7 | 
|  | 8 #include "base/macros.h" | 
|  | 9 #include "base/memory/scoped_ptr.h" | 
|  | 10 #include "testing/gtest/include/gtest/gtest.h" | 
|  | 11 #include "ui/gfx/geometry/size.h" | 
|  | 12 #include "ui/gfx/geometry/size_f.h" | 
|  | 13 #include "ui/views/animation/ink_drop_animation.h" | 
|  | 14 #include "ui/views/animation/ink_drop_state.h" | 
|  | 15 #include "ui/views/animation/test/ink_drop_animation_test_api.h" | 
|  | 16 | 
|  | 17 namespace views { | 
|  | 18 namespace test { | 
|  | 19 | 
|  | 20 namespace { | 
|  | 21 | 
|  | 22 // Transforms a copy of |point| with |transform| and returns it. | 
|  | 23 gfx::Point TransformPoint(const gfx::Transform& transform, | 
|  | 24                           const gfx::Point& point) { | 
|  | 25   gfx::Point transformed_point = point; | 
|  | 26   transform.TransformPoint(&transformed_point); | 
|  | 27   return transformed_point; | 
|  | 28 } | 
|  | 29 | 
|  | 30 }  // namespace | 
|  | 31 | 
|  | 32 class InkDropAnimationTest : public testing::Test { | 
|  | 33  public: | 
|  | 34   InkDropAnimationTest() {} | 
|  | 35   ~InkDropAnimationTest() override {} | 
|  | 36 | 
|  | 37  protected: | 
|  | 38   scoped_ptr<InkDropAnimation> CreateInkDropAnimation() const; | 
|  | 39 | 
|  | 40  private: | 
|  | 41   DISALLOW_COPY_AND_ASSIGN(InkDropAnimationTest); | 
|  | 42 }; | 
|  | 43 | 
|  | 44 // Returns a new InkDropAnimation with default parameters. | 
|  | 45 scoped_ptr<InkDropAnimation> InkDropAnimationTest::CreateInkDropAnimation() | 
|  | 46     const { | 
|  | 47   return make_scoped_ptr( | 
|  | 48       new InkDropAnimation(gfx::Size(10, 10), 2, gfx::Size(8, 8), 1)); | 
|  | 49 } | 
|  | 50 | 
|  | 51 TEST_F(InkDropAnimationTest, InitialStateAfterConstruction) { | 
|  | 52   scoped_ptr<InkDropAnimation> ink_drop_animation = CreateInkDropAnimation(); | 
|  | 53   EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_animation->ink_drop_state()); | 
|  | 54 } | 
|  | 55 | 
|  | 56 TEST_F(InkDropAnimationTest, AnimateToActionPending) { | 
|  | 57   scoped_ptr<InkDropAnimation> ink_drop_animation = CreateInkDropAnimation(); | 
|  | 58   ink_drop_animation->AnimateToState(views::InkDropState::ACTION_PENDING); | 
|  | 59   EXPECT_EQ(views::InkDropState::ACTION_PENDING, | 
|  | 60             ink_drop_animation->ink_drop_state()); | 
|  | 61 } | 
|  | 62 | 
|  | 63 TEST_F(InkDropAnimationTest, AnimateToQuickAction) { | 
|  | 64   scoped_ptr<InkDropAnimation> ink_drop_animation = CreateInkDropAnimation(); | 
|  | 65   ink_drop_animation->AnimateToState(views::InkDropState::QUICK_ACTION); | 
|  | 66   EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_animation->ink_drop_state()); | 
|  | 67 } | 
|  | 68 | 
|  | 69 TEST_F(InkDropAnimationTest, AnimateToSlowActionPending) { | 
|  | 70   scoped_ptr<InkDropAnimation> ink_drop_animation = CreateInkDropAnimation(); | 
|  | 71   ink_drop_animation->AnimateToState(views::InkDropState::SLOW_ACTION_PENDING); | 
|  | 72   EXPECT_EQ(views::InkDropState::SLOW_ACTION_PENDING, | 
|  | 73             ink_drop_animation->ink_drop_state()); | 
|  | 74 } | 
|  | 75 | 
|  | 76 TEST_F(InkDropAnimationTest, AnimateToSlowAction) { | 
|  | 77   scoped_ptr<InkDropAnimation> ink_drop_animation = CreateInkDropAnimation(); | 
|  | 78   ink_drop_animation->AnimateToState(views::InkDropState::SLOW_ACTION); | 
|  | 79   EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_animation->ink_drop_state()); | 
|  | 80 } | 
|  | 81 | 
|  | 82 TEST_F(InkDropAnimationTest, AnimateToActivated) { | 
|  | 83   scoped_ptr<InkDropAnimation> ink_drop_animation = CreateInkDropAnimation(); | 
|  | 84   ink_drop_animation->AnimateToState(views::InkDropState::ACTIVATED); | 
|  | 85   EXPECT_EQ(views::InkDropState::ACTIVATED, | 
|  | 86             ink_drop_animation->ink_drop_state()); | 
|  | 87 } | 
|  | 88 | 
|  | 89 TEST_F(InkDropAnimationTest, AnimateToDeactivated) { | 
|  | 90   scoped_ptr<InkDropAnimation> ink_drop_animation = CreateInkDropAnimation(); | 
|  | 91   ink_drop_animation->AnimateToState(views::InkDropState::DEACTIVATED); | 
|  | 92   EXPECT_EQ(views::InkDropState::HIDDEN, ink_drop_animation->ink_drop_state()); | 
|  | 93 } | 
|  | 94 | 
|  | 95 TEST_F(InkDropAnimationTest, | 
|  | 96        TransformedPointsUsingTransformsFromCalculateCircleTransforms) { | 
|  | 97   const int kHalfDrawnSize = 5; | 
|  | 98   const int kDrawnSize = 2 * kHalfDrawnSize; | 
|  | 99 | 
|  | 100   const int kHalfTransformedSize = 100; | 
|  | 101   const int kTransformedSize = 2 * kHalfTransformedSize; | 
|  | 102 | 
|  | 103   // Constant points in the drawn space that will be transformed. | 
|  | 104   const gfx::Point center(kHalfDrawnSize, kHalfDrawnSize); | 
|  | 105   const gfx::Point mid_left(0, kHalfDrawnSize); | 
|  | 106   const gfx::Point mid_right(kDrawnSize, kHalfDrawnSize); | 
|  | 107   const gfx::Point top_mid(kHalfDrawnSize, 0); | 
|  | 108   const gfx::Point bottom_mid(kHalfDrawnSize, kDrawnSize); | 
|  | 109 | 
|  | 110   scoped_ptr<InkDropAnimation> ink_drop_animation( | 
|  | 111       new InkDropAnimation(gfx::Size(kDrawnSize, kDrawnSize), 2, | 
|  | 112                            gfx::Size(kHalfDrawnSize, kHalfDrawnSize), 1)); | 
|  | 113   InkDropAnimationTestApi test_api(ink_drop_animation.get()); | 
|  | 114 | 
|  | 115   InkDropAnimationTestApi::InkDropTransforms transforms; | 
|  | 116   test_api.CalculateCircleTransforms( | 
|  | 117       gfx::SizeF(kTransformedSize, kTransformedSize), transforms); | 
|  | 118 | 
|  | 119   // Transform variables to reduce verbosity of actual verification code. | 
|  | 120   const gfx::Transform kTopLeftTransform = | 
|  | 121       transforms[InkDropAnimationTestApi::PaintedShape::TOP_LEFT_CIRCLE]; | 
|  | 122   const gfx::Transform kTopRightTransform = | 
|  | 123       transforms[InkDropAnimationTestApi::PaintedShape::TOP_RIGHT_CIRCLE]; | 
|  | 124   const gfx::Transform kBottomRightTransform = | 
|  | 125       transforms[InkDropAnimationTestApi::PaintedShape::BOTTOM_RIGHT_CIRCLE]; | 
|  | 126   const gfx::Transform kBottomLeftTransform = | 
|  | 127       transforms[InkDropAnimationTestApi::PaintedShape::BOTTOM_LEFT_CIRCLE]; | 
|  | 128   const gfx::Transform kHorizontalTransform = | 
|  | 129       transforms[InkDropAnimationTestApi::PaintedShape::HORIZONTAL_RECT]; | 
|  | 130   const gfx::Transform kVerticalTransform = | 
|  | 131       transforms[InkDropAnimationTestApi::PaintedShape::VERTICAL_RECT]; | 
|  | 132 | 
|  | 133   // Top left circle | 
|  | 134   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kTopLeftTransform, center)); | 
|  | 135   EXPECT_EQ(gfx::Point(-kHalfTransformedSize, 0), | 
|  | 136             TransformPoint(kTopLeftTransform, mid_left)); | 
|  | 137   EXPECT_EQ(gfx::Point(kHalfTransformedSize, 0), | 
|  | 138             TransformPoint(kTopLeftTransform, mid_right)); | 
|  | 139   EXPECT_EQ(gfx::Point(0, -kHalfTransformedSize), | 
|  | 140             TransformPoint(kTopLeftTransform, top_mid)); | 
|  | 141   EXPECT_EQ(gfx::Point(0, kHalfTransformedSize), | 
|  | 142             TransformPoint(kTopLeftTransform, bottom_mid)); | 
|  | 143 | 
|  | 144   // Top right circle | 
|  | 145   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kTopRightTransform, center)); | 
|  | 146   EXPECT_EQ(gfx::Point(-kHalfTransformedSize, 0), | 
|  | 147             TransformPoint(kTopRightTransform, mid_left)); | 
|  | 148   EXPECT_EQ(gfx::Point(kHalfTransformedSize, 0), | 
|  | 149             TransformPoint(kTopRightTransform, mid_right)); | 
|  | 150   EXPECT_EQ(gfx::Point(0, -kHalfTransformedSize), | 
|  | 151             TransformPoint(kTopRightTransform, top_mid)); | 
|  | 152   EXPECT_EQ(gfx::Point(0, kHalfTransformedSize), | 
|  | 153             TransformPoint(kTopRightTransform, bottom_mid)); | 
|  | 154 | 
|  | 155   // Bottom right circle | 
|  | 156   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kBottomRightTransform, center)); | 
|  | 157   EXPECT_EQ(gfx::Point(-kHalfTransformedSize, 0), | 
|  | 158             TransformPoint(kBottomRightTransform, mid_left)); | 
|  | 159   EXPECT_EQ(gfx::Point(kHalfTransformedSize, 0), | 
|  | 160             TransformPoint(kBottomRightTransform, mid_right)); | 
|  | 161   EXPECT_EQ(gfx::Point(0, -kHalfTransformedSize), | 
|  | 162             TransformPoint(kBottomRightTransform, top_mid)); | 
|  | 163   EXPECT_EQ(gfx::Point(0, kHalfTransformedSize), | 
|  | 164             TransformPoint(kBottomRightTransform, bottom_mid)); | 
|  | 165 | 
|  | 166   // Bottom left circle | 
|  | 167   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kBottomLeftTransform, center)); | 
|  | 168   EXPECT_EQ(gfx::Point(-kHalfTransformedSize, 0), | 
|  | 169             TransformPoint(kBottomLeftTransform, mid_left)); | 
|  | 170   EXPECT_EQ(gfx::Point(kHalfTransformedSize, 0), | 
|  | 171             TransformPoint(kBottomLeftTransform, mid_right)); | 
|  | 172   EXPECT_EQ(gfx::Point(0, -kHalfTransformedSize), | 
|  | 173             TransformPoint(kBottomLeftTransform, top_mid)); | 
|  | 174   EXPECT_EQ(gfx::Point(0, kHalfTransformedSize), | 
|  | 175             TransformPoint(kBottomLeftTransform, bottom_mid)); | 
|  | 176 | 
|  | 177   // Horizontal rectangle | 
|  | 178   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kHorizontalTransform, center)); | 
|  | 179   EXPECT_EQ(gfx::Point(-kHalfTransformedSize, 0), | 
|  | 180             TransformPoint(kHorizontalTransform, mid_left)); | 
|  | 181   EXPECT_EQ(gfx::Point(kHalfTransformedSize, 0), | 
|  | 182             TransformPoint(kHorizontalTransform, mid_right)); | 
|  | 183   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kHorizontalTransform, top_mid)); | 
|  | 184   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kHorizontalTransform, bottom_mid)); | 
|  | 185 | 
|  | 186   // Vertical rectangle | 
|  | 187   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kVerticalTransform, center)); | 
|  | 188   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kVerticalTransform, mid_left)); | 
|  | 189   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kVerticalTransform, mid_right)); | 
|  | 190   EXPECT_EQ(gfx::Point(0, -kHalfTransformedSize), | 
|  | 191             TransformPoint(kVerticalTransform, top_mid)); | 
|  | 192   EXPECT_EQ(gfx::Point(0, kHalfTransformedSize), | 
|  | 193             TransformPoint(kVerticalTransform, bottom_mid)); | 
|  | 194 } | 
|  | 195 | 
|  | 196 TEST_F(InkDropAnimationTest, | 
|  | 197        TransformedPointsUsingTransformsFromCalculateRectTransforms) { | 
|  | 198   const int kHalfDrawnSize = 5; | 
|  | 199   const int kDrawnSize = 2 * kHalfDrawnSize; | 
|  | 200 | 
|  | 201   const int kTransformedRadius = 10; | 
|  | 202 | 
|  | 203   const int kHalfTransformedWidth = 100; | 
|  | 204   const int kTransformedWidth = 2 * kHalfTransformedWidth; | 
|  | 205 | 
|  | 206   const int kHalfTransformedHeight = 100; | 
|  | 207   const int kTransformedHeight = 2 * kHalfTransformedHeight; | 
|  | 208 | 
|  | 209   // Constant points in the drawn space that will be transformed. | 
|  | 210   const gfx::Point center(kHalfDrawnSize, kHalfDrawnSize); | 
|  | 211   const gfx::Point mid_left(0, kHalfDrawnSize); | 
|  | 212   const gfx::Point mid_right(kDrawnSize, kHalfDrawnSize); | 
|  | 213   const gfx::Point top_mid(kHalfDrawnSize, 0); | 
|  | 214   const gfx::Point bottom_mid(kHalfDrawnSize, kDrawnSize); | 
|  | 215 | 
|  | 216   scoped_ptr<InkDropAnimation> ink_drop_animation( | 
|  | 217       new InkDropAnimation(gfx::Size(kDrawnSize, kDrawnSize), 2, | 
|  | 218                            gfx::Size(kHalfDrawnSize, kHalfDrawnSize), 1)); | 
|  | 219   InkDropAnimationTestApi test_api(ink_drop_animation.get()); | 
|  | 220 | 
|  | 221   InkDropAnimationTestApi::InkDropTransforms transforms; | 
|  | 222   test_api.CalculateRectTransforms( | 
|  | 223       gfx::SizeF(kTransformedWidth, kTransformedHeight), kTransformedRadius, | 
|  | 224       transforms); | 
|  | 225 | 
|  | 226   // Transform variables to reduce verbosity of actual verification code. | 
|  | 227   const gfx::Transform kTopLeftTransform = | 
|  | 228       transforms[InkDropAnimationTestApi::PaintedShape::TOP_LEFT_CIRCLE]; | 
|  | 229   const gfx::Transform kTopRightTransform = | 
|  | 230       transforms[InkDropAnimationTestApi::PaintedShape::TOP_RIGHT_CIRCLE]; | 
|  | 231   const gfx::Transform kBottomRightTransform = | 
|  | 232       transforms[InkDropAnimationTestApi::PaintedShape::BOTTOM_RIGHT_CIRCLE]; | 
|  | 233   const gfx::Transform kBottomLeftTransform = | 
|  | 234       transforms[InkDropAnimationTestApi::PaintedShape::BOTTOM_LEFT_CIRCLE]; | 
|  | 235   const gfx::Transform kHorizontalTransform = | 
|  | 236       transforms[InkDropAnimationTestApi::PaintedShape::HORIZONTAL_RECT]; | 
|  | 237   const gfx::Transform kVerticalTransform = | 
|  | 238       transforms[InkDropAnimationTestApi::PaintedShape::VERTICAL_RECT]; | 
|  | 239 | 
|  | 240   const int x_offset = kHalfTransformedWidth - kTransformedRadius; | 
|  | 241   const int y_offset = kHalfTransformedWidth - kTransformedRadius; | 
|  | 242 | 
|  | 243   // Top left circle | 
|  | 244   EXPECT_EQ(gfx::Point(-x_offset, -y_offset), | 
|  | 245             TransformPoint(kTopLeftTransform, center)); | 
|  | 246   EXPECT_EQ(gfx::Point(-kHalfTransformedWidth, -y_offset), | 
|  | 247             TransformPoint(kTopLeftTransform, mid_left)); | 
|  | 248   EXPECT_EQ(gfx::Point(-x_offset, -kHalfTransformedHeight), | 
|  | 249             TransformPoint(kTopLeftTransform, top_mid)); | 
|  | 250 | 
|  | 251   // Top right circle | 
|  | 252   EXPECT_EQ(gfx::Point(x_offset, -y_offset), | 
|  | 253             TransformPoint(kTopRightTransform, center)); | 
|  | 254   EXPECT_EQ(gfx::Point(kHalfTransformedWidth, -y_offset), | 
|  | 255             TransformPoint(kTopRightTransform, mid_right)); | 
|  | 256   EXPECT_EQ(gfx::Point(x_offset, -kHalfTransformedHeight), | 
|  | 257             TransformPoint(kTopRightTransform, top_mid)); | 
|  | 258 | 
|  | 259   // Bottom right circle | 
|  | 260   EXPECT_EQ(gfx::Point(x_offset, y_offset), | 
|  | 261             TransformPoint(kBottomRightTransform, center)); | 
|  | 262   EXPECT_EQ(gfx::Point(kHalfTransformedWidth, y_offset), | 
|  | 263             TransformPoint(kBottomRightTransform, mid_right)); | 
|  | 264   EXPECT_EQ(gfx::Point(x_offset, kHalfTransformedHeight), | 
|  | 265             TransformPoint(kBottomRightTransform, bottom_mid)); | 
|  | 266 | 
|  | 267   // Bottom left circle | 
|  | 268   EXPECT_EQ(gfx::Point(-x_offset, y_offset), | 
|  | 269             TransformPoint(kBottomLeftTransform, center)); | 
|  | 270   EXPECT_EQ(gfx::Point(-kHalfTransformedWidth, y_offset), | 
|  | 271             TransformPoint(kBottomLeftTransform, mid_left)); | 
|  | 272   EXPECT_EQ(gfx::Point(-x_offset, kHalfTransformedHeight), | 
|  | 273             TransformPoint(kBottomLeftTransform, bottom_mid)); | 
|  | 274 | 
|  | 275   // Horizontal rectangle | 
|  | 276   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kHorizontalTransform, center)); | 
|  | 277   EXPECT_EQ(gfx::Point(-kHalfTransformedWidth, 0), | 
|  | 278             TransformPoint(kHorizontalTransform, mid_left)); | 
|  | 279   EXPECT_EQ(gfx::Point(kHalfTransformedWidth, 0), | 
|  | 280             TransformPoint(kHorizontalTransform, mid_right)); | 
|  | 281   EXPECT_EQ(gfx::Point(0, -y_offset), | 
|  | 282             TransformPoint(kHorizontalTransform, top_mid)); | 
|  | 283   EXPECT_EQ(gfx::Point(0, y_offset), | 
|  | 284             TransformPoint(kHorizontalTransform, bottom_mid)); | 
|  | 285 | 
|  | 286   // Vertical rectangle | 
|  | 287   EXPECT_EQ(gfx::Point(0, 0), TransformPoint(kVerticalTransform, center)); | 
|  | 288   EXPECT_EQ(gfx::Point(-x_offset, 0), | 
|  | 289             TransformPoint(kVerticalTransform, mid_left)); | 
|  | 290   EXPECT_EQ(gfx::Point(x_offset, 0), | 
|  | 291             TransformPoint(kVerticalTransform, mid_right)); | 
|  | 292   EXPECT_EQ(gfx::Point(0, -kHalfTransformedHeight), | 
|  | 293             TransformPoint(kVerticalTransform, top_mid)); | 
|  | 294   EXPECT_EQ(gfx::Point(0, kHalfTransformedHeight), | 
|  | 295             TransformPoint(kVerticalTransform, bottom_mid)); | 
|  | 296 } | 
|  | 297 | 
|  | 298 }  // namespace test | 
|  | 299 }  // namespace views | 
|  | 300 | 
|  | 301 #endif  // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_UNITTEST_H_ | 
| OLD | NEW | 
|---|