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

Side by Side Diff: content/browser/web_contents/aura/overscroll_window_animation_unittest.cc

Issue 895543005: Refactor GestureNavigation to eliminate code redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits Created 5 years, 8 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
(Empty)
1 // Copyright (c) 2013 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 "content/browser/web_contents/aura/overscroll_window_animation.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/window.h"
10 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
11 #include "ui/compositor/scoped_layer_animation_settings.h"
12 #include "ui/compositor/test/layer_animator_test_controller.h"
13 #include "ui/gfx/frame_time.h"
14
15 namespace content {
16
17 class OverscrollWindowAnimationTest
18 : public OverscrollWindowAnimation::Delegate,
19 public aura::test::AuraTestBase {
20 public:
21 OverscrollWindowAnimationTest()
22 : create_window_(true),
23 overscroll_started_(false),
24 overscroll_completing_(false),
25 overscroll_completed_(false),
26 overscroll_aborted_(false),
27 main_window_(nullptr) {}
28
29 ~OverscrollWindowAnimationTest() override {}
30
31 OverscrollWindowAnimation* owa() { return owa_.get(); }
32
33 // Set to true to return a window in the Create*Window functions, false to
34 // return null.
35 void set_create_window(bool create_window) { create_window_ = create_window; }
36
37 // The following functions indicate if the events have been called on this
38 // delegate.
39 bool overscroll_started() { return overscroll_started_; }
40 bool overscroll_completing() { return overscroll_completing_; }
41 bool overscroll_completed() { return overscroll_completed_; }
42 bool overscroll_aborted() { return overscroll_aborted_; }
43
44 void ResetFlags() {
45 overscroll_started_ = false;
46 overscroll_completing_ = false;
47 overscroll_completed_ = false;
48 overscroll_aborted_ = false;
49 }
50
51 protected:
52 // aura::test::AuraTestBase:
53 void SetUp() override {
54 aura::test::AuraTestBase::SetUp();
55 main_window_.reset(CreateNormalWindow(0, root_window(), nullptr));
56 ResetFlags();
57 create_window_ = true;
58 last_window_id_ = 0;
59 owa_.reset(new OverscrollWindowAnimation(this));
60 }
61
62 void TearDown() override {
63 owa_.reset();
64 main_window_.reset();
65 aura::test::AuraTestBase::TearDown();
66 }
67
68 // OverscrollWindowAnimation::Delegate:
69 scoped_ptr<aura::Window> CreateFrontWindow() override {
70 return CreateSlideWindow();
71 }
72
73 scoped_ptr<aura::Window> CreateBackWindow() override {
74 return CreateSlideWindow();
75 }
76
77 aura::Window* GetMainWindow() const override { return main_window_.get(); }
78
79 void OnOverscrollCompleting() override { overscroll_completing_ = true; }
80
81 void OnOverscrollCompleted(scoped_ptr<aura::Window> window) override {
82 overscroll_completed_ = true;
83 }
84
85 void OnOverscrollCancelled() override { overscroll_aborted_ = true; }
86
87 private:
88 // The overscroll window animation under test.
89 scoped_ptr<OverscrollWindowAnimation> owa_;
90
91 scoped_ptr<aura::Window> CreateSlideWindow() {
92 overscroll_started_ = true;
93 if (create_window_) {
94 return scoped_ptr<aura::Window>(
95 CreateNormalWindow(++last_window_id_, root_window(), nullptr));
96 }
97 return nullptr;
98 }
99
100 // Controls if we return a window for the window creation callbacks or not.
101 bool create_window_;
102
103 // State flags.
104 bool overscroll_started_;
105 bool overscroll_completing_;
106 bool overscroll_completed_;
107 bool overscroll_aborted_;
108
109 int last_window_id_;
110
111 // The dummy target window we provide.
112 scoped_ptr<aura::Window> main_window_;
113
114 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowAnimationTest);
115 };
116
117 // Tests a simple overscroll gesture.
118 TEST_F(OverscrollWindowAnimationTest, BasicOverscroll) {
119 EXPECT_FALSE(owa()->is_active());
120 EXPECT_FALSE(overscroll_started());
121 EXPECT_FALSE(overscroll_completing());
122 EXPECT_FALSE(overscroll_completed());
123 EXPECT_FALSE(overscroll_aborted());
124
125 // Start an OVERSCROLL_EAST gesture.
126 owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
127 EXPECT_TRUE(owa()->is_active());
128 EXPECT_TRUE(overscroll_started());
129 EXPECT_FALSE(overscroll_completing());
130 EXPECT_FALSE(overscroll_completed());
131 EXPECT_FALSE(overscroll_aborted());
132
133 // Complete the overscroll.
134 owa()->OnOverscrollComplete(OVERSCROLL_EAST);
135 EXPECT_FALSE(owa()->is_active());
136 EXPECT_TRUE(overscroll_started());
137 EXPECT_TRUE(overscroll_completing());
138 EXPECT_TRUE(overscroll_completed());
139 EXPECT_FALSE(overscroll_aborted());
140 }
141
142 // Tests aborting an overscroll gesture.
143 TEST_F(OverscrollWindowAnimationTest, BasicAbort) {
144 // Start an OVERSCROLL_EAST gesture.
145 owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
146 // Abort the overscroll.
147 owa()->OnOverscrollModeChange(OVERSCROLL_EAST, OVERSCROLL_NONE);
148 EXPECT_FALSE(owa()->is_active());
149 EXPECT_TRUE(overscroll_started());
150 EXPECT_FALSE(overscroll_completing());
151 EXPECT_FALSE(overscroll_completed());
152 EXPECT_TRUE(overscroll_aborted());
153 }
154
155 // Tests starting an overscroll gesture when the slide window cannot be created.
156 TEST_F(OverscrollWindowAnimationTest, BasicCannotNavigate) {
157 set_create_window(false);
158 // Start an OVERSCROLL_EAST gesture.
159 owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
160 EXPECT_FALSE(owa()->is_active());
161 EXPECT_TRUE(overscroll_started());
162 EXPECT_FALSE(overscroll_completing());
163 EXPECT_FALSE(overscroll_completed());
164 EXPECT_FALSE(overscroll_aborted());
165 }
166
167 // Tests starting an overscroll gesture while another one was in progress
168 // completes the first one.
169 TEST_F(OverscrollWindowAnimationTest, NewOverscrollCompletesPreviousGesture) {
170 // This test requires a normal animation duration so that
171 // OnImplicitAnimationsCancelled is not called as soon as the first overscroll
172 // finishes.
173 ui::ScopedAnimationDurationScaleMode normal_duration(
174 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
175 ui::LayerAnimator* animator = GetMainWindow()->layer()->GetAnimator();
176 ui::ScopedLayerAnimationSettings settings(animator);
177 animator->set_disable_timer_for_test(true);
178 ui::LayerAnimatorTestController test_controller(animator);
179 // Start an OVERSCROLL_EAST gesture.
180 owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
181
182 // Finishes the OVERSCROLL_EAST gesture. At this point the window should be
183 // being animated to its final position.
184 owa()->OnOverscrollComplete(OVERSCROLL_EAST);
185 EXPECT_TRUE(owa()->is_active());
186 EXPECT_TRUE(overscroll_started());
187 EXPECT_TRUE(overscroll_completing());
188 EXPECT_FALSE(overscroll_completed());
189 EXPECT_FALSE(overscroll_aborted());
190
191 // Start another OVERSCROLL_EAST gesture.
192 owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
193 EXPECT_TRUE(owa()->is_active());
194 EXPECT_TRUE(overscroll_started());
195 EXPECT_TRUE(overscroll_completing());
196 EXPECT_TRUE(overscroll_completed());
197 EXPECT_FALSE(overscroll_aborted());
198
199 // Complete the overscroll gesture.
200 ResetFlags();
201 owa()->OnOverscrollComplete(OVERSCROLL_EAST);
202
203 base::TimeDelta duration = settings.GetTransitionDuration();
204 test_controller.StartThreadedAnimationsIfNeeded();
205 base::TimeTicks start_time = gfx::FrameTime::Now();
206
207 // Halfway through the animation, OverscrollCompleting should have been fired.
208 animator->Step(start_time + duration / 2);
209 EXPECT_TRUE(owa()->is_active());
210 EXPECT_FALSE(overscroll_started());
211 EXPECT_TRUE(overscroll_completing());
212 EXPECT_FALSE(overscroll_completed());
213 EXPECT_FALSE(overscroll_aborted());
214
215 // The animation has finished, OverscrollCompleted should have been fired.
216 animator->Step(start_time + duration);
217 EXPECT_FALSE(owa()->is_active());
218 EXPECT_FALSE(overscroll_started());
219 EXPECT_TRUE(overscroll_completing());
220 EXPECT_TRUE(overscroll_completed());
221 EXPECT_FALSE(overscroll_aborted());
222 }
223
224 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698