Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: ui/views/animation/ink_drop_animation_controller_factory_unittest.cc

Issue 1390113006: Added material design mouse hover feedback support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed the InkDropAnimationControllerImpl to destroy its timer when not running. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/test/test_mock_time_task_runner.h"
8 #include "base/test/test_simple_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "base/timer/timer.h"
7 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/base/material_design/material_design_controller.h" 12 #include "ui/base/material_design/material_design_controller.h"
9 #include "ui/base/test/material_design_controller_test_api.h" 13 #include "ui/base/test/material_design_controller_test_api.h"
10 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
11 #include "ui/views/animation/ink_drop_animation_controller.h" 15 #include "ui/views/animation/ink_drop_animation_controller.h"
12 #include "ui/views/animation/ink_drop_animation_controller_factory.h" 16 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
17 #include "ui/views/animation/ink_drop_animation_controller_impl.h"
13 #include "ui/views/animation/ink_drop_host.h" 18 #include "ui/views/animation/ink_drop_host.h"
14 #include "ui/views/animation/ink_drop_state.h" 19 #include "ui/views/animation/ink_drop_state.h"
15 #include "ui/views/animation/test/test_ink_drop_host.h" 20 #include "ui/views/animation/test/test_ink_drop_host.h"
16 21
17 namespace views { 22 namespace views {
18 23
19 class InkDropAnimationControllerFactoryTest 24 class InkDropAnimationControllerFactoryTest
20 : public testing::TestWithParam<ui::MaterialDesignController::Mode> { 25 : public testing::TestWithParam<
26 testing::tuple<ui::MaterialDesignController::Mode>> {
21 public: 27 public:
22 InkDropAnimationControllerFactoryTest(); 28 InkDropAnimationControllerFactoryTest();
23 ~InkDropAnimationControllerFactoryTest(); 29 ~InkDropAnimationControllerFactoryTest();
24 30
25 protected: 31 protected:
26 // A dummy InkDropHost required to create an InkDropAnimationController. 32 // A dummy InkDropHost required to create an InkDropAnimationController.
27 TestInkDropHost test_ink_drop_host_; 33 TestInkDropHost test_ink_drop_host_;
28 34
29 // The InkDropAnimationController returned by the 35 // The InkDropAnimationController returned by the
30 // InkDropAnimationControllerFactory test target. 36 // InkDropAnimationControllerFactory test target.
31 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_; 37 scoped_ptr<InkDropAnimationController> ink_drop_animation_controller_;
32 38
33 private: 39 private:
40 // Extracts and returns the material design mode from the test parameters.
41 ui::MaterialDesignController::Mode GetMaterialMode() const;
42
34 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; 43 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
35 44
45 // Required by base::Timer's.
46 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
47
36 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); 48 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest);
37 }; 49 };
38 50
39 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest() 51 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest()
40 : ink_drop_animation_controller_(nullptr) { 52 : ink_drop_animation_controller_(nullptr) {
41 // Any call by a previous test to MaterialDesignController::GetMode() will 53 // Any call by a previous test to MaterialDesignController::GetMode() will
42 // initialize and cache the mode. This ensures that these tests will run from 54 // initialize and cache the mode. This ensures that these tests will run from
43 // a non-initialized state. 55 // a non-initialized state.
44 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); 56 ui::test::MaterialDesignControllerTestAPI::UninitializeMode();
45 ui::test::MaterialDesignControllerTestAPI::SetMode(GetParam()); 57 ui::test::MaterialDesignControllerTestAPI::SetMode(GetMaterialMode());
46 ink_drop_animation_controller_.reset( 58 ink_drop_animation_controller_.reset(
47 InkDropAnimationControllerFactory::CreateInkDropAnimationController( 59 InkDropAnimationControllerFactory::CreateInkDropAnimationController(
48 &test_ink_drop_host_) 60 &test_ink_drop_host_)
49 .release()); 61 .release());
50 ink_drop_animation_controller_->SetInkDropSize(gfx::Size(10, 10), 4, 62 ink_drop_animation_controller_->SetInkDropSize(gfx::Size(10, 10), 4,
51 gfx::Size(8, 8), 2); 63 gfx::Size(8, 8), 2);
52 64
53 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 65 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
54 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 66 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
67
68 switch (GetMaterialMode()) {
69 case ui::MaterialDesignController::NON_MATERIAL:
70 break;
71 case ui::MaterialDesignController::MATERIAL_NORMAL:
72 case ui::MaterialDesignController::MATERIAL_HYBRID:
73 // The Timer's used by the InkDropAnimationControllerImpl class require a
74 // base::ThreadTaskRunnerHandle instance.
75 scoped_refptr<base::TestMockTimeTaskRunner> task_runner(
76 new base::TestMockTimeTaskRunner);
77 thread_task_runner_handle_.reset(
78 new base::ThreadTaskRunnerHandle(task_runner));
79 break;
80 }
55 } 81 }
56 82
57 InkDropAnimationControllerFactoryTest:: 83 InkDropAnimationControllerFactoryTest::
58 ~InkDropAnimationControllerFactoryTest() { 84 ~InkDropAnimationControllerFactoryTest() {
59 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); 85 ui::test::MaterialDesignControllerTestAPI::UninitializeMode();
60 } 86 }
61 87
88 ui::MaterialDesignController::Mode
89 InkDropAnimationControllerFactoryTest::GetMaterialMode() const {
90 return testing::get<0>(GetParam());
91 }
92
62 // Note: First argument is optional and intentionally left blank. 93 // Note: First argument is optional and intentionally left blank.
63 // (it's a prefix for the generated test cases) 94 // (it's a prefix for the generated test cases)
64 INSTANTIATE_TEST_CASE_P( 95 INSTANTIATE_TEST_CASE_P(
65 , 96 ,
66 InkDropAnimationControllerFactoryTest, 97 InkDropAnimationControllerFactoryTest,
67 testing::Values(ui::MaterialDesignController::NON_MATERIAL, 98 testing::Values(ui::MaterialDesignController::NON_MATERIAL,
68 ui::MaterialDesignController::MATERIAL_NORMAL)); 99 ui::MaterialDesignController::MATERIAL_NORMAL,
100 ui::MaterialDesignController::MATERIAL_HYBRID));
69 101
70 TEST_P(InkDropAnimationControllerFactoryTest, 102 TEST_P(InkDropAnimationControllerFactoryTest,
71 VerifyAllInkDropLayersRemovedAfterDestruction) { 103 VerifyAllInkDropLayersRemovedAfterDestruction) {
72 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); 104 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
73 ink_drop_animation_controller_.reset(); 105 ink_drop_animation_controller_.reset();
74 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); 106 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers());
75 } 107 }
76 108
77 TEST_P(InkDropAnimationControllerFactoryTest, StateIsHiddenInitially) { 109 TEST_P(InkDropAnimationControllerFactoryTest, StateIsHiddenInitially) {
78 EXPECT_EQ(InkDropState::HIDDEN, 110 EXPECT_EQ(InkDropState::HIDDEN,
79 ink_drop_animation_controller_->GetInkDropState()); 111 ink_drop_animation_controller_->GetInkDropState());
80 } 112 }
81 113
114 TEST_P(InkDropAnimationControllerFactoryTest, HoveredStateAfterAnimateToState) {
115 ink_drop_animation_controller_->SetHovered(true);
116 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
117
118 EXPECT_FALSE(ink_drop_animation_controller_->IsHovered());
119 }
120
82 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickAction) { 121 TEST_P(InkDropAnimationControllerFactoryTest, TypicalQuickAction) {
83 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); 122 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
84 ink_drop_animation_controller_->AnimateToState(InkDropState::QUICK_ACTION); 123 ink_drop_animation_controller_->AnimateToState(InkDropState::QUICK_ACTION);
85 EXPECT_EQ(InkDropState::HIDDEN, 124 EXPECT_EQ(InkDropState::HIDDEN,
86 ink_drop_animation_controller_->GetInkDropState()); 125 ink_drop_animation_controller_->GetInkDropState());
87 } 126 }
88 127
89 TEST_P(InkDropAnimationControllerFactoryTest, CancelQuickAction) { 128 TEST_P(InkDropAnimationControllerFactoryTest, CancelQuickAction) {
90 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); 129 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
91 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN); 130 ink_drop_animation_controller_->AnimateToState(InkDropState::HIDDEN);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); 162 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
124 ink_drop_animation_controller_->AnimateToState( 163 ink_drop_animation_controller_->AnimateToState(
125 InkDropState::SLOW_ACTION_PENDING); 164 InkDropState::SLOW_ACTION_PENDING);
126 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); 165 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED);
127 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); 166 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED);
128 EXPECT_EQ(InkDropState::HIDDEN, 167 EXPECT_EQ(InkDropState::HIDDEN,
129 ink_drop_animation_controller_->GetInkDropState()); 168 ink_drop_animation_controller_->GetInkDropState());
130 } 169 }
131 170
132 } // namespace views 171 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_animation_controller_factory.cc ('k') | ui/views/animation/ink_drop_animation_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698