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

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

Issue 2067013002: Removed InkDropFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed views:: -> ui:: compile error. Created 4 years, 6 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
« no previous file with comments | « ui/views/animation/ink_drop_factory.cc ('k') | ui/views/animation/ink_drop_host_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "ui/views/animation/ink_drop_factory.h"
6
7 #include <memory>
8
9 #include "base/macros.h"
10 #include "base/test/test_mock_time_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/timer/timer.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/base/test/material_design_controller_test_api.h"
16 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
17 #include "ui/views/animation/ink_drop.h"
18 #include "ui/views/animation/ink_drop_host.h"
19 #include "ui/views/animation/ink_drop_impl.h"
20 #include "ui/views/animation/ink_drop_state.h"
21 #include "ui/views/animation/test/test_ink_drop_host.h"
22
23 namespace views {
24
25 class InkDropFactoryTest
26 : public testing::TestWithParam<
27 testing::tuple<ui::MaterialDesignController::Mode>> {
28 public:
29 InkDropFactoryTest();
30 ~InkDropFactoryTest();
31
32 protected:
33 // A dummy InkDropHost required to create an InkDrop.
34 TestInkDropHost test_ink_drop_host_;
35
36 // The InkDrop returned by the InkDropFactory test target.
37 std::unique_ptr<InkDrop> ink_drop_;
38
39 private:
40 // Extracts and returns the material design mode from the test parameters.
41 ui::MaterialDesignController::Mode GetMaterialMode() const;
42
43 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
44
45 // Required by base::Timer's.
46 std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
47
48 std::unique_ptr<ui::test::MaterialDesignControllerTestAPI>
49 material_design_state_;
50
51 DISALLOW_COPY_AND_ASSIGN(InkDropFactoryTest);
52 };
53
54 InkDropFactoryTest::InkDropFactoryTest() : ink_drop_(nullptr) {
55 // Any call by a previous test to MaterialDesignController::GetMode() will
56 // initialize and cache the mode. This ensures that these tests will run from
57 // a non-initialized state.
58 material_design_state_.reset(
59 new ui::test::MaterialDesignControllerTestAPI(GetMaterialMode()));
60 ink_drop_.reset(
61 InkDropFactory::CreateInkDrop(&test_ink_drop_host_).release());
62
63 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
64 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
65
66 switch (GetMaterialMode()) {
67 case ui::MaterialDesignController::NON_MATERIAL:
68 break;
69 case ui::MaterialDesignController::MATERIAL_NORMAL:
70 case ui::MaterialDesignController::MATERIAL_HYBRID:
71 // The Timer's used by the InkDropImpl class require a
72 // base::ThreadTaskRunnerHandle instance.
73 scoped_refptr<base::TestMockTimeTaskRunner> task_runner(
74 new base::TestMockTimeTaskRunner);
75 thread_task_runner_handle_.reset(
76 new base::ThreadTaskRunnerHandle(task_runner));
77 break;
78 }
79 }
80
81 InkDropFactoryTest::~InkDropFactoryTest() {
82 material_design_state_.reset();
83 }
84
85 ui::MaterialDesignController::Mode InkDropFactoryTest::GetMaterialMode() const {
86 return testing::get<0>(GetParam());
87 }
88
89 // Note: First argument is optional and intentionally left blank.
90 // (it's a prefix for the generated test cases)
91 INSTANTIATE_TEST_CASE_P(
92 ,
93 InkDropFactoryTest,
94 testing::Values(ui::MaterialDesignController::NON_MATERIAL,
95 ui::MaterialDesignController::MATERIAL_NORMAL,
96 ui::MaterialDesignController::MATERIAL_HYBRID));
97
98 TEST_P(InkDropFactoryTest,
99 VerifyInkDropLayersRemovedAfterDestructionWhenRippleIsActive) {
100 ink_drop_->AnimateToState(InkDropState::ACTION_PENDING);
101 ink_drop_.reset();
102 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers());
103 }
104
105 TEST_P(InkDropFactoryTest,
106 VerifyInkDropLayersRemovedAfterDestructionWhenHoverIsActive) {
107 test_ink_drop_host_.set_should_show_highlight(true);
108 ink_drop_->SetHovered(true);
109 ink_drop_.reset();
110 EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers());
111 }
112
113 TEST_P(InkDropFactoryTest, StateIsHiddenInitially) {
114 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState());
115 }
116
117 TEST_P(InkDropFactoryTest, TypicalQuickAction) {
118 ink_drop_->AnimateToState(InkDropState::ACTION_PENDING);
119 ink_drop_->AnimateToState(InkDropState::ACTION_TRIGGERED);
120 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState());
121 }
122
123 TEST_P(InkDropFactoryTest, CancelQuickAction) {
124 ink_drop_->AnimateToState(InkDropState::ACTION_PENDING);
125 ink_drop_->AnimateToState(InkDropState::HIDDEN);
126 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState());
127 }
128
129 TEST_P(InkDropFactoryTest, TypicalSlowAction) {
130 ink_drop_->AnimateToState(InkDropState::ACTION_PENDING);
131 ink_drop_->AnimateToState(InkDropState::ALTERNATE_ACTION_PENDING);
132 ink_drop_->AnimateToState(InkDropState::ALTERNATE_ACTION_TRIGGERED);
133 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState());
134 }
135
136 TEST_P(InkDropFactoryTest, CancelSlowAction) {
137 ink_drop_->AnimateToState(InkDropState::ACTION_PENDING);
138 ink_drop_->AnimateToState(InkDropState::ALTERNATE_ACTION_PENDING);
139 ink_drop_->AnimateToState(InkDropState::HIDDEN);
140 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState());
141 }
142
143 TEST_P(InkDropFactoryTest, TypicalQuickActivated) {
144 ink_drop_->AnimateToState(InkDropState::ACTION_PENDING);
145 ink_drop_->AnimateToState(InkDropState::ACTIVATED);
146 ink_drop_->AnimateToState(InkDropState::DEACTIVATED);
147 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState());
148 }
149
150 TEST_P(InkDropFactoryTest, TypicalSlowActivated) {
151 ink_drop_->AnimateToState(InkDropState::ACTION_PENDING);
152 ink_drop_->AnimateToState(InkDropState::ALTERNATE_ACTION_PENDING);
153 ink_drop_->AnimateToState(InkDropState::ACTIVATED);
154 ink_drop_->AnimateToState(InkDropState::DEACTIVATED);
155 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState());
156 }
157
158 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_factory.cc ('k') | ui/views/animation/ink_drop_host_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698