Commit dfa0e9b4 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Reland "Batch BottomSheetControllerTests"

This is a reland of 3c8430ae

This patch adds a check for the currently running animation. Animations
on Android M seem to continue for a few updates after cancellation.

Original change's description:
> Batch BottomSheetControllerTests
>
> This patch batches all the tests in BottomSheetControllerTest.
> Consequently, some new methods to reset the sheet's state were added
> to the test support classes and BlankCTATabInitialState was updated to
> support any subclass of ChromeActivity.
>
> Bug: 1122163
> Change-Id: I3fbb73431eff206010d93d8c5e26e4942b84adb8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2377664
> Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
> Commit-Queue: Matthew Jones <mdjones@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#803156}

Bug: 1122163
Change-Id: I2b562243eb50b7990fa82bd9d353c8d1f16589cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387433Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804935}
parent fd60c6af
...@@ -22,11 +22,13 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -22,11 +22,13 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
* *
* State is stored statically, and so the Activity may be reused across multiple test suites within * State is stored statically, and so the Activity may be reused across multiple test suites within
* the same {@link Batch}. * the same {@link Batch}.
*
* @param <T> The type of {@link ChromeActivity}.
*/ */
public class BlankCTATabInitialStateRule implements TestRule { public class BlankCTATabInitialStateRule<T extends ChromeActivity> implements TestRule {
private static ChromeActivity sActivity; private static ChromeActivity sActivity;
private final ChromeActivityTestRule<ChromeActivity> mActivityTestRule; private final ChromeActivityTestRule<T> mActivityTestRule;
private final boolean mClearAllTabState; private final boolean mClearAllTabState;
/** /**
...@@ -35,7 +37,7 @@ public class BlankCTATabInitialStateRule implements TestRule { ...@@ -35,7 +37,7 @@ public class BlankCTATabInitialStateRule implements TestRule {
* renderer process between each test. * renderer process between each test.
*/ */
public BlankCTATabInitialStateRule( public BlankCTATabInitialStateRule(
ChromeActivityTestRule<ChromeActivity> activityTestRule, boolean clearAllTabState) { ChromeActivityTestRule<T> activityTestRule, boolean clearAllTabState) {
super(); super();
mActivityTestRule = activityTestRule; mActivityTestRule = activityTestRule;
mClearAllTabState = clearAllTabState; mClearAllTabState = clearAllTabState;
...@@ -52,7 +54,7 @@ public class BlankCTATabInitialStateRule implements TestRule { ...@@ -52,7 +54,7 @@ public class BlankCTATabInitialStateRule implements TestRule {
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
sActivity = mActivityTestRule.getActivity(); sActivity = mActivityTestRule.getActivity();
} else { } else {
mActivityTestRule.setActivity(sActivity); mActivityTestRule.setActivity((T) sActivity);
if (mClearAllTabState) { if (mClearAllTabState) {
resetTabStateThorough(); resetTabStateThorough();
} else { } else {
......
...@@ -609,6 +609,9 @@ class BottomSheet extends FrameLayout ...@@ -609,6 +609,9 @@ class BottomSheet extends FrameLayout
mSettleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { mSettleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override @Override
public void onAnimationUpdate(ValueAnimator animator) { public void onAnimationUpdate(ValueAnimator animator) {
// Cancelled animation on M seem to continue updating, block them.
if (animator != mSettleAnimator) return;
setSheetOffsetFromBottom((Float) animator.getAnimatedValue(), reason); setSheetOffsetFromBottom((Float) animator.getAnimatedValue(), reason);
} }
}); });
......
...@@ -367,6 +367,14 @@ class BottomSheetControllerImpl implements ManagedBottomSheetController { ...@@ -367,6 +367,14 @@ class BottomSheetControllerImpl implements ManagedBottomSheetController {
mBottomSheet.endAnimations(); mBottomSheet.endAnimations();
} }
@VisibleForTesting
public void forceDismissAllContent() {
clearRequestsAndHide();
// Handle content that has a custom lifecycle.
hideContent(mBottomSheet.getCurrentSheetContent(), /* animate= */ true);
}
@Override @Override
public boolean requestShowContent(BottomSheetContent content, boolean animate) { public boolean requestShowContent(BottomSheetContent content, boolean animate) {
if (mBottomSheet == null) mSheetInitializer.run(); if (mBottomSheet == null) mSheetInitializer.run();
......
...@@ -41,7 +41,7 @@ public class BottomSheetTestSupport { ...@@ -41,7 +41,7 @@ public class BottomSheetTestSupport {
/** End all animations on the sheet for testing purposes. */ /** End all animations on the sheet for testing purposes. */
public void endAllAnimations() { public void endAllAnimations() {
mController.endAnimationsForTesting(); if (getBottomSheet() != null) mController.endAnimationsForTesting();
} }
/** @see {@link BottomSheet#setSheetOffsetFromBottom(float, int)} */ /** @see {@link BottomSheet#setSheetOffsetFromBottom(float, int)} */
...@@ -99,6 +99,11 @@ public class BottomSheetTestSupport { ...@@ -99,6 +99,11 @@ public class BottomSheetTestSupport {
return getBottomSheet().forceScrollingStateForTesting(sheetHeight, yVelocity); return getBottomSheet().forceScrollingStateForTesting(sheetHeight, yVelocity);
} }
/** Dismiss all content currently queued in the controller including custom lifecycles. */
public void forceDismissAllContent() {
mController.forceDismissAllContent();
}
/** @return The bottom sheet view. */ /** @return The bottom sheet view. */
private BottomSheet getBottomSheet() { private BottomSheet getBottomSheet() {
return (BottomSheet) mController.getBottomSheetViewForTesting(); return (BottomSheet) mController.getBottomSheetViewForTesting();
......
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