Chromium Code Reviews| 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_CONTROLLER_FACTORY_UNITTEST_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ |
|
varkha
2015/12/22 02:49:56
Is this necessary?
bruthig
2015/12/22 16:20:34
Removed.
| |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/base/resource/material_design/material_design_controller.h" | |
| 11 #include "ui/base/test/material_design_controller_test_api.h" | 12 #include "ui/base/test/material_design_controller_test_api.h" |
| 13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
| 12 #include "ui/views/animation/ink_drop_animation_controller.h" | 14 #include "ui/views/animation/ink_drop_animation_controller.h" |
| 13 #include "ui/views/animation/ink_drop_animation_controller_factory.h" | 15 #include "ui/views/animation/ink_drop_animation_controller_factory.h" |
| 14 #include "ui/views/animation/ink_drop_host.h" | 16 #include "ui/views/animation/ink_drop_host.h" |
| 15 #include "ui/views/animation/ink_drop_state.h" | 17 #include "ui/views/animation/ink_drop_state.h" |
| 16 #include "ui/views/animation/test/test_ink_drop_host.h" | 18 #include "ui/views/animation/test/test_ink_drop_host.h" |
| 17 | 19 |
| 18 namespace views { | 20 namespace views { |
| 19 | 21 |
| 20 // Macro that will execute |test_code| against all derivatives of the | 22 class InkDropAnimationControllerFactoryTest |
| 21 // InkDropAnimationController returned by the InkDropAnimationControllerFactory. | 23 : public testing::TestWithParam<ui::MaterialDesignController::Mode> { |
| 22 // TODO(bruthig): Refactor these tests to use TEST_P and | |
| 23 // INSTANTIATE_TEST_CASE_P. | |
| 24 #define TEST_ALL_INK_DROPS(test_name, test_code) \ | |
| 25 TEST_F(InkDropAnimationControllerFactoryTest, test_name) \ | |
| 26 test_code TEST_F(MDInkDropAnimationControllerFactoryTest, test_name) test_code | |
| 27 | |
| 28 // Test fixture to test the non material design InkDropAnimationController. | |
| 29 class InkDropAnimationControllerFactoryTest : public testing::Test { | |
| 30 public: | 24 public: |
| 31 InkDropAnimationControllerFactoryTest() {} | 25 InkDropAnimationControllerFactoryTest(); |
| 32 ~InkDropAnimationControllerFactoryTest() override {} | 26 ~InkDropAnimationControllerFactoryTest(); |
| 33 | |
| 34 // testing::Test: | |
| 35 void SetUp() override; | |
| 36 void TearDown() override; | |
| 37 | 27 |
| 38 protected: | 28 protected: |
| 39 // A dummy InkDropHost required to create an InkDropAnimationController. | 29 // A dummy InkDropHost required to create an InkDropAnimationController. |
| 40 TestInkDropHost test_ink_drop_host_; | 30 TestInkDropHost test_ink_drop_host_; |
| 41 | 31 |
| 42 // The InkDropAnimationController returned by the | 32 // The InkDropAnimationController returned by the |
| 43 // InkDropAnimationControllerFactory test target. | 33 // InkDropAnimationControllerFactory test target. |
| 44 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; | 34 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; |
| 45 | 35 |
| 46 private: | 36 private: |
| 37 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; | |
| 38 | |
| 47 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); | 39 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); |
| 48 }; | 40 }; |
| 49 | 41 |
| 50 void InkDropAnimationControllerFactoryTest::SetUp() { | 42 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest() |
| 43 : ink_drop_animation_controller_(nullptr) { | |
| 51 // Any call by a previous test to MaterialDesignController::GetMode() will | 44 // Any call by a previous test to MaterialDesignController::GetMode() will |
| 52 // initialize and cache the mode. This ensures that these tests will run from | 45 // initialize and cache the mode. This ensures that these tests will run from |
| 53 // a non-initialized state. | 46 // a non-initialized state. |
| 54 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 47 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
| 48 ui::test::MaterialDesignControllerTestAPI::SetMode(GetParam()); | |
| 49 ink_drop_animation_controller_.reset( | |
| 50 InkDropAnimationControllerFactory::CreateInkDropAnimationController( | |
| 51 &test_ink_drop_host_) | |
| 52 .release()); | |
| 55 | 53 |
| 56 ink_drop_animation_controller_ = | 54 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| 57 InkDropAnimationControllerFactory::CreateInkDropAnimationController( | 55 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
| 58 &test_ink_drop_host_); | |
| 59 } | 56 } |
| 60 | 57 |
| 61 void InkDropAnimationControllerFactoryTest::TearDown() { | 58 InkDropAnimationControllerFactoryTest:: |
| 59 ~InkDropAnimationControllerFactoryTest() { | |
| 62 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); | 60 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
| 63 } | 61 } |
| 64 | 62 |
| 65 // Test fixture to test the material design InkDropAnimationController. | 63 // Note: First argument is optional and intentionally left blank. |
| 66 class MDInkDropAnimationControllerFactoryTest | 64 // (it's a prefix for the generated test cases) |
| 67 : public InkDropAnimationControllerFactoryTest { | 65 INSTANTIATE_TEST_CASE_P( |
| 68 public: | 66 , |
| 69 MDInkDropAnimationControllerFactoryTest() {} | 67 InkDropAnimationControllerFactoryTest, |
| 68 testing::Values(ui::MaterialDesignController::NON_MATERIAL, | |
| 69 ui::MaterialDesignController::MATERIAL_NORMAL)); | |
| 70 | 70 |
| 71 // InkDropAnimationControllerFactoryTest: | 71 TEST_P(InkDropAnimationControllerFactoryTest, |
| 72 void SetUp() override; | 72 VerifyAllInkDropLayersRemovedAfterDestruction) { |
| 73 | 73 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
| 74 private: | 74 ink_drop_animation_controller_.reset(); |
| 75 DISALLOW_COPY_AND_ASSIGN(MDInkDropAnimationControllerFactoryTest); | 75 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); |
| 76 }; | |
| 77 | |
| 78 void MDInkDropAnimationControllerFactoryTest::SetUp() { | |
| 79 ui::test::MaterialDesignControllerTestAPI::SetMode( | |
| 80 ui::MaterialDesignController::MATERIAL_NORMAL); | |
| 81 InkDropAnimationControllerFactoryTest::SetUp(); | |
| 82 } | 76 } |
| 83 | 77 |
| 84 TEST_ALL_INK_DROPS( | 78 TEST_P(InkDropAnimationControllerFactoryTest, StateIsHiddenInitially) { |
| 85 VerifyAllInkDropLayersRemovedAfterDestruction, | 79 EXPECT_EQ(InkDropState::HIDDEN, |
| 86 { | 80 ink_drop_animation_controller_->GetInkDropState()); |
| 87 ink_drop_animation_controller_->AnimateToState( | 81 } |
| 88 InkDropState::ACTION_PENDING); | |
| 89 ink_drop_animation_controller_.reset(); | |
| 90 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); | |
| 91 }) | |
| 92 | 82 |
| 93 TEST_ALL_INK_DROPS(StateIsHiddenInitially, | 83 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickAction) { |
| 94 { | 84 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
| 95 EXPECT_EQ( | 85 ink_drop_animation_controller_->AnimateToState(InkDropState::QUICK_ACTION); |
| 96 InkDropState::HIDDEN, | 86 EXPECT_EQ(InkDropState::HIDDEN, |
| 97 ink_drop_animation_controller_->GetInkDropState()); | 87 ink_drop_animation_controller_->GetInkDropState()); |
| 98 }) | 88 } |
| 99 | 89 |
| 100 TEST_ALL_INK_DROPS(TypicalQuickAction, | 90 TEST_P(InkDropAnimationControllerFactoryTest, CancelQuickAction) { |
| 101 { | 91 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
| 102 ink_drop_animation_controller_->AnimateToState( | 92 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); |
| 103 InkDropState::ACTION_PENDING); | 93 EXPECT_EQ(InkDropState::HIDDEN, |
| 104 ink_drop_animation_controller_->AnimateToState( | 94 ink_drop_animation_controller_->GetInkDropState()); |
| 105 InkDropState::QUICK_ACTION); | 95 } |
| 106 EXPECT_EQ( | |
| 107 InkDropState::HIDDEN, | |
| 108 ink_drop_animation_controller_->GetInkDropState()); | |
| 109 }) | |
| 110 | 96 |
| 111 TEST_ALL_INK_DROPS(CancelQuickAction, | 97 TEST_P(InkDropAnimationControllerFactoryTest, TypicalSlowAction) { |
| 112 { | 98 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
| 113 ink_drop_animation_controller_->AnimateToState( | 99 ink_drop_animation_controller_->AnimateToState( |
| 114 InkDropState::ACTION_PENDING); | 100 InkDropState::SLOW_ACTION_PENDING); |
| 115 ink_drop_animation_controller_->AnimateToState( | 101 ink_drop_animation_controller_->AnimateToState(InkDropState::SLOW_ACTION); |
| 116 InkDropState::HIDDEN); | 102 EXPECT_EQ(InkDropState::HIDDEN, |
| 117 EXPECT_EQ( | 103 ink_drop_animation_controller_->GetInkDropState()); |
| 118 InkDropState::HIDDEN, | 104 } |
| 119 ink_drop_animation_controller_->GetInkDropState()); | |
| 120 }) | |
| 121 | 105 |
| 122 TEST_ALL_INK_DROPS(TypicalSlowAction, | 106 TEST_P(InkDropAnimationControllerFactoryTest, CancelSlowAction) { |
| 123 { | 107 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
| 124 ink_drop_animation_controller_->AnimateToState( | 108 ink_drop_animation_controller_->AnimateToState( |
| 125 InkDropState::ACTION_PENDING); | 109 InkDropState::SLOW_ACTION_PENDING); |
| 126 ink_drop_animation_controller_->AnimateToState( | 110 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); |
| 127 InkDropState::SLOW_ACTION_PENDING); | 111 EXPECT_EQ(InkDropState::HIDDEN, |
| 128 ink_drop_animation_controller_->AnimateToState( | 112 ink_drop_animation_controller_->GetInkDropState()); |
| 129 InkDropState::SLOW_ACTION); | 113 } |
| 130 EXPECT_EQ( | |
| 131 InkDropState::HIDDEN, | |
| 132 ink_drop_animation_controller_->GetInkDropState()); | |
| 133 }) | |
| 134 | 114 |
| 135 TEST_ALL_INK_DROPS(CancelSlowAction, | 115 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickActivated) { |
| 136 { | 116 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
| 137 ink_drop_animation_controller_->AnimateToState( | 117 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); |
| 138 InkDropState::ACTION_PENDING); | 118 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); |
| 139 ink_drop_animation_controller_->AnimateToState( | 119 EXPECT_EQ(InkDropState::HIDDEN, |
| 140 InkDropState::SLOW_ACTION_PENDING); | 120 ink_drop_animation_controller_->GetInkDropState()); |
| 141 ink_drop_animation_controller_->AnimateToState( | 121 } |
| 142 InkDropState::HIDDEN); | |
| 143 EXPECT_EQ( | |
| 144 InkDropState::HIDDEN, | |
| 145 ink_drop_animation_controller_->GetInkDropState()); | |
| 146 }) | |
| 147 | 122 |
| 148 TEST_ALL_INK_DROPS( | 123 TEST_P(InkDropAnimationControllerFactoryTest, TypicalSlowActivated) { |
| 149 TypicalQuickActivated, | 124 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); |
| 150 { | 125 ink_drop_animation_controller_->AnimateToState( |
| 151 ink_drop_animation_controller_->AnimateToState( | 126 InkDropState::SLOW_ACTION_PENDING); |
| 152 InkDropState::ACTION_PENDING); | 127 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); |
| 153 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); | 128 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); |
| 154 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); | 129 EXPECT_EQ(InkDropState::HIDDEN, |
| 155 EXPECT_EQ(InkDropState::HIDDEN, | 130 ink_drop_animation_controller_->GetInkDropState()); |
| 156 ink_drop_animation_controller_->GetInkDropState()); | 131 } |
| 157 }) | |
| 158 | |
| 159 TEST_ALL_INK_DROPS( | |
| 160 TypicalSlowActivated, | |
| 161 { | |
| 162 ink_drop_animation_controller_->AnimateToState( | |
| 163 InkDropState::ACTION_PENDING); | |
| 164 ink_drop_animation_controller_->AnimateToState( | |
| 165 InkDropState::SLOW_ACTION_PENDING); | |
| 166 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); | |
| 167 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); | |
| 168 EXPECT_EQ(InkDropState::HIDDEN, | |
| 169 ink_drop_animation_controller_->GetInkDropState()); | |
| 170 }) | |
| 171 | 132 |
| 172 } // namespace views | 133 } // namespace views |
| 173 | 134 |
| 174 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ | 135 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_CONTROLLER_FACTORY_UNITTEST_H_ |
| OLD | NEW |