blob: 742dd140af9962c4bf8eb1cc2bb7e2b9405f0b64 [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(
47 0, 0, dx, dy, 0,
48 ui::input_types::ScrollGranularity::kScrollByPrecisePixel));
Mohsen Izadi9830436c2017-12-21 18:02:4649 return controller_->WillHandleEvent(*current_event_);
50 }
51
chaopeng1d469b02018-04-05 15:41:0752 // Creates and sends a gesture event to the overscroll controller. Returns
53 // |true| if the event is consumed by the overscroll controller.
54 bool SimulateGestureEvent(blink::WebInputEvent::Type type,
Mohsen Izadi5a6583512018-04-23 18:31:1955 blink::WebGestureDevice source_device,
Daniel Cheng224569ee2018-04-25 05:45:0656 base::TimeTicks timestamp) {
chaopeng1d469b02018-04-05 15:41:0757 DCHECK(!current_event_);
58 current_event_ = std::make_unique<blink::WebGestureEvent>(
59 SyntheticWebGestureEventBuilder::Build(type, source_device));
Daniel Cheng224569ee2018-04-25 05:45:0660 current_event_->SetTimeStamp(timestamp);
chaopeng1d469b02018-04-05 15:41:0761 return controller_->WillHandleEvent(*current_event_);
62 }
63
Mohsen Izadi9830436c2017-12-21 18:02:4664 // Creates and sends a gesture-scroll-update event to the overscroll
65 // controller. Returns |true| if the event is consumed by the overscroll
66 // controller.
67 bool SimulateGestureScrollUpdate(float dx,
68 float dy,
chaopeng1d469b02018-04-05 15:41:0769 blink::WebGestureDevice device,
Daniel Cheng224569ee2018-04-25 05:45:0670 base::TimeTicks timestamp,
chaopeng1d469b02018-04-05 15:41:0771 bool inertial_update) {
Mohsen Izadi9830436c2017-12-21 18:02:4672 DCHECK(!current_event_);
chaopeng1d469b02018-04-05 15:41:0773 auto event = std::make_unique<blink::WebGestureEvent>(
Mohsen Izadi9830436c2017-12-21 18:02:4674 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dx, dy, 0, device));
Daniel Cheng224569ee2018-04-25 05:45:0675 event->SetTimeStamp(timestamp);
chaopeng1d469b02018-04-05 15:41:0776 if (inertial_update) {
77 event->data.scroll_update.inertial_phase =
Daniel Libby6ce6b95a2019-05-10 17:06:2678 blink::WebGestureEvent::InertialPhaseState::kMomentum;
chaopeng1d469b02018-04-05 15:41:0779 }
80 current_event_ = std::move(event);
Mohsen Izadi9830436c2017-12-21 18:02:4681 return controller_->WillHandleEvent(*current_event_);
82 }
83
Mohsen Izadi8c59ba52018-04-12 18:52:0184 // Creates and sends a gesture-fling-start event to the overscroll controller.
85 // Returns |true| if the event is consumed by the overscroll controller.
86 bool SimulateGestureFlingStart(float velocity_x,
87 float velocity_y,
Mohsen Izadi5a6583512018-04-23 18:31:1988 blink::WebGestureDevice device,
Daniel Cheng224569ee2018-04-25 05:45:0689 base::TimeTicks timestamp) {
Mohsen Izadi8c59ba52018-04-12 18:52:0190 DCHECK(!current_event_);
91 current_event_ = std::make_unique<blink::WebGestureEvent>(
92 SyntheticWebGestureEventBuilder::BuildFling(velocity_x, velocity_y,
93 device));
Daniel Cheng224569ee2018-04-25 05:45:0694 current_event_->SetTimeStamp(timestamp);
Mohsen Izadi8c59ba52018-04-12 18:52:0195 return controller_->WillHandleEvent(*current_event_);
96 }
97
Mohsen Izadi9830436c2017-12-21 18:02:4698 // Notifies the overscroll controller that the current event is ACKed.
99 void SimulateAck(bool processed) {
100 DCHECK(current_event_);
101 controller_->ReceivedEventACK(*current_event_, processed);
102 current_event_ = nullptr;
103 }
104
105 TestOverscrollDelegate* delegate() const { return delegate_.get(); }
106
107 OverscrollMode controller_mode() const {
108 return controller_->overscroll_mode_;
109 }
110
111 OverscrollSource controller_source() const {
112 return controller_->overscroll_source_;
113 }
114
115 private:
116 std::unique_ptr<TestOverscrollDelegate> delegate_;
117 std::unique_ptr<OverscrollController> controller_;
118
119 // Keeps track of the last event that has been processed by the overscroll
120 // controller which is not yet ACKed. Will be null if no event is processed or
121 // the last event is ACKed.
122 std::unique_ptr<blink::WebInputEvent> current_event_;
123
chaopengcd44c7622018-04-13 04:08:21124 base::test::ScopedFeatureList scoped_feature_list_;
125
Mohsen Izadi9830436c2017-12-21 18:02:46126 DISALLOW_COPY_AND_ASSIGN(OverscrollControllerTest);
127};
128
129// Tests that if a mouse-wheel is consumed by content before overscroll is
130// initiated, overscroll will not initiate anymore.
131TEST_F(OverscrollControllerTest, MouseWheelConsumedPreventsOverscroll) {
Daniel Cheng224569ee2018-04-25 05:45:06132 const base::TimeTicks timestamp =
133 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19134
Mohsen Izadi9830436c2017-12-21 18:02:46135 // Simulate a mouse-wheel, ACK it as not processed, simulate the corresponding
Mohsen Izadi8c59ba52018-04-12 18:52:01136 // gesture scroll-update event, and ACK it as not processed. Since it is not
Mohsen Izadi9830436c2017-12-21 18:02:46137 // passing the start threshold, no overscroll should happen.
138 EXPECT_FALSE(SimulateMouseWheel(10, 0));
139 SimulateAck(false);
chaopeng1d469b02018-04-05 15:41:07140 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00141 10, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi9830436c2017-12-21 18:02:46142 SimulateAck(false);
143 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
144 EXPECT_EQ(OverscrollSource::NONE, controller_source());
145 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
146 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
147
148 // Simulate a mouse-wheel and ACK it as processed. No gesture scroll-update
149 // needs to be simulated. Still no overscroll.
150 EXPECT_FALSE(SimulateMouseWheel(10, 0));
151 SimulateAck(true);
152 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
153 EXPECT_EQ(OverscrollSource::NONE, controller_source());
154 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
155 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
156
157 // Simulate a mouse-wheel and the corresponding gesture scroll-update both
158 // ACKed as not processed. Although the scroll passes overscroll start
159 // threshold, no overscroll should happen since the previous mouse-wheel was
160 // marked as processed.
161 EXPECT_FALSE(SimulateMouseWheel(100, 0));
162 SimulateAck(false);
chaopeng1d469b02018-04-05 15:41:07163 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00164 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi9830436c2017-12-21 18:02:46165 SimulateAck(false);
166 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
167 EXPECT_EQ(OverscrollSource::NONE, controller_source());
168 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
169 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
170}
171
chaopeng1d469b02018-04-05 15:41:07172// Verifying the inertial scroll event completes overscroll. After that we will
173// ignore the following inertial scroll events until new sequence start.
174TEST_F(OverscrollControllerTest,
175 InertialGestureScrollUpdateCompletesOverscroll) {
Daniel Cheng224569ee2018-04-25 05:45:06176 const base::TimeTicks timestamp =
177 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19178
chaopeng1d469b02018-04-05 15:41:07179 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00180 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19181 timestamp));
chaopeng1d469b02018-04-05 15:41:07182 SimulateAck(false);
183
184 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00185 200, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopeng1d469b02018-04-05 15:41:07186 SimulateAck(false);
187 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
188 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
189 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
190 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
191
192 // Inertial update event complete the overscroll action.
193 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00194 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng1d469b02018-04-05 15:41:07195 SimulateAck(false);
chaopenga7585d792018-04-10 18:02:38196 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
197 EXPECT_EQ(OverscrollSource::NONE, controller_source());
198 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
chaopeng1d469b02018-04-05 15:41:07199 EXPECT_EQ(OVERSCROLL_EAST, delegate()->completed_mode());
200
201 // Next Inertial update event would be consumed by overscroll controller.
202 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00203 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng1d469b02018-04-05 15:41:07204}
205
chaopeng9736c522018-05-08 18:32:27206// Ensure inertial gesture scroll update can not start overscroll.
207TEST_F(OverscrollControllerTest, InertialGSUsDoNotStartOverscroll) {
208 base::TimeTicks timestamp =
209 blink::WebInputEvent::GetStaticTimeStampForTests();
210 // Inertial update event complete the overscroll action.
211 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00212 100, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27213 SimulateAck(false);
214 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
215 EXPECT_EQ(OverscrollSource::NONE, controller_source());
216 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
217 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
218}
219
220// After 300ms inertial gesture scroll updates, overscroll must get cancelled
221// if not completed.
222TEST_F(OverscrollControllerTest, OnlyProcessLimitedInertialGSUEvents) {
223 base::TimeTicks timestamp =
224 blink::WebInputEvent::GetStaticTimeStampForTests();
225
226 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00227 blink::WebGestureDevice::kTouchpad,
chaopeng9736c522018-05-08 18:32:27228 timestamp));
229 SimulateAck(false);
230
231 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00232 61, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopeng9736c522018-05-08 18:32:27233 SimulateAck(false);
234 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
235 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
236 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
237 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
238
239 // First inertial.
240 timestamp += base::TimeDelta::FromSeconds(1);
241 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00242 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27243 SimulateAck(true);
244 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
245 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
246 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
247 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
248
249 // Not cancel in 10ms.
250 timestamp += base::TimeDelta::FromMilliseconds(10);
251 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00252 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27253 SimulateAck(true);
254 EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
255 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
256 EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
257 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
258
259 // Cancel after 300ms.
260 timestamp += base::TimeDelta::FromMilliseconds(291);
261 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00262 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27263 SimulateAck(true);
264 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
265 EXPECT_EQ(OverscrollSource::NONE, controller_source());
266 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
267 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
268
269 // Next event should be ignored.
270 timestamp += base::TimeDelta::FromMilliseconds(100);
271 EXPECT_TRUE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00272 1, 0, blink::WebGestureDevice::kTouchpad, timestamp, true));
chaopeng9736c522018-05-08 18:32:27273}
274
Mohsen Izadi8c59ba52018-04-12 18:52:01275// Verifies that when pull-to-refresh is disabled, it is not triggered for
276// neither touchpad nor touchscreen.
277TEST_F(OverscrollControllerTest, PullToRefreshDisabled) {
278 ScopedPullToRefreshMode scoped_mode(
279 OverscrollConfig::PullToRefreshMode::kDisabled);
280
Daniel Cheng224569ee2018-04-25 05:45:06281 base::TimeTicks timestamp =
282 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19283
284 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00285 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19286 timestamp));
287 SimulateAck(false);
288
Mohsen Izadi8c59ba52018-04-12 18:52:01289 // Simulate a touchpad gesture scroll-update event that passes the start
290 // threshold and ACK it as not processed. Pull-to-refresh should not be
291 // triggered.
292 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00293 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01294 SimulateAck(false);
295 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
296 EXPECT_EQ(OverscrollSource::NONE, controller_source());
297 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
298 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
299
Daniel Cheng224569ee2018-04-25 05:45:06300 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19301
Mohsen Izadi8c59ba52018-04-12 18:52:01302 // Simulate a touchpad zero-velocity fling-start which would normally end
303 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Daniel Cheng7f9ec902019-04-18 05:07:00304 EXPECT_FALSE(SimulateGestureFlingStart(
305 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01306 SimulateAck(false);
307 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
308 EXPECT_EQ(OverscrollSource::NONE, controller_source());
309 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
310 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
311
Daniel Cheng224569ee2018-04-25 05:45:06312 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19313
314 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00315 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19316 timestamp));
317 SimulateAck(false);
318
Mohsen Izadi8c59ba52018-04-12 18:52:01319 // Simulate a touchscreen gesture scroll-update event that passes the start
320 // threshold and ACK it as not processed. Pull-to-refresh should not be
321 // triggered.
322 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00323 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01324 SimulateAck(false);
325 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
326 EXPECT_EQ(OverscrollSource::NONE, controller_source());
327 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
328 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
329
Daniel Cheng224569ee2018-04-25 05:45:06330 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19331
Mohsen Izadi8c59ba52018-04-12 18:52:01332 // Simulate a touchscreen gesture scroll-end which would normally end
333 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
334 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00335 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19336 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01337 SimulateAck(false);
338 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
339 EXPECT_EQ(OverscrollSource::NONE, controller_source());
340 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
341 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
342}
343
344// Verifies that when pull-to-refresh is enabled, it is triggered for both
345// touchpad and touchscreen.
346TEST_F(OverscrollControllerTest, PullToRefreshEnabled) {
347 ScopedPullToRefreshMode scoped_mode(
348 OverscrollConfig::PullToRefreshMode::kEnabled);
349
Daniel Cheng224569ee2018-04-25 05:45:06350 base::TimeTicks timestamp =
351 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19352
353 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00354 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19355 timestamp));
356 SimulateAck(false);
357
Mohsen Izadi8c59ba52018-04-12 18:52:01358 // Simulate a touchpad gesture scroll-update event that passes the start
359 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
360 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00361 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01362 SimulateAck(false);
363 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
364 EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
365 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
366 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
367
Daniel Cheng224569ee2018-04-25 05:45:06368 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19369
Mohsen Izadi8c59ba52018-04-12 18:52:01370 // Simulate a touchpad zero-velocity fling-start and ACK it as not processed..
371 // It should abort pull-to-refresh.
Daniel Cheng7f9ec902019-04-18 05:07:00372 EXPECT_FALSE(SimulateGestureFlingStart(
373 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01374 SimulateAck(false);
375 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
376 EXPECT_EQ(OverscrollSource::NONE, controller_source());
377 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
378 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
379
Daniel Cheng224569ee2018-04-25 05:45:06380 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19381
382 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00383 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19384 timestamp));
385 SimulateAck(false);
386
Mohsen Izadi8c59ba52018-04-12 18:52:01387 // Simulate a touchscreen gesture scroll-update event that passes the start
388 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
389 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00390 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01391 SimulateAck(false);
392 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
393 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
394 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
395 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
396
Daniel Cheng224569ee2018-04-25 05:45:06397 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19398
Mohsen Izadi8c59ba52018-04-12 18:52:01399 // Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
400 // should abort pull-to-refresh.
401 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00402 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19403 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01404 SimulateAck(false);
405 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
406 EXPECT_EQ(OverscrollSource::NONE, controller_source());
407 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
408 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
409}
410
411// Verifies that when pull-to-refresh is enabled only for touchscreen, it is
412// triggered for touchscreen but not for touchpad.
413TEST_F(OverscrollControllerTest, PullToRefreshEnabledTouchscreen) {
414 ScopedPullToRefreshMode scoped_mode(
415 OverscrollConfig::PullToRefreshMode::kEnabledTouchschreen);
416
Daniel Cheng224569ee2018-04-25 05:45:06417 base::TimeTicks timestamp =
418 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19419
420 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00421 blink::WebGestureDevice::kTouchpad,
Mohsen Izadi5a6583512018-04-23 18:31:19422 timestamp));
423 SimulateAck(false);
424
Mohsen Izadi8c59ba52018-04-12 18:52:01425 // Simulate a touchpad gesture scroll-update event that passes the start
426 // threshold and ACK it as not processed. Pull-to-refresh should not be
427 // triggered.
428 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00429 0, 80, blink::WebGestureDevice::kTouchpad, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01430 SimulateAck(false);
431 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
432 EXPECT_EQ(OverscrollSource::NONE, controller_source());
433 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
434 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
435
Daniel Cheng224569ee2018-04-25 05:45:06436 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19437
Mohsen Izadi8c59ba52018-04-12 18:52:01438 // Simulate a touchpad zero-velocity fling-start which would normally end
439 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
Daniel Cheng7f9ec902019-04-18 05:07:00440 EXPECT_FALSE(SimulateGestureFlingStart(
441 0, 0, blink::WebGestureDevice::kTouchpad, timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01442 SimulateAck(false);
443 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
444 EXPECT_EQ(OverscrollSource::NONE, controller_source());
445 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
446 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
447
Daniel Cheng224569ee2018-04-25 05:45:06448 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19449
450 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00451 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19452 timestamp));
453 SimulateAck(false);
454
Mohsen Izadi8c59ba52018-04-12 18:52:01455 // Simulate a touchscreen gesture scroll-update event that passes the start
456 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
457 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00458 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8c59ba52018-04-12 18:52:01459 SimulateAck(false);
460 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
461 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
462 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
463 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
464
Daniel Cheng224569ee2018-04-25 05:45:06465 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19466
Mohsen Izadi8c59ba52018-04-12 18:52:01467 // Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
468 // should abort pull-to-refresh.
469 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00470 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19471 timestamp));
Mohsen Izadi8c59ba52018-04-12 18:52:01472 SimulateAck(false);
473 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
474 EXPECT_EQ(OverscrollSource::NONE, controller_source());
475 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
476 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
477}
478
chaopengcd44c7622018-04-13 04:08:21479// Ensure disabling kTouchpadOverscrollHistoryNavigation will prevent overscroll
480// from touchpad.
481TEST_F(OverscrollControllerTest, DisableTouchpadOverscrollHistoryNavigation) {
482 base::test::ScopedFeatureList feature_list;
483 feature_list.InitAndDisableFeature(
484 features::kTouchpadOverscrollHistoryNavigation);
485 ASSERT_FALSE(OverscrollConfig::TouchpadOverscrollHistoryNavigationEnabled());
Mohsen Izadi5a6583512018-04-23 18:31:19486
Daniel Cheng224569ee2018-04-25 05:45:06487 const base::TimeTicks timestamp =
488 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19489
chaopengcd44c7622018-04-13 04:08:21490 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00491 200, 0, blink::WebGestureDevice::kTouchpad, timestamp, false));
chaopengcd44c7622018-04-13 04:08:21492 SimulateAck(false);
493
494 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
495 EXPECT_EQ(OverscrollSource::NONE, controller_source());
496 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
497 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
498}
499
Mohsen Izadi5a6583512018-04-23 18:31:19500// Verifies that if an overscroll happens before cool off period after a page
Mohsen Izadi8f43c2c52018-10-09 17:17:11501// scroll, it does not trigger pull-to-refresh. Verifies following sequence of
502// scrolls:
503// 1) Page scroll;
504// 2) Scroll before cool off -> PTR not triggered;
505// 3) Scroll before cool off -> PTR not triggered;
506// 4) Scroll after cool off -> PTR triggered;
507// 5) Scroll before cool off -> PTR triggered.
508TEST_F(OverscrollControllerTest, PullToRefreshBeforeCoolOff) {
Mohsen Izadi5a6583512018-04-23 18:31:19509 ScopedPullToRefreshMode scoped_mode(
510 OverscrollConfig::PullToRefreshMode::kEnabled);
511
Mohsen Izadi8f43c2c52018-10-09 17:17:11512 // 1) Page scroll.
Daniel Cheng224569ee2018-04-25 05:45:06513 base::TimeTicks timestamp =
514 blink::WebInputEvent::GetStaticTimeStampForTests();
Mohsen Izadi5a6583512018-04-23 18:31:19515
516 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00517 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19518 timestamp));
519 SimulateAck(false);
520
521 // Simulate a touchscreen gesture scroll-update event that passes the start
Mohsen Izadi8f43c2c52018-10-09 17:17:11522 // threshold and ACK it as processed. Pull-to-refresh should not be triggered.
Mohsen Izadi5a6583512018-04-23 18:31:19523 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00524 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi5a6583512018-04-23 18:31:19525 SimulateAck(true);
526 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
527 EXPECT_EQ(OverscrollSource::NONE, controller_source());
528 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
529 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
530
Daniel Cheng224569ee2018-04-25 05:45:06531 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19532
533 // Simulate a touchscreen gesture scroll-end which would normally end
534 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
535 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00536 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19537 timestamp));
538 SimulateAck(false);
539 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
540 EXPECT_EQ(OverscrollSource::NONE, controller_source());
541 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
542 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
543
Mohsen Izadi8f43c2c52018-10-09 17:17:11544 // 2) Scroll before cool off -> PTR not triggered.
545 timestamp += base::TimeDelta::FromMilliseconds(500);
Mohsen Izadi5a6583512018-04-23 18:31:19546
547 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00548 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19549 timestamp));
550 SimulateAck(false);
551
552 // Simulate a touchscreen gesture scroll-update event that passes the start
553 // threshold and ACK it as not processed. Pull-to-refresh should not be
554 // triggered.
555 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00556 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi5a6583512018-04-23 18:31:19557 SimulateAck(false);
558 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
559 EXPECT_EQ(OverscrollSource::NONE, controller_source());
560 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
561 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
562
Daniel Cheng224569ee2018-04-25 05:45:06563 timestamp += base::TimeDelta::FromSeconds(1);
Mohsen Izadi5a6583512018-04-23 18:31:19564
565 // Simulate a touchscreen gesture scroll-end which would normally end
566 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
567 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00568 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi5a6583512018-04-23 18:31:19569 timestamp));
570 SimulateAck(false);
571 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
572 EXPECT_EQ(OverscrollSource::NONE, controller_source());
573 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
574 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
Mohsen Izadi8f43c2c52018-10-09 17:17:11575
576 // 3) Scroll before cool off -> PTR not triggered.
577 timestamp += base::TimeDelta::FromMilliseconds(500);
578
579 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00580 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11581 timestamp));
582 SimulateAck(false);
583
584 // Simulate a touchscreen gesture scroll-update event that passes the start
585 // threshold and ACK it as not processed. Pull-to-refresh should not be
586 // triggered.
587 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00588 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11589 SimulateAck(false);
590 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
591 EXPECT_EQ(OverscrollSource::NONE, controller_source());
592 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
593 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
594
595 timestamp += base::TimeDelta::FromSeconds(1);
596
597 // Simulate a touchscreen gesture scroll-end which would normally end
598 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
599 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00600 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11601 timestamp));
602 SimulateAck(false);
603 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
604 EXPECT_EQ(OverscrollSource::NONE, controller_source());
605 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
606 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
607
608 // 4) Scroll after cool off -> PTR triggered.
609 timestamp += base::TimeDelta::FromSeconds(1);
610
611 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00612 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11613 timestamp));
614 SimulateAck(false);
615
616 // Simulate a touchscreen gesture scroll-update event that passes the start
617 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
618 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00619 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11620 SimulateAck(false);
621 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
622 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
623 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
624 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
625
626 timestamp += base::TimeDelta::FromSeconds(1);
627
628 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
629 // and ACK it as not processed. Pull-to-refresh should be aborted.
630 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00631 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11632 timestamp));
633 SimulateAck(false);
634 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
635 EXPECT_EQ(OverscrollSource::NONE, controller_source());
636 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
637 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
638
639 // 5) Scroll before cool off -> PTR triggered.
640 timestamp += base::TimeDelta::FromMilliseconds(500);
641
642 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00643 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11644 timestamp));
645 SimulateAck(false);
646
647 // Simulate a touchscreen gesture scroll-update event that passes the start
648 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
649 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00650 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11651 SimulateAck(false);
652 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
653 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
654 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
655 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
656
657 timestamp += base::TimeDelta::FromSeconds(1);
658
659 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
660 // and ACK it as not processed. Pull-to-refresh should be aborted.
661 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00662 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11663 timestamp));
664 SimulateAck(false);
665 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
666 EXPECT_EQ(OverscrollSource::NONE, controller_source());
667 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
668 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
669}
670
671// Verifies that if an overscroll happens after cool off period after a page
672// scroll, it triggers pull-to-refresh. Verifies the following sequence of
673// scrolls:
674// 1) Page scroll;
675// 2) Scroll after cool off -> PTR triggered;
676// 3) Scroll before cool off -> PTR triggered;
677TEST_F(OverscrollControllerTest, PullToRefreshAfterCoolOff) {
678 ScopedPullToRefreshMode scoped_mode(
679 OverscrollConfig::PullToRefreshMode::kEnabled);
680
681 // 1) Page scroll.
682 base::TimeTicks timestamp =
683 blink::WebInputEvent::GetStaticTimeStampForTests();
684
685 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00686 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11687 timestamp));
688 SimulateAck(false);
689
690 // Simulate a touchscreen gesture scroll-update event that passes the start
691 // threshold and ACK it as processed. Pull-to-refresh should not be triggered.
692 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00693 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11694 SimulateAck(true);
695 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
696 EXPECT_EQ(OverscrollSource::NONE, controller_source());
697 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
698 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
699
700 timestamp += base::TimeDelta::FromSeconds(1);
701
702 // Simulate a touchscreen gesture scroll-end which would normally end
703 // pull-to-refresh, and ACK it as not processed. Nothing should happen.
704 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00705 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11706 timestamp));
707 SimulateAck(false);
708 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
709 EXPECT_EQ(OverscrollSource::NONE, controller_source());
710 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
711 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
712
713 // 2) Scroll after cool off -> PTR triggered.
714 timestamp += base::TimeDelta::FromSeconds(1);
715
716 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00717 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11718 timestamp));
719 SimulateAck(false);
720
721 // Simulate a touchscreen gesture scroll-update event that passes the start
722 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
723 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00724 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11725 SimulateAck(false);
726 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
727 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
728 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
729 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
730
731 timestamp += base::TimeDelta::FromSeconds(1);
732
733 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
734 // and ACK it as not processed. Pull-to-refresh should be aborted.
735 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00736 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11737 timestamp));
738 SimulateAck(false);
739 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
740 EXPECT_EQ(OverscrollSource::NONE, controller_source());
741 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
742 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
743
744 // 3) Scroll before cool off -> PTR triggered.
745 timestamp += base::TimeDelta::FromMilliseconds(500);
746
747 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
Daniel Cheng7f9ec902019-04-18 05:07:00748 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11749 timestamp));
750 SimulateAck(false);
751
752 // Simulate a touchscreen gesture scroll-update event that passes the start
753 // threshold and ACK it as not processed. Pull-to-refresh should be triggered.
754 EXPECT_FALSE(SimulateGestureScrollUpdate(
Daniel Cheng7f9ec902019-04-18 05:07:00755 0, 80, blink::WebGestureDevice::kTouchscreen, timestamp, false));
Mohsen Izadi8f43c2c52018-10-09 17:17:11756 SimulateAck(false);
757 EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
758 EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
759 EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
760 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
761
762 timestamp += base::TimeDelta::FromSeconds(1);
763
764 // Simulate a touchscreen gesture scroll-end which will end pull-to-refresh,
765 // and ACK it as not processed. Pull-to-refresh should be aborted.
766 EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
Daniel Cheng7f9ec902019-04-18 05:07:00767 blink::WebGestureDevice::kTouchscreen,
Mohsen Izadi8f43c2c52018-10-09 17:17:11768 timestamp));
769 SimulateAck(false);
770 EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
771 EXPECT_EQ(OverscrollSource::NONE, controller_source());
772 EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
773 EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
Mohsen Izadi5a6583512018-04-23 18:31:19774}
775
Mohsen Izadi9830436c2017-12-21 18:02:46776} // namespace content