Commit ea6373d1 authored by Robbie Gibson's avatar Robbie Gibson Committed by Chromium LUCI CQ

[iOS][Thumb Strip] Add unit test for conflicting gestures

This test makes sure that the ViewRevealingVerticalPanHandler can handle
two gestures at once. Specifically, if a second gesture is received
while processing a first gesture, the second gesture is ignored.

Bug: 1161209
Change-Id: I2b4f4ea1553e2cc11a51a6430485ecb900ac9d5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2632692Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Cr-Commit-Position: refs/heads/master@{#844725}
parent 4bbd4978
......@@ -137,6 +137,10 @@ void SimulatePanGesture(ViewRevealingVerticalPanHandler* pan_handler,
initWithTarget:pan_handler
action:@selector(handlePanGesture:)];
if (![pan_handler gestureRecognizerShouldBegin:fake_gesture_recognizer]) {
return;
}
fake_gesture_recognizer.state = UIGestureRecognizerStateBegan;
[pan_handler handlePanGesture:fake_gesture_recognizer];
fake_gesture_recognizer.state = UIGestureRecognizerStateChanged;
......@@ -145,7 +149,7 @@ void SimulatePanGesture(ViewRevealingVerticalPanHandler* pan_handler,
fake_gesture_recognizer.translation = CGPointMake(0, translation_y + offset);
fake_gesture_recognizer.state = UIGestureRecognizerStateEnded;
[pan_handler handlePanGesture:fake_gesture_recognizer];
// The runloop needs to be spun between the end of a gesture and the beggining
// The runloop needs to be spun between the end of a gesture and the begining
// of another one, because the current state of the pan_handler needs to be
// updated to its next state before starting a new transition.
base::test::ios::SpinRunLoopWithMinDelay(
......@@ -230,4 +234,62 @@ TEST_F(ViewRevealingVerticalPanHandlerTest, ManualStateChange) {
EXPECT_EQ(ViewRevealState::Hidden, fake_animatee.state);
EXPECT_EQ(LayoutSwitcherState::Horizontal, fake_layout_switcher.state);
}
// Tests that a second gesture does not interrupt the first gesture.
TEST_F(ViewRevealingVerticalPanHandlerTest, ConflictingGestures) {
// Create a view revealing vertical pan handler.
ViewRevealingVerticalPanHandler* pan_handler =
[[ViewRevealingVerticalPanHandler alloc]
initWithPeekedHeight:kThumbStripHeight
revealedCoverHeight:kBVCHeightTabGrid
baseViewHeight:kBaseViewHeight];
// Create a fake animatee.
FakeAnimatee* fake_animatee = [[FakeAnimatee alloc] init];
[pan_handler addAnimatee:fake_animatee];
EXPECT_EQ(ViewRevealState::Hidden, fake_animatee.state);
// Scroll down to transition to Peeked state.
SimulatePanGesture(pan_handler, kThumbStripHeight * kRevealThreshold);
EXPECT_EQ(ViewRevealState::Peeked, fake_animatee.state);
// Start a gesture moving further down.
FakeGestureRecognizer* fake_gesture_recognizer =
[[FakeGestureRecognizer alloc]
initWithTarget:pan_handler
action:@selector(handlePanGesture:)];
EXPECT_TRUE(
[pan_handler gestureRecognizerShouldBegin:fake_gesture_recognizer]);
fake_gesture_recognizer.state = UIGestureRecognizerStateBegan;
[pan_handler handlePanGesture:fake_gesture_recognizer];
fake_gesture_recognizer.state = UIGestureRecognizerStateChanged;
fake_gesture_recognizer.translation = CGPointMake(0, kSmallOffset);
// Start and finish a second gesture moving back up to Hidden.
SimulatePanGesture(pan_handler, -(kThumbStripHeight * kRevealThreshold));
// This second gesture should NOT change the state back to Hidden.
EXPECT_NE(ViewRevealState::Hidden, fake_animatee.state);
// Start and finish a second gesture moving down to Revealed.
double remaining_height = kBaseViewHeight - kBVCHeightTabGrid;
SimulatePanGesture(pan_handler, remaining_height * kRevealThreshold);
// This second gesture should NOT change the state to Revealed.
EXPECT_NE(ViewRevealState::Revealed, fake_animatee.state);
// Finish the ongoing gesture down to Revealed. This should change the state
// to revealed.
fake_gesture_recognizer.state = UIGestureRecognizerStateChanged;
fake_gesture_recognizer.translation = CGPointMake(0, remaining_height);
fake_gesture_recognizer.state = UIGestureRecognizerStateEnded;
[pan_handler handlePanGesture:fake_gesture_recognizer];
// The runloop needs to be spun between the end of a gesture and the begining
// of another one, because the current state of the pan_handler needs to be
// updated to its next state before starting a new transition.
base::test::ios::SpinRunLoopWithMinDelay(
base::TimeDelta::FromMilliseconds(kAnimationDelay));
EXPECT_NE(ViewRevealState::Revealed, fake_animatee.state);
}
} // namespace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment