diff options
Diffstat (limited to 'chromium/ui/views/animation/ink_drop_animation_controller_factory_unittest.cc')
-rw-r--r-- | chromium/ui/views/animation/ink_drop_animation_controller_factory_unittest.cc | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/chromium/ui/views/animation/ink_drop_animation_controller_factory_unittest.cc b/chromium/ui/views/animation/ink_drop_animation_controller_factory_unittest.cc index 1743c59355d..c75b2c23d7b 100644 --- a/chromium/ui/views/animation/ink_drop_animation_controller_factory_unittest.cc +++ b/chromium/ui/views/animation/ink_drop_animation_controller_factory_unittest.cc @@ -4,12 +4,16 @@ #include "base/macros.h" #include "base/memory/scoped_ptr.h" +#include "base/test/test_mock_time_task_runner.h" +#include "base/thread_task_runner_handle.h" +#include "base/timer/timer.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/resource/material_design/material_design_controller.h" +#include "ui/base/material_design/material_design_controller.h" #include "ui/base/test/material_design_controller_test_api.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/views/animation/ink_drop_animation_controller.h" #include "ui/views/animation/ink_drop_animation_controller_factory.h" +#include "ui/views/animation/ink_drop_animation_controller_impl.h" #include "ui/views/animation/ink_drop_host.h" #include "ui/views/animation/ink_drop_state.h" #include "ui/views/animation/test/test_ink_drop_host.h" @@ -17,7 +21,8 @@ namespace views { class InkDropAnimationControllerFactoryTest - : public testing::TestWithParam<ui::MaterialDesignController::Mode> { + : public testing::TestWithParam< + testing::tuple<ui::MaterialDesignController::Mode>> { public: InkDropAnimationControllerFactoryTest(); ~InkDropAnimationControllerFactoryTest(); @@ -31,8 +36,14 @@ class InkDropAnimationControllerFactoryTest scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; private: + // Extracts and returns the material design mode from the test parameters. + ui::MaterialDesignController::Mode GetMaterialMode() const; + scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; + // Required by base::Timer's. + scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; + DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); }; @@ -42,16 +53,28 @@ InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest() // initialize and cache the mode. This ensures that these tests will run from // a non-initialized state. ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); - ui::test::MaterialDesignControllerTestAPI::SetMode(GetParam()); + ui::test::MaterialDesignControllerTestAPI::SetMode(GetMaterialMode()); ink_drop_animation_controller_.reset( InkDropAnimationControllerFactory::CreateInkDropAnimationController( &test_ink_drop_host_) .release()); - ink_drop_animation_controller_->SetInkDropSize(gfx::Size(10, 10), 4, - gfx::Size(8, 8), 2); zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); + + switch (GetMaterialMode()) { + case ui::MaterialDesignController::NON_MATERIAL: + break; + case ui::MaterialDesignController::MATERIAL_NORMAL: + case ui::MaterialDesignController::MATERIAL_HYBRID: + // The Timer's used by the InkDropAnimationControllerImpl class require a + // base::ThreadTaskRunnerHandle instance. + scoped_refptr<base::TestMockTimeTaskRunner> task_runner( + new base::TestMockTimeTaskRunner); + thread_task_runner_handle_.reset( + new base::ThreadTaskRunnerHandle(task_runner)); + break; + } } InkDropAnimationControllerFactoryTest:: @@ -59,56 +82,72 @@ InkDropAnimationControllerFactoryTest:: ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); } +ui::MaterialDesignController::Mode +InkDropAnimationControllerFactoryTest::GetMaterialMode() const { + return testing::get<0>(GetParam()); +} + // Note: First argument is optional and intentionally left blank. // (it's a prefix for the generated test cases) INSTANTIATE_TEST_CASE_P( , InkDropAnimationControllerFactoryTest, testing::Values(ui::MaterialDesignController::NON_MATERIAL, - ui::MaterialDesignController::MATERIAL_NORMAL)); + ui::MaterialDesignController::MATERIAL_NORMAL, + ui::MaterialDesignController::MATERIAL_HYBRID)); TEST_P(InkDropAnimationControllerFactoryTest, - VerifyAllInkDropLayersRemovedAfterDestruction) { + VerifyInkDropLayersRemovedAfterDestructionWhenRippleIsActive) { ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); ink_drop_animation_controller_.reset(); EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); } +TEST_P(InkDropAnimationControllerFactoryTest, + VerifyInkDropLayersRemovedAfterDestructionWhenHoverIsActive) { + test_ink_drop_host_.set_should_show_hover(true); + ink_drop_animation_controller_->SetHovered(true); + ink_drop_animation_controller_.reset(); + EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); +} + TEST_P(InkDropAnimationControllerFactoryTest, StateIsHiddenInitially) { EXPECT_EQ(InkDropState::HIDDEN, - ink_drop_animation_controller_->GetInkDropState()); + ink_drop_animation_controller_->GetTargetInkDropState()); } TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickAction) { ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); - ink_drop_animation_controller_->AnimateToState(InkDropState::QUICK_ACTION); + ink_drop_animation_controller_->AnimateToState( + InkDropState::ACTION_TRIGGERED); EXPECT_EQ(InkDropState::HIDDEN, - ink_drop_animation_controller_->GetInkDropState()); + ink_drop_animation_controller_->GetTargetInkDropState()); } TEST_P(InkDropAnimationControllerFactoryTest, CancelQuickAction) { ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); EXPECT_EQ(InkDropState::HIDDEN, - ink_drop_animation_controller_->GetInkDropState()); + ink_drop_animation_controller_->GetTargetInkDropState()); } TEST_P(InkDropAnimationControllerFactoryTest, TypicalSlowAction) { ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); ink_drop_animation_controller_->AnimateToState( - InkDropState::SLOW_ACTION_PENDING); - ink_drop_animation_controller_->AnimateToState(InkDropState::SLOW_ACTION); + InkDropState::ALTERNATE_ACTION_PENDING); + ink_drop_animation_controller_->AnimateToState( + InkDropState::ALTERNATE_ACTION_TRIGGERED); EXPECT_EQ(InkDropState::HIDDEN, - ink_drop_animation_controller_->GetInkDropState()); + ink_drop_animation_controller_->GetTargetInkDropState()); } TEST_P(InkDropAnimationControllerFactoryTest, CancelSlowAction) { ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); ink_drop_animation_controller_->AnimateToState( - InkDropState::SLOW_ACTION_PENDING); + InkDropState::ALTERNATE_ACTION_PENDING); ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); EXPECT_EQ(InkDropState::HIDDEN, - ink_drop_animation_controller_->GetInkDropState()); + ink_drop_animation_controller_->GetTargetInkDropState()); } TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickActivated) { @@ -116,17 +155,17 @@ TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickActivated) { ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); EXPECT_EQ(InkDropState::HIDDEN, - ink_drop_animation_controller_->GetInkDropState()); + ink_drop_animation_controller_->GetTargetInkDropState()); } TEST_P(InkDropAnimationControllerFactoryTest, TypicalSlowActivated) { ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); ink_drop_animation_controller_->AnimateToState( - InkDropState::SLOW_ACTION_PENDING); + InkDropState::ALTERNATE_ACTION_PENDING); ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); EXPECT_EQ(InkDropState::HIDDEN, - ink_drop_animation_controller_->GetInkDropState()); + ink_drop_animation_controller_->GetTargetInkDropState()); } } // namespace views |