1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/renderer_host/overscroll_controller.h"
#include <memory>
#include "base/containers/queue.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/renderer_host/overscroll_controller_delegate.h"
#include "content/common/input/synthetic_web_input_event_builders.h"
#include "content/public/browser/overscroll_configuration.h"
#include "content/public/common/content_features.h"
#include "content/public/test/scoped_overscroll_modes.h"
#include "content/test/test_overscroll_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_input_event.h"
namespace content {
class OverscrollControllerTest : public ::testing::Test {
protected:
OverscrollControllerTest() {}
~OverscrollControllerTest() override {}
void SetUp() override {
OverscrollConfig::ResetTouchpadOverscrollHistoryNavigationEnabled();
scoped_feature_list_.InitAndEnableFeature(
features::kTouchpadOverscrollHistoryNavigation);
delegate_ = std::make_unique<TestOverscrollDelegate>(gfx::Size(400, 300));
controller_ = std::make_unique<OverscrollController>();
controller_->set_delegate(delegate_.get());
}
void TearDown() override {
controller_ = nullptr;
delegate_ = nullptr;
}
// Creates and sends a mouse-wheel event to the overscroll controller. Returns
// |true| if the event is consumed by the overscroll controller.
bool SimulateMouseWheel(float dx, float dy) {
DCHECK(!current_event_);
current_event_ = std::make_unique<blink::WebMouseWheelEvent>(
SyntheticWebMouseWheelEventBuilder::Build(0, 0, dx, dy, 0, true));
return controller_->WillHandleEvent(*current_event_);
}
// Creates and sends a gesture event to the overscroll controller. Returns
// |true| if the event is consumed by the overscroll controller.
bool SimulateGestureEvent(blink::WebInputEvent::Type type,
blink::WebGestureDevice source_device,
base::TimeTicks timestamp) {
DCHECK(!current_event_);
current_event_ = std::make_unique<blink::WebGestureEvent>(
SyntheticWebGestureEventBuilder::Build(type, source_device));
current_event_->SetTimeStamp(timestamp);
return controller_->WillHandleEvent(*current_event_);
}
// Creates and sends a gesture-scroll-update event to the overscroll
// controller. Returns |true| if the event is consumed by the overscroll
// controller.
bool SimulateGestureScrollUpdate(float dx,
float dy,
blink::WebGestureDevice device,
base::TimeTicks timestamp,
bool inertial_update) {
DCHECK(!current_event_);
auto event = std::make_unique<blink::WebGestureEvent>(
SyntheticWebGestureEventBuilder::BuildScrollUpdate(dx, dy, 0, device));
event->SetTimeStamp(timestamp);
if (inertial_update) {
event->data.scroll_update.inertial_phase =
blink::WebGestureEvent::kMomentumPhase;
}
current_event_ = std::move(event);
return controller_->WillHandleEvent(*current_event_);
}
// Creates and sends a gesture-fling-start event to the overscroll controller.
// Returns |true| if the event is consumed by the overscroll controller.
bool SimulateGestureFlingStart(float velocity_x,
float velocity_y,
blink::WebGestureDevice device,
base::TimeTicks timestamp) {
DCHECK(!current_event_);
current_event_ = std::make_unique<blink::WebGestureEvent>(
SyntheticWebGestureEventBuilder::BuildFling(velocity_x, velocity_y,
device));
current_event_->SetTimeStamp(timestamp);
return controller_->WillHandleEvent(*current_event_);
}
// Notifies the overscroll controller that the current event is ACKed.
void SimulateAck(bool processed) {
DCHECK(current_event_);
controller_->ReceivedEventACK(*current_event_, processed);
current_event_ = nullptr;
}
TestOverscrollDelegate* delegate() const { return delegate_.get(); }
OverscrollMode controller_mode() const {
return controller_->overscroll_mode_;
}
OverscrollSource controller_source() const {
return controller_->overscroll_source_;
}
private:
std::unique_ptr<TestOverscrollDelegate> delegate_;
std::unique_ptr<OverscrollController> controller_;
// Keeps track of the last event that has been processed by the overscroll
// controller which is not yet ACKed. Will be null if no event is processed or
// the last event is ACKed.
std::unique_ptr<blink::WebInputEvent> current_event_;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(OverscrollControllerTest);
};
// Tests that if a mouse-wheel is consumed by content before overscroll is
// initiated, overscroll will not initiate anymore.
TEST_F(OverscrollControllerTest, MouseWheelConsumedPreventsOverscroll) {
const base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
// Simulate a mouse-wheel, ACK it as not processed, simulate the corresponding
// gesture scroll-update event, and ACK it as not processed. Since it is not
// passing the start threshold, no overscroll should happen.
EXPECT_FALSE(SimulateMouseWheel(10, 0));
SimulateAck(false);
EXPECT_FALSE(SimulateGestureScrollUpdate(
10, 0, blink::kWebGestureDeviceTouchpad, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
// Simulate a mouse-wheel and ACK it as processed. No gesture scroll-update
// needs to be simulated. Still no overscroll.
EXPECT_FALSE(SimulateMouseWheel(10, 0));
SimulateAck(true);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
// Simulate a mouse-wheel and the corresponding gesture scroll-update both
// ACKed as not processed. Although the scroll passes overscroll start
// threshold, no overscroll should happen since the previous mouse-wheel was
// marked as processed.
EXPECT_FALSE(SimulateMouseWheel(100, 0));
SimulateAck(false);
EXPECT_FALSE(SimulateGestureScrollUpdate(
100, 0, blink::kWebGestureDeviceTouchpad, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
}
// Verifying the inertial scroll event completes overscroll. After that we will
// ignore the following inertial scroll events until new sequence start.
TEST_F(OverscrollControllerTest,
InertialGestureScrollUpdateCompletesOverscroll) {
const base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchpad,
timestamp));
SimulateAck(false);
EXPECT_FALSE(SimulateGestureScrollUpdate(
200, 0, blink::kWebGestureDeviceTouchpad, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
// Inertial update event complete the overscroll action.
EXPECT_FALSE(SimulateGestureScrollUpdate(
100, 0, blink::kWebGestureDeviceTouchpad, timestamp, true));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_EAST, delegate()->completed_mode());
// Next Inertial update event would be consumed by overscroll controller.
EXPECT_TRUE(SimulateGestureScrollUpdate(
100, 0, blink::kWebGestureDeviceTouchpad, timestamp, true));
}
// Ensure inertial gesture scroll update can not start overscroll.
TEST_F(OverscrollControllerTest, InertialGSUsDoNotStartOverscroll) {
base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
// Inertial update event complete the overscroll action.
EXPECT_FALSE(SimulateGestureScrollUpdate(
100, 0, blink::kWebGestureDeviceTouchpad, timestamp, true));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
}
// After 300ms inertial gesture scroll updates, overscroll must get cancelled
// if not completed.
TEST_F(OverscrollControllerTest, OnlyProcessLimitedInertialGSUEvents) {
base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchpad,
timestamp));
SimulateAck(false);
EXPECT_FALSE(SimulateGestureScrollUpdate(
61, 0, blink::kWebGestureDeviceTouchpad, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
// First inertial.
timestamp += base::TimeDelta::FromSeconds(1);
EXPECT_TRUE(SimulateGestureScrollUpdate(
1, 0, blink::kWebGestureDeviceTouchpad, timestamp, true));
SimulateAck(true);
EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
// Not cancel in 10ms.
timestamp += base::TimeDelta::FromMilliseconds(10);
EXPECT_TRUE(SimulateGestureScrollUpdate(
1, 0, blink::kWebGestureDeviceTouchpad, timestamp, true));
SimulateAck(true);
EXPECT_EQ(OVERSCROLL_EAST, controller_mode());
EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
EXPECT_EQ(OVERSCROLL_EAST, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
// Cancel after 300ms.
timestamp += base::TimeDelta::FromMilliseconds(291);
EXPECT_TRUE(SimulateGestureScrollUpdate(
1, 0, blink::kWebGestureDeviceTouchpad, timestamp, true));
SimulateAck(true);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
// Next event should be ignored.
timestamp += base::TimeDelta::FromMilliseconds(100);
EXPECT_TRUE(SimulateGestureScrollUpdate(
1, 0, blink::kWebGestureDeviceTouchpad, timestamp, true));
}
// Verifies that when pull-to-refresh is disabled, it is not triggered for
// neither touchpad nor touchscreen.
TEST_F(OverscrollControllerTest, PullToRefreshDisabled) {
ScopedPullToRefreshMode scoped_mode(
OverscrollConfig::PullToRefreshMode::kDisabled);
base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchpad,
timestamp));
SimulateAck(false);
// Simulate a touchpad gesture scroll-update event that passes the start
// threshold and ACK it as not processed. Pull-to-refresh should not be
// triggered.
EXPECT_FALSE(SimulateGestureScrollUpdate(
0, 80, blink::kWebGestureDeviceTouchpad, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
// Simulate a touchpad zero-velocity fling-start which would normally end
// pull-to-refresh, and ACK it as not processed. Nothing should happen.
EXPECT_FALSE(SimulateGestureFlingStart(0, 0, blink::kWebGestureDeviceTouchpad,
timestamp));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
// Simulate a touchscreen gesture scroll-update event that passes the start
// threshold and ACK it as not processed. Pull-to-refresh should not be
// triggered.
EXPECT_FALSE(SimulateGestureScrollUpdate(
0, 80, blink::kWebGestureDeviceTouchscreen, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
// Simulate a touchscreen gesture scroll-end which would normally end
// pull-to-refresh, and ACK it as not processed. Nothing should happen.
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
}
// Verifies that when pull-to-refresh is enabled, it is triggered for both
// touchpad and touchscreen.
TEST_F(OverscrollControllerTest, PullToRefreshEnabled) {
ScopedPullToRefreshMode scoped_mode(
OverscrollConfig::PullToRefreshMode::kEnabled);
base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchpad,
timestamp));
SimulateAck(false);
// Simulate a touchpad gesture scroll-update event that passes the start
// threshold and ACK it as not processed. Pull-to-refresh should be triggered.
EXPECT_FALSE(SimulateGestureScrollUpdate(
0, 80, blink::kWebGestureDeviceTouchpad, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
EXPECT_EQ(OverscrollSource::TOUCHPAD, controller_source());
EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
// Simulate a touchpad zero-velocity fling-start and ACK it as not processed..
// It should abort pull-to-refresh.
EXPECT_FALSE(SimulateGestureFlingStart(0, 0, blink::kWebGestureDeviceTouchpad,
timestamp));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
// Simulate a touchscreen gesture scroll-update event that passes the start
// threshold and ACK it as not processed. Pull-to-refresh should be triggered.
EXPECT_FALSE(SimulateGestureScrollUpdate(
0, 80, blink::kWebGestureDeviceTouchscreen, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
// Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
// should abort pull-to-refresh.
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
}
// Verifies that when pull-to-refresh is enabled only for touchscreen, it is
// triggered for touchscreen but not for touchpad.
TEST_F(OverscrollControllerTest, PullToRefreshEnabledTouchscreen) {
ScopedPullToRefreshMode scoped_mode(
OverscrollConfig::PullToRefreshMode::kEnabledTouchschreen);
base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchpad,
timestamp));
SimulateAck(false);
// Simulate a touchpad gesture scroll-update event that passes the start
// threshold and ACK it as not processed. Pull-to-refresh should not be
// triggered.
EXPECT_FALSE(SimulateGestureScrollUpdate(
0, 80, blink::kWebGestureDeviceTouchpad, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
// Simulate a touchpad zero-velocity fling-start which would normally end
// pull-to-refresh, and ACK it as not processed. Nothing should happen.
EXPECT_FALSE(SimulateGestureFlingStart(0, 0, blink::kWebGestureDeviceTouchpad,
timestamp));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
// Simulate a touchscreen gesture scroll-update event that passes the start
// threshold and ACK it as not processed. Pull-to-refresh should be triggered.
EXPECT_FALSE(SimulateGestureScrollUpdate(
0, 80, blink::kWebGestureDeviceTouchscreen, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_SOUTH, controller_mode());
EXPECT_EQ(OverscrollSource::TOUCHSCREEN, controller_source());
EXPECT_EQ(OVERSCROLL_SOUTH, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
// Simulate a touchscreen gesture scroll-end and ACK it as not processed. It
// should abort pull-to-refresh.
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
}
// Ensure disabling kTouchpadOverscrollHistoryNavigation will prevent overscroll
// from touchpad.
TEST_F(OverscrollControllerTest, DisableTouchpadOverscrollHistoryNavigation) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(
features::kTouchpadOverscrollHistoryNavigation);
ASSERT_FALSE(OverscrollConfig::TouchpadOverscrollHistoryNavigationEnabled());
const base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
EXPECT_FALSE(SimulateGestureScrollUpdate(
200, 0, blink::kWebGestureDeviceTouchpad, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
}
// Verifies that if an overscroll happens before cool off period after a page
// scroll, it does not trigger pull-to-refresh.
TEST_F(OverscrollControllerTest, PullToRefreshCoolOff) {
ScopedPullToRefreshMode scoped_mode(
OverscrollConfig::PullToRefreshMode::kEnabled);
base::TimeTicks timestamp =
blink::WebInputEvent::GetStaticTimeStampForTests();
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
// Simulate a touchscreen gesture scroll-update event that passes the start
// threshold and ACK it as not processed. Pull-to-refresh should not be
// triggered.
EXPECT_FALSE(SimulateGestureScrollUpdate(
0, 80, blink::kWebGestureDeviceTouchscreen, timestamp, false));
SimulateAck(true);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
// Simulate a touchscreen gesture scroll-end which would normally end
// pull-to-refresh, and ACK it as not processed. Nothing should happen.
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
// Next scroll should happen before cool off period is finished, so that it
// does not trigger pull-to-refresh.
timestamp += base::TimeDelta::FromSecondsD(0.5);
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollBegin,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
// Simulate a touchscreen gesture scroll-update event that passes the start
// threshold and ACK it as not processed. Pull-to-refresh should not be
// triggered.
EXPECT_FALSE(SimulateGestureScrollUpdate(
0, 80, blink::kWebGestureDeviceTouchscreen, timestamp, false));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
timestamp += base::TimeDelta::FromSeconds(1);
// Simulate a touchscreen gesture scroll-end which would normally end
// pull-to-refresh, and ACK it as not processed. Nothing should happen.
EXPECT_FALSE(SimulateGestureEvent(blink::WebInputEvent::kGestureScrollEnd,
blink::kWebGestureDeviceTouchscreen,
timestamp));
SimulateAck(false);
EXPECT_EQ(OVERSCROLL_NONE, controller_mode());
EXPECT_EQ(OverscrollSource::NONE, controller_source());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, delegate()->completed_mode());
}
} // namespace content
|