blob: 25c2a238593ddcb79d13de0c04d25833a7ed570e [file] [log] [blame]
Mohsen Izadi9830436c2017-12-21 18:02:461// Copyright 2017 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/renderer_host/overscroll_controller.h"
6
7#include <memory>
8
9#include "base/containers/queue.h"
chaopengcd44c7622018-04-13 04:08:2110#include "base/test/scoped_feature_list.h"
Mohsen Izadi9830436c2017-12-21 18:02:4611#include "content/browser/renderer_host/overscroll_controller_delegate.h"
12#include "content/common/input/synthetic_web_input_event_builders.h"
chaopengcd44c7622018-04-13 04:08:2113#include "content/public/browser/overscroll_configuration.h"
14#include "content/public/common/content_features.h"
Mohsen Izadi8c59ba52018-04-12 18:52:0115#include "content/public/test/scoped_overscroll_modes.h"
Mohsen Izadi9830436c2017-12-21 18:02:4616#include "content/test/test_overscroll_delegate.h"
17#include "testing/gtest/include/gtest/gtest.h"
Blink Reformata30d4232018-04-07 15:31:0618#include "third_party/blink/public/platform/web_input_event.h"
Mohsen Izadi9830436c2017-12-21 18:02:4619
20namespace content {
21
22class OverscrollControllerTest : public ::testing::Test {
23 protected:
24 OverscrollControllerTest() {}
25 ~OverscrollControllerTest() override {}
26
27 void SetUp() override {
chaopengcd44c7622018-04-13 04:08:2128 OverscrollConfig::ResetTouchpadOverscrollHistoryNavigationEnabled();
29 scoped_feature_list_.InitAndEnableFeature(
30 features::kTouchpadOverscrollHistoryNavigation);
Mohsen Izadi9830436c2017-12-21 18:02:4631 delegate_ = std::make_unique<TestOverscrollDelegate>(gfx::Size(400, 300));
32 controller_ = std::make_unique<OverscrollController>();
33 controller_->set_delegate(delegate_.get());
34 }
35
36 void TearDown() override {
37 controller_ = nullptr;
38 delegate_ = nullptr;
39 }
40
41 // Creates and sends a mouse-wheel event to the overscroll controller. Returns
42 // |true| if the event is consumed by the overscroll controller.
43 bool SimulateMouseWheel(float dx, float dy) {
44 DCHECK(!current_event_);
45 current_event_ = std::make_unique<blink::WebMouseWheelEvent>(
46 SyntheticWebMouseWheelEventBuilder::Build(0, 0, dx, dy, 0, true));
47 return controller_->WillHandleEvent(*current_event_);
48 }
49
chaopeng1d469b02018-04-05 15:41:0750 // Creates and sends a gesture event to the overscroll controller. Returns
51 // |true| if the event is consumed by the overscroll controller.
52 bool SimulateGestureEvent(blink::WebInputEvent::Type type,
Mohsen Izadi5a6583512018-04-23 18:31:1953 blink::WebGestureDevice source_device,
Daniel Cheng224569ee2018-04-25 05:45:0654 base::TimeTicks timestamp) {
chaopeng1d469b02018-04-05 15:41:0755 DCHECK(!current_event_);
56 current_event_ = std::make_unique<blink::WebGestureEvent>(
57 SyntheticWebGestureEventBuilder::Build(type, source_device));
Daniel Cheng224569ee2018-04-25 05:45:0658 current_event_->SetTimeStamp(timestamp);
chaopeng1d469b02018-04-05 15:41:0759 return controller_->WillHandleEvent(*current_event_);
60 }
61
Mohsen Izadi9830436c2017-12-21 18:02:4662 // Creates and sends a gesture-scroll-update event to the overscroll
63 // controller. Returns |true| if the event is consumed by the overscroll
64 // controller.
65 bool SimulateGestureScrollUpdate(float dx,
66 float dy,
chaopeng1d469b02018-04-05 15:41:0767 blink::WebGestureDevice device,
Daniel Cheng224569ee2018-04-25 05:45:0668 base::TimeTicks timestamp,
chaopeng1d469b02018-04-05 15:41:0769 bool inertial_update) {
Mohsen Izadi9830436c2017-12-21 18:02:4670 DCHECK(!current_event_);
chaopeng1d469b02018-04-05 15:41:0771 auto event = std::make_unique<blink::WebGestureEvent>(
Mohsen Izadi9830436c2017-12-21 18:02:4672 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dx, dy, 0, device));
Daniel Cheng224569ee2018-04-25 05:45:0673 event->SetTimeStamp(timestamp);
chaopeng1d469b02018-04-05 15:41:0774 if (inertial_update) {
75 event->data.scroll_update.inertial_phase =
76 blink::WebGestureEvent::kMomentumPhase;
77 }
78 current_event_ = std::move(event);
Mohsen Izadi9830436c2017-12-21 18:02:4679 return controller_->WillHandleEvent(*current_event_);
80 }
81
Mohsen Izadi8c59ba52018-04-12 18:52:0182 // Creates and sends a gesture-fling-start event to the overscroll controller.
83 // Returns |true| if the event is consumed by the overscroll controller.
84 bool SimulateGestureFlingStart(float velocity_x,
85 float velocity_y,
Mohsen Izadi5a6583512018-04-23 18:31:1986 blink::WebGestureDevice device,
Daniel Cheng224569ee2018-04-25 05:45:0687 base::TimeTicks timestamp) {
Mohsen Izadi8c59ba52018-04-12 18:52:0188 DCHECK(!current_event_);
89 current_event_ = std::make_unique<blink::WebGestureEvent>(
90 SyntheticWebGestureEventBuilder::BuildFling(velocity_x, velocity_y,
91 device));
Daniel Cheng224569ee2018-04-25 05:45:0692 current_event_->SetTimeStamp(timestamp);
Mohsen Izadi8c59ba52018-04-12 18:52:0193 return controller_->WillHandleEvent(*current_event_);
94 }
95
Mohsen Izadi9830436c2017-12-21 18:02:4696 // Notifies the overscroll controller that the current event is ACKed.
97 void SimulateAck(bool processed) {
98 DCHECK(current_event_);
99 controller_->ReceivedEventACK(*current_event_, processed);
100 current_event_ = nullptr;
101 }
102
103 TestOverscrollDelegate* delegate() const { return delegate_.get(); }
104
105 OverscrollMode controller_mode() const {
106 return controller_->overscroll_mode_;
107 }
108
109 OverscrollSource controller_source() const {
110 return controller_->overscroll_source_;
111 }
112
113 private:
114 std::unique_ptr<TestOverscrollDelegate> delegate_;
115 std::unique_ptr<OverscrollController> controller_;
116
117 // Keeps track of the last event that has been processed by the overscroll
118 // controller which is not yet ACKed. Will be null if no event is processed or
119 // the last event is ACKed.
120 std::unique_ptr<blink::WebInputEvent> current_event_;
121
chaopengcd44c7622018-04-13 04:08:21122 base::test::ScopedFeatureList scoped_feature_list_;
123
Mohsen Izadi9830436c2017-12-21 18:02:46124 DISALLOW_COPY_AND_ASSIGN(OverscrollControllerTest);
125};
126
127// Tests that if a mouse-wheel is consumed by content before overscroll is
128// initiated, overscroll will not initiate anymore.
129TEST_F(OverscrollControllerTest, MouseWheelConsumedPreventsOverscroll) {
Daniel Cheng224569ee2018-04-25 05:45:06130 const base::TimeTicks timestamp =
131 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19132
Mohsen Izadi9830436c2017-12-21 18:02:46133 // Simulate a mouse-wheel, ACK it as not processed, simulate the corresponding
Mohsen Izadi8c59ba52018-04-12 18:52:01134 // gesture scroll-update event, and ACK it as not processed. Since it is not
Mohsen Izadi9830436c2017-12-21 18:02:46135 // passing the start threshold, no overscroll should happen.
136 EXPECT_FALSE(SimulateMouseWheel(10, 0));
137 SimulateAck(false);
chaopeng1d469b02018-04-05 15:41:07138 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00139 10, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi9830436c2017-12-21 18:02:46140 SimulateAck(false);
141 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
142 EXPECT_EQ(OverscrollSource::NONE, controller_source());
143 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
144 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
145
146 // Simulate a mouse-wheel and ACK it as processed. No gesture scroll-update
147 // needs to be simulated. Still no overscroll.
148 EXPECT_FALSE(SimulateMouseWheel(10, 0));
149 SimulateAck(true);
150 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
151 EXPECT_EQ(OverscrollSource::NONE, controller_source());
152 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
153 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
154
155 // Simulate a mouse-wheel and the corresponding gesture scroll-update both
156 // ACKed as not processed. Although the scroll passes overscroll start
157 // threshold, no overscroll should happen since the previous mouse-wheel was
158 // marked as processed.
159 EXPECT_FALSE(SimulateMouseWheel(100, 0));
160 SimulateAck(false);
chaopeng1d469b02018-04-05 15:41:07161 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00162 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi9830436c2017-12-21 18:02:46163 SimulateAck(false);
164 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
165 EXPECT_EQ(OverscrollSource::NONE, controller_source());
166 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
167 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
168}
169
chaopeng1d469b02018-04-05 15:41:07170// Verifying the inertial scroll event completes overscroll. After that we will
171// ignore the following inertial scroll events until new sequence start.
172TEST_F(OverscrollControllerTest,
173 InertialGestureScrollUpdateCompletesOverscroll) {
Daniel Cheng224569ee2018-04-25 05:45:06174 const base::TimeTicks timestamp =
175 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19176
chaopeng1d469b02018-04-05 15:41:07177 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00178 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19179 timestamp));
chaopeng1d469b02018-04-05 15:41:07180 SimulateAck(false);
181
182 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00183 200, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopeng1d469b02018-04-05 15:41:07184 SimulateAck(false);
185 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
186 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
187 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
188 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
189
190 // Inertial update event complete the overscroll action.
191 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00192 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng1d469b02018-04-05 15:41:07193 SimulateAck(false);
chaopenga7585d792018-04-10 18:02:38194 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
195 EXPECT_EQ(OverscrollSource::NONE, controller_source());
196 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
chaopeng1d469b02018-04-05 15:41:07197 EXPECT_EQ(OVERSCROLL_EAST, delegate()->completed_mode());
198
199 // Next Inertial update event would be consumed by overscroll controller.
200 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00201 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng1d469b02018-04-05 15:41:07202}
203
chaopeng9736c522018-05-08 18:32:27204// Ensure inertial gesture scroll update can not start overscroll.
205TEST_F(OverscrollControllerTest, InertialGSUsDoNotStartOverscroll) {
206 base::TimeTicks timestamp =
207 blink::WebInputEvent::GetStaticTimeStampForTests();
208 // Inertial update event complete the overscroll action.
209 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00210 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27211 SimulateAck(false);
212 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
213 EXPECT_EQ(OverscrollSource::NONE, controller_source());
214 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
215 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
216}
217
218// After 300ms inertial gesture scroll updates, overscroll must get cancelled
219// if not completed.
220TEST_F(OverscrollControllerTest, OnlyProcessLimitedInertialGSUEvents) {
221 base::TimeTicks timestamp =
222 blink::WebInputEvent::GetStaticTimeStampForTests();
223
224 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00225 blink::WebGestureDevice::kTouchpad,
chaopeng9736c522018-05-08 18:32:27226 timestamp));
227 SimulateAck(false);
228
229 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00230 61, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopeng9736c522018-05-08 18:32:27231 SimulateAck(false);
232 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
233 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
234 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
235 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
236
237 // First inertial.
238 timestamp += base::TimeDelta::FromSeconds(1);
239 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00240 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27241 SimulateAck(true);
242 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
243 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
244 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
245 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
246
247 // Not cancel in 10ms.
248 timestamp += base::TimeDelta::FromMilliseconds(10);
249 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00250 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27251 SimulateAck(true);
252 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
253 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
254 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
255 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
256
257 // Cancel after 300ms.
258 timestamp += base::TimeDelta::FromMilliseconds(291);
259 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00260 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27261 SimulateAck(true);
262 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
263 EXPECT_EQ(OverscrollSource::NONE, controller_source());
264 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
265 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
266
267 // Next event should be ignored.
268 timestamp += base::TimeDelta::FromMilliseconds(100);
269 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00270 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27271}
272
Mohsen Izadi8c59ba52018-04-12 18:52:01273// Verifies that when pull-to-refresh is disabled, it is not triggered for
274// neither touchpad nor touchscreen.
275TEST_F(OverscrollControllerTest, PullToRefreshDisabled) {
276 ScopedPullToRefreshMode scoped_mode(
277 OverscrollConfig::PullToRefreshMode::kDisabled);
278
Daniel Cheng224569ee2018-04-25 05:45:06279 base::TimeTicks timestamp =
280 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19281
282 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00283 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19284 timestamp));
285 SimulateAck(false);
286
Mohsen Izadi8c59ba52018-04-12 18:52:01287 // Simulate a touchpad gesture scroll-update event that passes the start
288 // threshold and ACK it as not processed. Pull-to-refresh should not be
289 // triggered.
290 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00291 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01292 SimulateAck(false);
293 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
294 EXPECT_EQ(OverscrollSource::NONE, controller_source());
295 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
296 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
297
Daniel Cheng224569ee2018-04-25 05:45:06298 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19299
Mohsen Izadi8c59ba52018-04-12 18:52:01300 // Simulate a touchpad zero-velocity fling-start which would normally end
301 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Daniel Cheng7f9ec902019-04-18 05:07:00302 EXPECT_FALSE(SimulateGestureFlingStart(
303 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01304 SimulateAck(false);
305 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
306 EXPECT_EQ(OverscrollSource::NONE, controller_source());
307 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
308 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
309
Daniel Cheng224569ee2018-04-25 05:45:06310 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19311
312 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00313 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19314 timestamp));
315 SimulateAck(false);
316
Mohsen Izadi8c59ba52018-04-12 18:52:01317 // Simulate a touchscreen gesture scroll-update event that passes the start
318 // threshold and ACK it as not processed. Pull-to-refresh should not be
319 // triggered.
320 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00321 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01322 SimulateAck(false);
323 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
324 EXPECT_EQ(OverscrollSource::NONE, controller_source());
325 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
326 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
327
Daniel Cheng224569ee2018-04-25 05:45:06328 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19329
Mohsen Izadi8c59ba52018-04-12 18:52:01330 // Simulate a touchscreen gesture scroll-end which would normally end
331 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
332 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00333 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19334 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01335 SimulateAck(false);
336 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
337 EXPECT_EQ(OverscrollSource::NONE, controller_source());
338 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
339 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
340}
341
342// Verifies that when pull-to-refresh is enabled, it is triggered for both
343// touchpad and touchscreen.
344TEST_F(OverscrollControllerTest, PullToRefreshEnabled) {
345 ScopedPullToRefreshMode scoped_mode(
346 OverscrollConfig::PullToRefreshMode::kEnabled);
347
Daniel Cheng224569ee2018-04-25 05:45:06348 base::TimeTicks timestamp =
349 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19350
351 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00352 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19353 timestamp));
354 SimulateAck(false);
355
Mohsen Izadi8c59ba52018-04-12 18:52:01356 // Simulate a touchpad gesture scroll-update event that passes the start
357 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
358 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00359 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01360 SimulateAck(false);
361 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
362 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
363 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
364 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
365
Daniel Cheng224569ee2018-04-25 05:45:06366 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19367
Mohsen Izadi8c59ba52018-04-12 18:52:01368 // Simulate a touchpad zero-velocity fling-start and ACK it as not processed..
369 // It should abort pull-to-refresh.
Daniel Cheng7f9ec902019-04-18 05:07:00370 EXPECT_FALSE(SimulateGestureFlingStart(
371 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01372 SimulateAck(false);
373 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
374 EXPECT_EQ(OverscrollSource::NONE, controller_source());
375 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
376 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
377
Daniel Cheng224569ee2018-04-25 05:45:06378 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19379
380 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00381 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19382 timestamp));
383 SimulateAck(false);
384
Mohsen Izadi8c59ba52018-04-12 18:52:01385 // Simulate a touchscreen gesture scroll-update event that passes the start
386 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
387 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00388 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01389 SimulateAck(false);
390 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
391 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
392 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
393 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
394
Daniel Cheng224569ee2018-04-25 05:45:06395 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19396
Mohsen Izadi8c59ba52018-04-12 18:52:01397 // Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
398 // should abort pull-to-refresh.
399 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00400 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19401 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01402 SimulateAck(false);
403 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
404 EXPECT_EQ(OverscrollSource::NONE, controller_source());
405 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
406 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
407}
408
409// Verifies that when pull-to-refresh is enabled only for touchscreen, it is
410// triggered for touchscreen but not for touchpad.
411TEST_F(OverscrollControllerTest, PullToRefreshEnabledTouchscreen) {
412 ScopedPullToRefreshMode scoped_mode(
413 OverscrollConfig::PullToRefreshMode::kEnabledTouchschreen);
414
Daniel Cheng224569ee2018-04-25 05:45:06415 base::TimeTicks timestamp =
416 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19417
418 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00419 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19420 timestamp));
421 SimulateAck(false);
422
Mohsen Izadi8c59ba52018-04-12 18:52:01423 // Simulate a touchpad gesture scroll-update event that passes the start
424 // threshold and ACK it as not processed. Pull-to-refresh should not be
425 // triggered.
426 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00427 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01428 SimulateAck(false);
429 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
430 EXPECT_EQ(OverscrollSource::NONE, controller_source());
431 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
432 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
433
Daniel Cheng224569ee2018-04-25 05:45:06434 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19435
Mohsen Izadi8c59ba52018-04-12 18:52:01436 // Simulate a touchpad zero-velocity fling-start which would normally end
437 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Daniel Cheng7f9ec902019-04-18 05:07:00438 EXPECT_FALSE(SimulateGestureFlingStart(
439 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01440 SimulateAck(false);
441 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
442 EXPECT_EQ(OverscrollSource::NONE, controller_source());
443 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
444 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
445
Daniel Cheng224569ee2018-04-25 05:45:06446 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19447
448 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00449 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19450 timestamp));
451 SimulateAck(false);
452
Mohsen Izadi8c59ba52018-04-12 18:52:01453 // Simulate a touchscreen gesture scroll-update event that passes the start
454 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
455 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00456 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01457 SimulateAck(false);
458 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
459 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
460 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
461 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
462
Daniel Cheng224569ee2018-04-25 05:45:06463 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19464
Mohsen Izadi8c59ba52018-04-12 18:52:01465 // Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
466 // should abort pull-to-refresh.
467 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00468 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19469 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01470 SimulateAck(false);
471 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
472 EXPECT_EQ(OverscrollSource::NONE, controller_source());
473 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
474 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
475}
476
chaopengcd44c7622018-04-13 04:08:21477// Ensure disabling kTouchpadOverscrollHistoryNavigation will prevent overscroll
478// from touchpad.
479TEST_F(OverscrollControllerTest, DisableTouchpadOverscrollHistoryNavigation) {
480 base::test::ScopedFeatureList feature_list;
481 feature_list.InitAndDisableFeature(
482 features::kTouchpadOverscrollHistoryNavigation);
483 ASSERT_FALSE(OverscrollConfig::TouchpadOverscrollHistoryNavigationEnabled());
Mohsen Izadi5a6583512018-04-23 18:31:19484
Daniel Cheng224569ee2018-04-25 05:45:06485 const base::TimeTicks timestamp =
486 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19487
chaopengcd44c7622018-04-13 04:08:21488 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00489 200, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopengcd44c7622018-04-13 04:08:21490 SimulateAck(false);
491
492 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
493 EXPECT_EQ(OverscrollSource::NONE, controller_source());
494 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
495 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
496}
497
Mohsen Izadi5a6583512018-04-23 18:31:19498// Verifies that if an overscroll happens before cool off period after a page
Mohsen Izadi8f43c2c52018-10-09 17:17:11499// scroll, it does not trigger pull-to-refresh. Verifies following sequence of
500// scrolls:
501// 1) Page scroll;
502// 2) Scroll before cool off -> PTR not triggered;
503// 3) Scroll before cool off -> PTR not triggered;
504// 4) Scroll after cool off -> PTR triggered;
505// 5) Scroll before cool off -> PTR triggered.
506TEST_F(OverscrollControllerTest, PullToRefreshBeforeCoolOff) {
Mohsen Izadi5a6583512018-04-23 18:31:19507 ScopedPullToRefreshMode scoped_mode(
508 OverscrollConfig::PullToRefreshMode::kEnabled);
509
Mohsen Izadi8f43c2c52018-10-09 17:17:11510 // 1) Page scroll.
Daniel Cheng224569ee2018-04-25 05:45:06511 base::TimeTicks timestamp =
512 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19513
514 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00515 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19516 timestamp));
517 SimulateAck(false);
518
519 // Simulate a touchscreen gesture scroll-update event that passes the start
Mohsen Izadi8f43c2c52018-10-09 17:17:11520 // threshold and ACK it as processed. Pull-to-refresh should not be triggered.
Mohsen Izadi5a6583512018-04-23 18:31:19521 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00522 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi5a6583512018-04-23 18:31:19523 SimulateAck(true);
524 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
525 EXPECT_EQ(OverscrollSource::NONE, controller_source());
526 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
527 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
528
Daniel Cheng224569ee2018-04-25 05:45:06529 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19530
531 // Simulate a touchscreen gesture scroll-end which would normally end
532 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
533 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00534 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19535 timestamp));
536 SimulateAck(false);
537 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
538 EXPECT_EQ(OverscrollSource::NONE, controller_source());
539 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
540 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
541
Mohsen Izadi8f43c2c52018-10-09 17:17:11542 // 2) Scroll before cool off -> PTR not triggered.
543 timestamp += base::TimeDelta::FromMilliseconds(500);
Mohsen Izadi5a6583512018-04-23 18:31:19544
545 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00546 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19547 timestamp));
548 SimulateAck(false);
549
550 // Simulate a touchscreen gesture scroll-update event that passes the start
551 // threshold and ACK it as not processed. Pull-to-refresh should not be
552 // triggered.
553 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00554 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi5a6583512018-04-23 18:31:19555 SimulateAck(false);
556 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
557 EXPECT_EQ(OverscrollSource::NONE, controller_source());
558 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
559 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
560
Daniel Cheng224569ee2018-04-25 05:45:06561 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19562
563 // Simulate a touchscreen gesture scroll-end which would normally end
564 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
565 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00566 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19567 timestamp));
568 SimulateAck(false);
569 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
570 EXPECT_EQ(OverscrollSource::NONE, controller_source());
571 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
572 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
Mohsen Izadi8f43c2c52018-10-09 17:17:11573
574 // 3) Scroll before cool off -> PTR not triggered.
575 timestamp += base::TimeDelta::FromMilliseconds(500);
576
577 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00578 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11579 timestamp));
580 SimulateAck(false);
581
582 // Simulate a touchscreen gesture scroll-update event that passes the start
583 // threshold and ACK it as not processed. Pull-to-refresh should not be
584 // triggered.
585 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00586 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11587 SimulateAck(false);
588 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
589 EXPECT_EQ(OverscrollSource::NONE, controller_source());
590 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
591 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
592
593 timestamp += base::TimeDelta::FromSeconds(1);
594
595 // Simulate a touchscreen gesture scroll-end which would normally end
596 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
597 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00598 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11599 timestamp));
600 SimulateAck(false);
601 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
602 EXPECT_EQ(OverscrollSource::NONE, controller_source());
603 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
604 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
605
606 // 4) Scroll after cool off -> PTR triggered.
607 timestamp += base::TimeDelta::FromSeconds(1);
608
609 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00610 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11611 timestamp));
612 SimulateAck(false);
613
614 // Simulate a touchscreen gesture scroll-update event that passes the start
615 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
616 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00617 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11618 SimulateAck(false);
619 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
620 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
621 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
622 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
623
624 timestamp += base::TimeDelta::FromSeconds(1);
625
626 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
627 // and ACK it as not processed. Pull-to-refresh should be aborted.
628 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00629 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11630 timestamp));
631 SimulateAck(false);
632 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
633 EXPECT_EQ(OverscrollSource::NONE, controller_source());
634 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
635 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
636
637 // 5) Scroll before cool off -> PTR triggered.
638 timestamp += base::TimeDelta::FromMilliseconds(500);
639
640 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00641 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11642 timestamp));
643 SimulateAck(false);
644
645 // Simulate a touchscreen gesture scroll-update event that passes the start
646 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
647 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00648 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11649 SimulateAck(false);
650 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
651 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
652 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
653 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
654
655 timestamp += base::TimeDelta::FromSeconds(1);
656
657 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
658 // and ACK it as not processed. Pull-to-refresh should be aborted.
659 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00660 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11661 timestamp));
662 SimulateAck(false);
663 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
664 EXPECT_EQ(OverscrollSource::NONE, controller_source());
665 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
666 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
667}
668
669// Verifies that if an overscroll happens after cool off period after a page
670// scroll, it triggers pull-to-refresh. Verifies the following sequence of
671// scrolls:
672// 1) Page scroll;
673// 2) Scroll after cool off -> PTR triggered;
674// 3) Scroll before cool off -> PTR triggered;
675TEST_F(OverscrollControllerTest, PullToRefreshAfterCoolOff) {
676 ScopedPullToRefreshMode scoped_mode(
677 OverscrollConfig::PullToRefreshMode::kEnabled);
678
679 // 1) Page scroll.
680 base::TimeTicks timestamp =
681 blink::WebInputEvent::GetStaticTimeStampForTests();
682
683 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00684 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11685 timestamp));
686 SimulateAck(false);
687
688 // Simulate a touchscreen gesture scroll-update event that passes the start
689 // threshold and ACK it as processed. Pull-to-refresh should not be triggered.
690 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00691 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11692 SimulateAck(true);
693 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
694 EXPECT_EQ(OverscrollSource::NONE, controller_source());
695 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
696 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
697
698 timestamp += base::TimeDelta::FromSeconds(1);
699
700 // Simulate a touchscreen gesture scroll-end which would normally end
701 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
702 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00703 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11704 timestamp));
705 SimulateAck(false);
706 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
707 EXPECT_EQ(OverscrollSource::NONE, controller_source());
708 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
709 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
710
711 // 2) Scroll after cool off -> PTR triggered.
712 timestamp += base::TimeDelta::FromSeconds(1);
713
714 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00715 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11716 timestamp));
717 SimulateAck(false);
718
719 // Simulate a touchscreen gesture scroll-update event that passes the start
720 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
721 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00722 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11723 SimulateAck(false);
724 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
725 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
726 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
727 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
728
729 timestamp += base::TimeDelta::FromSeconds(1);
730
731 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
732 // and ACK it as not processed. Pull-to-refresh should be aborted.
733 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00734 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11735 timestamp));
736 SimulateAck(false);
737 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
738 EXPECT_EQ(OverscrollSource::NONE, controller_source());
739 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
740 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
741
742 // 3) Scroll before cool off -> PTR triggered.
743 timestamp += base::TimeDelta::FromMilliseconds(500);
744
745 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00746 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11747 timestamp));
748 SimulateAck(false);
749
750 // Simulate a touchscreen gesture scroll-update event that passes the start
751 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
752 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00753 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11754 SimulateAck(false);
755 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
756 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
757 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
758 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
759
760 timestamp += base::TimeDelta::FromSeconds(1);
761
762 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
763 // and ACK it as not processed. Pull-to-refresh should be aborted.
764 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00765 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11766 timestamp));
767 SimulateAck(false);
768 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
769 EXPECT_EQ(OverscrollSource::NONE, controller_source());
770 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
771 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
Mohsen Izadi5a6583512018-04-23 18:31:19772}
773
Mohsen Izadi9830436c2017-12-21 18:02:46774} // namespace content