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_animation_controller_impl_unittest.cc

Issue 1944043002: Enabled tests to control material design ink drop animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Replaced unique_ptr with scoped_ptr. Created 4 years, 7 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 "ui/views/animation/ink_drop_animation_controller_impl.h" 5 #include "ui/views/animation/ink_drop_animation_controller_impl.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 11 #include "ui/views/animation/ink_drop_animation.h"
12 #include "ui/views/animation/test/ink_drop_animation_controller_impl_test_api.h"
12 #include "ui/views/animation/test/test_ink_drop_host.h" 13 #include "ui/views/animation/test/test_ink_drop_host.h"
13 14
14 namespace views { 15 namespace views {
15 16
16 // NOTE: The InkDropAnimationControllerImpl class is also tested by the 17 // NOTE: The InkDropAnimationControllerImpl class is also tested by the
17 // InkDropAnimationControllerFactoryTest tests. 18 // InkDropAnimationControllerFactoryTest tests.
18 class InkDropAnimationControllerImplTest : public testing::Test { 19 class InkDropAnimationControllerImplTest : public testing::Test {
19 public: 20 public:
20 InkDropAnimationControllerImplTest(); 21 InkDropAnimationControllerImplTest();
21 ~InkDropAnimationControllerImplTest() override; 22 ~InkDropAnimationControllerImplTest() override;
22 23
23 protected: 24 protected:
24 TestInkDropHost ink_drop_host_; 25 TestInkDropHost ink_drop_host_;
25 26
26 bool is_hover_fading_in_or_visible() {
27 return ink_drop_animation_controller_.IsHoverFadingInOrVisible();
28 }
29
30 const InkDropHover* hover() const {
31 return ink_drop_animation_controller_.hover_.get();
32 }
33
34 // The test target. 27 // The test target.
35 InkDropAnimationControllerImpl ink_drop_animation_controller_; 28 InkDropAnimationControllerImpl ink_drop_animation_controller_;
36 29
30 // Allows privileged access to the the |ink_drop_hover_|.
31 test::InkDropAnimationControllerImplTestApi test_api_;
32
37 // Used to control the tasks scheduled by the InkDropAnimationControllerImpl's 33 // Used to control the tasks scheduled by the InkDropAnimationControllerImpl's
38 // Timer. 34 // Timer.
39 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 35 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
40 36
41 // Required by base::Timer's. 37 // Required by base::Timer's.
42 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; 38 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
43 39
44 private: 40 private:
45 // Ensures all animations complete immediately.
46 scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
47
48 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerImplTest); 41 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerImplTest);
49 }; 42 };
50 43
51 InkDropAnimationControllerImplTest::InkDropAnimationControllerImplTest() 44 InkDropAnimationControllerImplTest::InkDropAnimationControllerImplTest()
52 : ink_drop_animation_controller_(&ink_drop_host_), 45 : ink_drop_animation_controller_(&ink_drop_host_),
46 test_api_(&ink_drop_animation_controller_),
53 task_runner_(new base::TestSimpleTaskRunner), 47 task_runner_(new base::TestSimpleTaskRunner),
54 thread_task_runner_handle_( 48 thread_task_runner_handle_(
55 new base::ThreadTaskRunnerHandle(task_runner_)) { 49 new base::ThreadTaskRunnerHandle(task_runner_)) {
56 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 50 ink_drop_host_.set_disable_timers_for_test(true);
57 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
58 } 51 }
59 52
60 InkDropAnimationControllerImplTest::~InkDropAnimationControllerImplTest() {} 53 InkDropAnimationControllerImplTest::~InkDropAnimationControllerImplTest() {}
61 54
62 TEST_F(InkDropAnimationControllerImplTest, SetHoveredIsFadingInOrVisible) { 55 TEST_F(InkDropAnimationControllerImplTest, SetHoveredIsFadingInOrVisible) {
63 ink_drop_host_.set_should_show_hover(true); 56 ink_drop_host_.set_should_show_hover(true);
64 57
65 ink_drop_animation_controller_.SetHovered(true); 58 ink_drop_animation_controller_.SetHovered(true);
66 EXPECT_TRUE(is_hover_fading_in_or_visible()); 59 EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
60
61 test_api_.CompleteAnimations();
67 62
68 ink_drop_animation_controller_.SetHovered(false); 63 ink_drop_animation_controller_.SetHovered(false);
69 EXPECT_FALSE(is_hover_fading_in_or_visible()); 64 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
70 } 65 }
71 66
72 TEST_F(InkDropAnimationControllerImplTest, 67 TEST_F(InkDropAnimationControllerImplTest,
73 HoverDoesntFadeInAfterAnimationIfHoverNotSet) { 68 HoverDoesntFadeInAfterAnimationIfHoverNotSet) {
74 ink_drop_host_.set_should_show_hover(true); 69 ink_drop_host_.set_should_show_hover(true);
75 ink_drop_animation_controller_.SetHovered(false); 70 ink_drop_animation_controller_.SetHovered(false);
76 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED); 71 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED);
72 test_api_.CompleteAnimations();
77 73
78 EXPECT_FALSE(task_runner_->HasPendingTask()); 74 EXPECT_FALSE(task_runner_->HasPendingTask());
79 EXPECT_FALSE(is_hover_fading_in_or_visible()); 75 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
80 } 76 }
81 77
82 TEST_F(InkDropAnimationControllerImplTest, 78 TEST_F(InkDropAnimationControllerImplTest,
83 HoverFadesInAfterAnimationWhenHostIsHovered) { 79 HoverFadesInAfterAnimationWhenHostIsHovered) {
84 ink_drop_host_.set_should_show_hover(true); 80 ink_drop_host_.set_should_show_hover(true);
85 ink_drop_animation_controller_.SetHovered(true); 81 ink_drop_animation_controller_.SetHovered(true);
86 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED); 82 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED);
83 test_api_.CompleteAnimations();
87 84
88 EXPECT_TRUE(task_runner_->HasPendingTask()); 85 EXPECT_TRUE(task_runner_->HasPendingTask());
89 86
90 task_runner_->RunPendingTasks(); 87 task_runner_->RunPendingTasks();
91 88
92 EXPECT_TRUE(is_hover_fading_in_or_visible()); 89 EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
93 } 90 }
94 91
95 TEST_F(InkDropAnimationControllerImplTest, 92 TEST_F(InkDropAnimationControllerImplTest,
96 HoverDoesntFadeInAfterAnimationWhenHostIsNotHovered) { 93 HoverDoesntFadeInAfterAnimationWhenHostIsNotHovered) {
97 ink_drop_host_.set_should_show_hover(false); 94 ink_drop_host_.set_should_show_hover(false);
98 ink_drop_animation_controller_.SetHovered(true); 95 ink_drop_animation_controller_.SetHovered(true);
99 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED); 96 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED);
97 test_api_.CompleteAnimations();
100 98
101 EXPECT_TRUE(task_runner_->HasPendingTask()); 99 EXPECT_TRUE(task_runner_->HasPendingTask());
102 100
103 task_runner_->RunPendingTasks(); 101 task_runner_->RunPendingTasks();
104 102
105 EXPECT_FALSE(is_hover_fading_in_or_visible()); 103 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
106 } 104 }
107 105
108 TEST_F(InkDropAnimationControllerImplTest, 106 TEST_F(InkDropAnimationControllerImplTest,
109 HoveredStateNotVisibleOrFadingInAfterAnimateToState) { 107 HoveredStateNotVisibleOrFadingInAfterAnimateToState) {
110 ink_drop_host_.set_should_show_hover(true); 108 ink_drop_host_.set_should_show_hover(true);
111 109
112 ink_drop_animation_controller_.SetHovered(true); 110 ink_drop_animation_controller_.SetHovered(true);
113 EXPECT_TRUE(is_hover_fading_in_or_visible()); 111 test_api_.CompleteAnimations();
112 EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
114 113
115 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED); 114 ink_drop_animation_controller_.AnimateToState(InkDropState::ACTION_TRIGGERED);
116 EXPECT_FALSE(is_hover_fading_in_or_visible()); 115 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
117 } 116 }
118 117
119 // Verifies that there is not a crash when setting hovered state and the host 118 // Verifies that there is not a crash when setting hovered state and the host
120 // returns null for the hover. 119 // returns null for the hover.
121 TEST_F(InkDropAnimationControllerImplTest, 120 TEST_F(InkDropAnimationControllerImplTest,
122 SetHoveredFalseWorksWhenNoInkDropHoverExists) { 121 SetHoveredFalseWorksWhenNoInkDropHoverExists) {
123 ink_drop_host_.set_should_show_hover(false); 122 ink_drop_host_.set_should_show_hover(false);
124 ink_drop_animation_controller_.SetHovered(true); 123 ink_drop_animation_controller_.SetHovered(true);
125 EXPECT_FALSE(hover()); 124 EXPECT_FALSE(test_api_.hover());
126 ink_drop_animation_controller_.SetHovered(false); 125 ink_drop_animation_controller_.SetHovered(false);
127 EXPECT_FALSE(hover()); 126 EXPECT_FALSE(test_api_.hover());
128 } 127 }
129 128
130 TEST_F(InkDropAnimationControllerImplTest, HoverFadesOutOnSnapToActivated) { 129 TEST_F(InkDropAnimationControllerImplTest, HoverFadesOutOnSnapToActivated) {
131 ink_drop_host_.set_should_show_hover(true); 130 ink_drop_host_.set_should_show_hover(true);
132 ink_drop_animation_controller_.SetHovered(true); 131 ink_drop_animation_controller_.SetHovered(true);
132 test_api_.CompleteAnimations();
133 133
134 EXPECT_TRUE(is_hover_fading_in_or_visible()); 134 EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
135 135
136 ink_drop_animation_controller_.SnapToActivated(); 136 ink_drop_animation_controller_.SnapToActivated();
137 137
138 EXPECT_FALSE(is_hover_fading_in_or_visible()); 138 EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
139 } 139 }
140 140
141 } // namespace views 141 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_animation_controller_impl.h ('k') | ui/views/animation/ink_drop_hover.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698