blob: 31f8a0e6cc482e2b2085e6ac9f6e53068228f1e7 [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"
Dave Tapuska129cef82019-12-19 16:36:4818#include "third_party/blink/public/common/input/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>(
Matt Amert7b7f6722019-10-03 00:27:4246 SyntheticWebMouseWheelEventBuilder::Build(
Mohsen Izadiffcbc61f12020-02-09 06:31:2747 0, 0, dx, dy, 0, ui::ScrollGranularity::kScrollByPrecisePixel));
Mohsen Izadi9830436c2017-12-21 18:02:4648 return controller_->WillHandleEvent(*current_event_);
49 }
50
chaopeng1d469b02018-04-05 15:41:0751 // Creates and sends a gesture event to the overscroll controller. Returns
52 // |true| if the event is consumed by the overscroll controller.
53 bool SimulateGestureEvent(blink::WebInputEvent::Type type,
Mohsen Izadi5a6583512018-04-23 18:31:1954 blink::WebGestureDevice source_device,
Daniel Cheng224569ee2018-04-25 05:45:0655 base::TimeTicks timestamp) {
chaopeng1d469b02018-04-05 15:41:0756 DCHECK(!current_event_);
57 current_event_ = std::make_unique<blink::WebGestureEvent>(
58 SyntheticWebGestureEventBuilder::Build(type, source_device));
Daniel Cheng224569ee2018-04-25 05:45:0659 current_event_->SetTimeStamp(timestamp);
chaopeng1d469b02018-04-05 15:41:0760 return controller_->WillHandleEvent(*current_event_);
61 }
62
Mohsen Izadi9830436c2017-12-21 18:02:4663 // Creates and sends a gesture-scroll-update event to the overscroll
64 // controller. Returns |true| if the event is consumed by the overscroll
65 // controller.
66 bool SimulateGestureScrollUpdate(float dx,
67 float dy,
chaopeng1d469b02018-04-05 15:41:0768 blink::WebGestureDevice device,
Daniel Cheng224569ee2018-04-25 05:45:0669 base::TimeTicks timestamp,
chaopeng1d469b02018-04-05 15:41:0770 bool inertial_update) {
Mohsen Izadi9830436c2017-12-21 18:02:4671 DCHECK(!current_event_);
chaopeng1d469b02018-04-05 15:41:0772 auto event = std::make_unique<blink::WebGestureEvent>(
Mohsen Izadi9830436c2017-12-21 18:02:4673 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dx, dy, 0, device));
Daniel Cheng224569ee2018-04-25 05:45:0674 event->SetTimeStamp(timestamp);
chaopeng1d469b02018-04-05 15:41:0775 if (inertial_update) {
76 event->data.scroll_update.inertial_phase =
Daniel Libby6ce6b95a2019-05-10 17:06:2677 blink::WebGestureEvent::InertialPhaseState::kMomentum;
chaopeng1d469b02018-04-05 15:41:0778 }
79 current_event_ = std::move(event);
Mohsen Izadi9830436c2017-12-21 18:02:4680 return controller_->WillHandleEvent(*current_event_);
81 }
82
Mohsen Izadi8c59ba52018-04-12 18:52:0183 // Creates and sends a gesture-fling-start event to the overscroll controller.
84 // Returns |true| if the event is consumed by the overscroll controller.
85 bool SimulateGestureFlingStart(float velocity_x,
86 float velocity_y,
Mohsen Izadi5a6583512018-04-23 18:31:1987 blink::WebGestureDevice device,
Daniel Cheng224569ee2018-04-25 05:45:0688 base::TimeTicks timestamp) {
Mohsen Izadi8c59ba52018-04-12 18:52:0189 DCHECK(!current_event_);
90 current_event_ = std::make_unique<blink::WebGestureEvent>(
91 SyntheticWebGestureEventBuilder::BuildFling(velocity_x, velocity_y,
92 device));
Daniel Cheng224569ee2018-04-25 05:45:0693 current_event_->SetTimeStamp(timestamp);
Mohsen Izadi8c59ba52018-04-12 18:52:0194 return controller_->WillHandleEvent(*current_event_);
95 }
96
Mohsen Izadi9830436c2017-12-21 18:02:4697 // Notifies the overscroll controller that the current event is ACKed.
98 void SimulateAck(bool processed) {
99 DCHECK(current_event_);
100 controller_->ReceivedEventACK(*current_event_, processed);
101 current_event_ = nullptr;
102 }
103
104 TestOverscrollDelegate* delegate() const { return delegate_.get(); }
105
106 OverscrollMode controller_mode() const {
107 return controller_->overscroll_mode_;
108 }
109
110 OverscrollSource controller_source() const {
111 return controller_->overscroll_source_;
112 }
113
114 private:
115 std::unique_ptr<TestOverscrollDelegate> delegate_;
116 std::unique_ptr<OverscrollController> controller_;
117
118 // Keeps track of the last event that has been processed by the overscroll
119 // controller which is not yet ACKed. Will be null if no event is processed or
120 // the last event is ACKed.
121 std::unique_ptr<blink::WebInputEvent> current_event_;
122
chaopengcd44c7622018-04-13 04:08:21123 base::test::ScopedFeatureList scoped_feature_list_;
124
Mohsen Izadi9830436c2017-12-21 18:02:46125 DISALLOW_COPY_AND_ASSIGN(OverscrollControllerTest);
126};
127
128// Tests that if a mouse-wheel is consumed by content before overscroll is
129// initiated, overscroll will not initiate anymore.
130TEST_F(OverscrollControllerTest, MouseWheelConsumedPreventsOverscroll) {
Daniel Cheng224569ee2018-04-25 05:45:06131 const base::TimeTicks timestamp =
132 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19133
Mohsen Izadi9830436c2017-12-21 18:02:46134 // Simulate a mouse-wheel, ACK it as not processed, simulate the corresponding
Mohsen Izadi8c59ba52018-04-12 18:52:01135 // gesture scroll-update event, and ACK it as not processed. Since it is not
Mohsen Izadi9830436c2017-12-21 18:02:46136 // passing the start threshold, no overscroll should happen.
137 EXPECT_FALSE(SimulateMouseWheel(10, 0));
138 SimulateAck(false);
chaopeng1d469b02018-04-05 15:41:07139 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00140 10, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi9830436c2017-12-21 18:02:46141 SimulateAck(false);
142 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
143 EXPECT_EQ(OverscrollSource::NONE, controller_source());
144 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
145 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
146
147 // Simulate a mouse-wheel and ACK it as processed. No gesture scroll-update
148 // needs to be simulated. Still no overscroll.
149 EXPECT_FALSE(SimulateMouseWheel(10, 0));
150 SimulateAck(true);
151 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
152 EXPECT_EQ(OverscrollSource::NONE, controller_source());
153 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
154 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
155
156 // Simulate a mouse-wheel and the corresponding gesture scroll-update both
157 // ACKed as not processed. Although the scroll passes overscroll start
158 // threshold, no overscroll should happen since the previous mouse-wheel was
159 // marked as processed.
160 EXPECT_FALSE(SimulateMouseWheel(100, 0));
161 SimulateAck(false);
chaopeng1d469b02018-04-05 15:41:07162 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00163 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi9830436c2017-12-21 18:02:46164 SimulateAck(false);
165 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
166 EXPECT_EQ(OverscrollSource::NONE, controller_source());
167 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
168 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
169}
170
chaopeng1d469b02018-04-05 15:41:07171// Verifying the inertial scroll event completes overscroll. After that we will
172// ignore the following inertial scroll events until new sequence start.
173TEST_F(OverscrollControllerTest,
174 InertialGestureScrollUpdateCompletesOverscroll) {
Daniel Cheng224569ee2018-04-25 05:45:06175 const base::TimeTicks timestamp =
176 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19177
chaopeng1d469b02018-04-05 15:41:07178 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00179 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19180 timestamp));
chaopeng1d469b02018-04-05 15:41:07181 SimulateAck(false);
182
183 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00184 200, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopeng1d469b02018-04-05 15:41:07185 SimulateAck(false);
186 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
187 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
188 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
189 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
190
191 // Inertial update event complete the overscroll action.
192 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00193 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng1d469b02018-04-05 15:41:07194 SimulateAck(false);
chaopenga7585d792018-04-10 18:02:38195 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
196 EXPECT_EQ(OverscrollSource::NONE, controller_source());
197 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
chaopeng1d469b02018-04-05 15:41:07198 EXPECT_EQ(OVERSCROLL_EAST, delegate()->completed_mode());
199
200 // Next Inertial update event would be consumed by overscroll controller.
201 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00202 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng1d469b02018-04-05 15:41:07203}
204
chaopeng9736c522018-05-08 18:32:27205// Ensure inertial gesture scroll update can not start overscroll.
206TEST_F(OverscrollControllerTest, InertialGSUsDoNotStartOverscroll) {
207 base::TimeTicks timestamp =
208 blink::WebInputEvent::GetStaticTimeStampForTests();
209 // Inertial update event complete the overscroll action.
210 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00211 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27212 SimulateAck(false);
213 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
214 EXPECT_EQ(OverscrollSource::NONE, controller_source());
215 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
216 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
217}
218
219// After 300ms inertial gesture scroll updates, overscroll must get cancelled
220// if not completed.
221TEST_F(OverscrollControllerTest, OnlyProcessLimitedInertialGSUEvents) {
222 base::TimeTicks timestamp =
223 blink::WebInputEvent::GetStaticTimeStampForTests();
224
225 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00226 blink::WebGestureDevice::kTouchpad,
chaopeng9736c522018-05-08 18:32:27227 timestamp));
228 SimulateAck(false);
229
230 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00231 61, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopeng9736c522018-05-08 18:32:27232 SimulateAck(false);
233 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
234 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
235 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
236 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
237
238 // First inertial.
239 timestamp += base::TimeDelta::FromSeconds(1);
240 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00241 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27242 SimulateAck(true);
243 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
244 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
245 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
246 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
247
248 // Not cancel in 10ms.
249 timestamp += base::TimeDelta::FromMilliseconds(10);
250 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00251 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27252 SimulateAck(true);
253 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
254 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
255 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
256 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
257
258 // Cancel after 300ms.
259 timestamp += base::TimeDelta::FromMilliseconds(291);
260 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00261 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27262 SimulateAck(true);
263 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
264 EXPECT_EQ(OverscrollSource::NONE, controller_source());
265 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
266 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
267
268 // Next event should be ignored.
269 timestamp += base::TimeDelta::FromMilliseconds(100);
270 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00271 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27272}
273
Mohsen Izadi8c59ba52018-04-12 18:52:01274// Verifies that when pull-to-refresh is disabled, it is not triggered for
275// neither touchpad nor touchscreen.
276TEST_F(OverscrollControllerTest, PullToRefreshDisabled) {
277 ScopedPullToRefreshMode scoped_mode(
278 OverscrollConfig::PullToRefreshMode::kDisabled);
279
Daniel Cheng224569ee2018-04-25 05:45:06280 base::TimeTicks timestamp =
281 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19282
283 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00284 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19285 timestamp));
286 SimulateAck(false);
287
Mohsen Izadi8c59ba52018-04-12 18:52:01288 // Simulate a touchpad gesture scroll-update event that passes the start
289 // threshold and ACK it as not processed. Pull-to-refresh should not be
290 // triggered.
291 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00292 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01293 SimulateAck(false);
294 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
295 EXPECT_EQ(OverscrollSource::NONE, controller_source());
296 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
297 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
298
Daniel Cheng224569ee2018-04-25 05:45:06299 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19300
Mohsen Izadi8c59ba52018-04-12 18:52:01301 // Simulate a touchpad zero-velocity fling-start which would normally end
302 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Daniel Cheng7f9ec902019-04-18 05:07:00303 EXPECT_FALSE(SimulateGestureFlingStart(
304 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01305 SimulateAck(false);
306 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
307 EXPECT_EQ(OverscrollSource::NONE, controller_source());
308 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
309 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
310
Daniel Cheng224569ee2018-04-25 05:45:06311 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19312
313 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00314 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19315 timestamp));
316 SimulateAck(false);
317
Mohsen Izadi8c59ba52018-04-12 18:52:01318 // Simulate a touchscreen gesture scroll-update event that passes the start
319 // threshold and ACK it as not processed. Pull-to-refresh should not be
320 // triggered.
321 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00322 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01323 SimulateAck(false);
324 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
325 EXPECT_EQ(OverscrollSource::NONE, controller_source());
326 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
327 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
328
Daniel Cheng224569ee2018-04-25 05:45:06329 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19330
Mohsen Izadi8c59ba52018-04-12 18:52:01331 // Simulate a touchscreen gesture scroll-end which would normally end
332 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
333 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00334 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19335 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01336 SimulateAck(false);
337 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
338 EXPECT_EQ(OverscrollSource::NONE, controller_source());
339 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
340 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
341}
342
343// Verifies that when pull-to-refresh is enabled, it is triggered for both
344// touchpad and touchscreen.
345TEST_F(OverscrollControllerTest, PullToRefreshEnabled) {
346 ScopedPullToRefreshMode scoped_mode(
347 OverscrollConfig::PullToRefreshMode::kEnabled);
348
Daniel Cheng224569ee2018-04-25 05:45:06349 base::TimeTicks timestamp =
350 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19351
352 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00353 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19354 timestamp));
355 SimulateAck(false);
356
Mohsen Izadi8c59ba52018-04-12 18:52:01357 // Simulate a touchpad gesture scroll-update event that passes the start
358 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
359 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00360 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01361 SimulateAck(false);
362 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
363 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
364 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
365 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
366
Daniel Cheng224569ee2018-04-25 05:45:06367 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19368
Mohsen Izadi8c59ba52018-04-12 18:52:01369 // Simulate a touchpad zero-velocity fling-start and ACK it as not processed..
370 // It should abort pull-to-refresh.
Daniel Cheng7f9ec902019-04-18 05:07:00371 EXPECT_FALSE(SimulateGestureFlingStart(
372 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01373 SimulateAck(false);
374 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
375 EXPECT_EQ(OverscrollSource::NONE, controller_source());
376 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
377 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
378
Daniel Cheng224569ee2018-04-25 05:45:06379 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19380
381 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00382 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19383 timestamp));
384 SimulateAck(false);
385
Mohsen Izadi8c59ba52018-04-12 18:52:01386 // Simulate a touchscreen gesture scroll-update event that passes the start
387 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
388 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00389 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01390 SimulateAck(false);
391 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
392 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
393 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
394 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
395
Daniel Cheng224569ee2018-04-25 05:45:06396 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19397
Mohsen Izadi8c59ba52018-04-12 18:52:01398 // Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
399 // should abort pull-to-refresh.
400 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00401 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19402 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01403 SimulateAck(false);
404 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
405 EXPECT_EQ(OverscrollSource::NONE, controller_source());
406 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
407 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
408}
409
410// Verifies that when pull-to-refresh is enabled only for touchscreen, it is
411// triggered for touchscreen but not for touchpad.
412TEST_F(OverscrollControllerTest, PullToRefreshEnabledTouchscreen) {
413 ScopedPullToRefreshMode scoped_mode(
414 OverscrollConfig::PullToRefreshMode::kEnabledTouchschreen);
415
Daniel Cheng224569ee2018-04-25 05:45:06416 base::TimeTicks timestamp =
417 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19418
419 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00420 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19421 timestamp));
422 SimulateAck(false);
423
Mohsen Izadi8c59ba52018-04-12 18:52:01424 // Simulate a touchpad gesture scroll-update event that passes the start
425 // threshold and ACK it as not processed. Pull-to-refresh should not be
426 // triggered.
427 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00428 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01429 SimulateAck(false);
430 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
431 EXPECT_EQ(OverscrollSource::NONE, controller_source());
432 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
433 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
434
Daniel Cheng224569ee2018-04-25 05:45:06435 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19436
Mohsen Izadi8c59ba52018-04-12 18:52:01437 // Simulate a touchpad zero-velocity fling-start which would normally end
438 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Daniel Cheng7f9ec902019-04-18 05:07:00439 EXPECT_FALSE(SimulateGestureFlingStart(
440 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01441 SimulateAck(false);
442 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
443 EXPECT_EQ(OverscrollSource::NONE, controller_source());
444 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
445 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
446
Daniel Cheng224569ee2018-04-25 05:45:06447 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19448
449 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00450 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19451 timestamp));
452 SimulateAck(false);
453
Mohsen Izadi8c59ba52018-04-12 18:52:01454 // Simulate a touchscreen gesture scroll-update event that passes the start
455 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
456 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00457 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01458 SimulateAck(false);
459 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
460 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
461 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
462 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
463
Daniel Cheng224569ee2018-04-25 05:45:06464 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19465
Mohsen Izadi8c59ba52018-04-12 18:52:01466 // Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
467 // should abort pull-to-refresh.
468 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00469 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19470 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01471 SimulateAck(false);
472 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
473 EXPECT_EQ(OverscrollSource::NONE, controller_source());
474 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
475 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
476}
477
chaopengcd44c7622018-04-13 04:08:21478// Ensure disabling kTouchpadOverscrollHistoryNavigation will prevent overscroll
479// from touchpad.
480TEST_F(OverscrollControllerTest, DisableTouchpadOverscrollHistoryNavigation) {
481 base::test::ScopedFeatureList feature_list;
482 feature_list.InitAndDisableFeature(
483 features::kTouchpadOverscrollHistoryNavigation);
484 ASSERT_FALSE(OverscrollConfig::TouchpadOverscrollHistoryNavigationEnabled());
Mohsen Izadi5a6583512018-04-23 18:31:19485
Daniel Cheng224569ee2018-04-25 05:45:06486 const base::TimeTicks timestamp =
487 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19488
chaopengcd44c7622018-04-13 04:08:21489 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00490 200, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopengcd44c7622018-04-13 04:08:21491 SimulateAck(false);
492
493 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
494 EXPECT_EQ(OverscrollSource::NONE, controller_source());
495 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
496 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
497}
498
Mohsen Izadi5a6583512018-04-23 18:31:19499// Verifies that if an overscroll happens before cool off period after a page
Mohsen Izadi8f43c2c52018-10-09 17:17:11500// scroll, it does not trigger pull-to-refresh. Verifies following sequence of
501// scrolls:
502// 1) Page scroll;
503// 2) Scroll before cool off -> PTR not triggered;
504// 3) Scroll before cool off -> PTR not triggered;
505// 4) Scroll after cool off -> PTR triggered;
506// 5) Scroll before cool off -> PTR triggered.
507TEST_F(OverscrollControllerTest, PullToRefreshBeforeCoolOff) {
Mohsen Izadi5a6583512018-04-23 18:31:19508 ScopedPullToRefreshMode scoped_mode(
509 OverscrollConfig::PullToRefreshMode::kEnabled);
510
Mohsen Izadi8f43c2c52018-10-09 17:17:11511 // 1) Page scroll.
Daniel Cheng224569ee2018-04-25 05:45:06512 base::TimeTicks timestamp =
513 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19514
515 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00516 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19517 timestamp));
518 SimulateAck(false);
519
520 // Simulate a touchscreen gesture scroll-update event that passes the start
Mohsen Izadi8f43c2c52018-10-09 17:17:11521 // threshold and ACK it as processed. Pull-to-refresh should not be triggered.
Mohsen Izadi5a6583512018-04-23 18:31:19522 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00523 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi5a6583512018-04-23 18:31:19524 SimulateAck(true);
525 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
526 EXPECT_EQ(OverscrollSource::NONE, controller_source());
527 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
528 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
529
Daniel Cheng224569ee2018-04-25 05:45:06530 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19531
532 // Simulate a touchscreen gesture scroll-end which would normally end
533 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
534 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00535 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19536 timestamp));
537 SimulateAck(false);
538 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
539 EXPECT_EQ(OverscrollSource::NONE, controller_source());
540 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
541 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
542
Mohsen Izadi8f43c2c52018-10-09 17:17:11543 // 2) Scroll before cool off -> PTR not triggered.
544 timestamp += base::TimeDelta::FromMilliseconds(500);
Mohsen Izadi5a6583512018-04-23 18:31:19545
546 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00547 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19548 timestamp));
549 SimulateAck(false);
550
551 // Simulate a touchscreen gesture scroll-update event that passes the start
552 // threshold and ACK it as not processed. Pull-to-refresh should not be
553 // triggered.
554 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00555 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi5a6583512018-04-23 18:31:19556 SimulateAck(false);
557 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
558 EXPECT_EQ(OverscrollSource::NONE, controller_source());
559 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
560 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
561
Daniel Cheng224569ee2018-04-25 05:45:06562 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19563
564 // Simulate a touchscreen gesture scroll-end which would normally end
565 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
566 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00567 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19568 timestamp));
569 SimulateAck(false);
570 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
571 EXPECT_EQ(OverscrollSource::NONE, controller_source());
572 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
573 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
Mohsen Izadi8f43c2c52018-10-09 17:17:11574
575 // 3) Scroll before cool off -> PTR not triggered.
576 timestamp += base::TimeDelta::FromMilliseconds(500);
577
578 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00579 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11580 timestamp));
581 SimulateAck(false);
582
583 // Simulate a touchscreen gesture scroll-update event that passes the start
584 // threshold and ACK it as not processed. Pull-to-refresh should not be
585 // triggered.
586 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00587 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11588 SimulateAck(false);
589 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
590 EXPECT_EQ(OverscrollSource::NONE, controller_source());
591 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
592 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
593
594 timestamp += base::TimeDelta::FromSeconds(1);
595
596 // Simulate a touchscreen gesture scroll-end which would normally end
597 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
598 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00599 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11600 timestamp));
601 SimulateAck(false);
602 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
603 EXPECT_EQ(OverscrollSource::NONE, controller_source());
604 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
605 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
606
607 // 4) Scroll after cool off -> PTR triggered.
608 timestamp += base::TimeDelta::FromSeconds(1);
609
610 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00611 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11612 timestamp));
613 SimulateAck(false);
614
615 // Simulate a touchscreen gesture scroll-update event that passes the start
616 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
617 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00618 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11619 SimulateAck(false);
620 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
621 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
622 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
623 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
624
625 timestamp += base::TimeDelta::FromSeconds(1);
626
627 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
628 // and ACK it as not processed. Pull-to-refresh should be aborted.
629 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00630 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11631 timestamp));
632 SimulateAck(false);
633 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
634 EXPECT_EQ(OverscrollSource::NONE, controller_source());
635 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
636 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
637
638 // 5) Scroll before cool off -> PTR triggered.
639 timestamp += base::TimeDelta::FromMilliseconds(500);
640
641 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00642 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11643 timestamp));
644 SimulateAck(false);
645
646 // Simulate a touchscreen gesture scroll-update event that passes the start
647 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
648 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00649 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11650 SimulateAck(false);
651 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
652 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
653 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
654 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
655
656 timestamp += base::TimeDelta::FromSeconds(1);
657
658 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
659 // and ACK it as not processed. Pull-to-refresh should be aborted.
660 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00661 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11662 timestamp));
663 SimulateAck(false);
664 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
665 EXPECT_EQ(OverscrollSource::NONE, controller_source());
666 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
667 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
668}
669
670// Verifies that if an overscroll happens after cool off period after a page
671// scroll, it triggers pull-to-refresh. Verifies the following sequence of
672// scrolls:
673// 1) Page scroll;
674// 2) Scroll after cool off -> PTR triggered;
675// 3) Scroll before cool off -> PTR triggered;
676TEST_F(OverscrollControllerTest, PullToRefreshAfterCoolOff) {
677 ScopedPullToRefreshMode scoped_mode(
678 OverscrollConfig::PullToRefreshMode::kEnabled);
679
680 // 1) Page scroll.
681 base::TimeTicks timestamp =
682 blink::WebInputEvent::GetStaticTimeStampForTests();
683
684 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00685 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11686 timestamp));
687 SimulateAck(false);
688
689 // Simulate a touchscreen gesture scroll-update event that passes the start
690 // threshold and ACK it as processed. Pull-to-refresh should not be triggered.
691 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00692 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11693 SimulateAck(true);
694 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
695 EXPECT_EQ(OverscrollSource::NONE, controller_source());
696 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
697 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
698
699 timestamp += base::TimeDelta::FromSeconds(1);
700
701 // Simulate a touchscreen gesture scroll-end which would normally end
702 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
703 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00704 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11705 timestamp));
706 SimulateAck(false);
707 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
708 EXPECT_EQ(OverscrollSource::NONE, controller_source());
709 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
710 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
711
712 // 2) Scroll after cool off -> PTR triggered.
713 timestamp += base::TimeDelta::FromSeconds(1);
714
715 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00716 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11717 timestamp));
718 SimulateAck(false);
719
720 // Simulate a touchscreen gesture scroll-update event that passes the start
721 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
722 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00723 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11724 SimulateAck(false);
725 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
726 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
727 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
728 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
729
730 timestamp += base::TimeDelta::FromSeconds(1);
731
732 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
733 // and ACK it as not processed. Pull-to-refresh should be aborted.
734 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00735 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11736 timestamp));
737 SimulateAck(false);
738 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
739 EXPECT_EQ(OverscrollSource::NONE, controller_source());
740 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
741 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
742
743 // 3) Scroll before cool off -> PTR triggered.
744 timestamp += base::TimeDelta::FromMilliseconds(500);
745
746 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00747 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11748 timestamp));
749 SimulateAck(false);
750
751 // Simulate a touchscreen gesture scroll-update event that passes the start
752 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
753 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00754 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11755 SimulateAck(false);
756 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
757 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
758 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
759 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
760
761 timestamp += base::TimeDelta::FromSeconds(1);
762
763 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
764 // and ACK it as not processed. Pull-to-refresh should be aborted.
765 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00766 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11767 timestamp));
768 SimulateAck(false);
769 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
770 EXPECT_EQ(OverscrollSource::NONE, controller_source());
771 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
772 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
Mohsen Izadi5a6583512018-04-23 18:31:19773}
774
Mohsen Izadi9830436c2017-12-21 18:02:46775} // namespace content