Commit 3c8430ae authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

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/+/2377664Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803156}
parent 20c16d94
......@@ -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
* 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 final ChromeActivityTestRule<ChromeActivity> mActivityTestRule;
private final ChromeActivityTestRule<T> mActivityTestRule;
private final boolean mClearAllTabState;
/**
......@@ -35,7 +37,7 @@ public class BlankCTATabInitialStateRule implements TestRule {
* renderer process between each test.
*/
public BlankCTATabInitialStateRule(
ChromeActivityTestRule<ChromeActivity> activityTestRule, boolean clearAllTabState) {
ChromeActivityTestRule<T> activityTestRule, boolean clearAllTabState) {
super();
mActivityTestRule = activityTestRule;
mClearAllTabState = clearAllTabState;
......@@ -52,7 +54,7 @@ public class BlankCTATabInitialStateRule implements TestRule {
mActivityTestRule.startMainActivityOnBlankPage();
sActivity = mActivityTestRule.getActivity();
} else {
mActivityTestRule.setActivity(sActivity);
mActivityTestRule.setActivity((T) sActivity);
if (mClearAllTabState) {
resetTabStateThorough();
} else {
......
......@@ -367,6 +367,14 @@ class BottomSheetControllerImpl implements ManagedBottomSheetController {
mBottomSheet.endAnimations();
}
@VisibleForTesting
public void forceDismissAllContent() {
clearRequestsAndHide();
// Handle content that has a custom lifecycle.
hideContent(mBottomSheet.getCurrentSheetContent(), /* animate= */ true);
}
@Override
public boolean requestShowContent(BottomSheetContent content, boolean animate) {
if (mBottomSheet == null) mSheetInitializer.run();
......
......@@ -99,6 +99,11 @@ public class BottomSheetTestSupport {
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. */
private BottomSheet getBottomSheet() {
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