Commit d17ece3a authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

Revert "Batch BottomSheetControllerTests"

This reverts commit 3c8430ae.

Reason for revert:
https://ci.chromium.org/p/chromium/builders/ci/android-marshmallow-x86-rel/1133

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}

TBR=mthiesse@chromium.org,mdjones@chromium.org

Change-Id: I41a36c86f34d947b69e00a92109f56f0bfcda760
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1122163
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386500Reviewed-by: default avatarGang Wu <gangwu@chromium.org>
Commit-Queue: Gang Wu <gangwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803346}
parent 590567c5
...@@ -15,15 +15,12 @@ import android.view.View; ...@@ -15,15 +15,12 @@ import android.view.View;
import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
...@@ -38,7 +35,6 @@ import org.chromium.chrome.browser.tab.TabSelectionType; ...@@ -38,7 +35,6 @@ import org.chromium.chrome.browser.tab.TabSelectionType;
import org.chromium.chrome.browser.tabmodel.TabModelObserver; import org.chromium.chrome.browser.tabmodel.TabModelObserver;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule; import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent; import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController; import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
...@@ -61,17 +57,9 @@ import java.util.concurrent.TimeoutException; ...@@ -61,17 +57,9 @@ import java.util.concurrent.TimeoutException;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) @CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) // TODO(mdjones): Remove this (crbug.com/837838). @Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) // TODO(mdjones): Remove this (crbug.com/837838).
@Batch(Batch.PER_CLASS)
public class BottomSheetControllerTest { public class BottomSheetControllerTest {
@ClassRule
public static final ChromeTabbedActivityTestRule sActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule @Rule
public final BlankCTATabInitialStateRule mIninialStateRule = public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
new BlankCTATabInitialStateRule(sActivityTestRule, false);
private ChromeTabbedActivity mActivity;
private BottomSheetController mSheetController; private BottomSheetController mSheetController;
private BottomSheetTestSupport mTestSupport; private BottomSheetTestSupport mTestSupport;
...@@ -84,42 +72,35 @@ public class BottomSheetControllerTest { ...@@ -84,42 +72,35 @@ public class BottomSheetControllerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mActivity = sActivityTestRule.getActivity(); mActivityTestRule.startMainActivityOnBlankPage();
final ChromeTabbedActivity activity = mActivityTestRule.getActivity();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
BottomSheetTestSupport.setSmallScreen(false); BottomSheetTestSupport.setSmallScreen(false);
mScrimCoordinator = mScrimCoordinator = mActivityTestRule.getActivity()
mActivity.getRootUiCoordinatorForTesting().getScrimCoordinatorForTesting(); .getRootUiCoordinatorForTesting()
.getScrimCoordinatorForTesting();
mScrimCoordinator.disableAnimationForTesting(true); mScrimCoordinator.disableAnimationForTesting(true);
mSheetController = mSheetController = activity.getRootUiCoordinatorForTesting().getBottomSheetController();
mActivity.getRootUiCoordinatorForTesting().getBottomSheetController();
mTestSupport = new BottomSheetTestSupport(mSheetController); mTestSupport = new BottomSheetTestSupport(mSheetController);
mLowPriorityContent = new TestBottomSheetContent( mLowPriorityContent = new TestBottomSheetContent(
mActivity, BottomSheetContent.ContentPriority.LOW, false); mActivityTestRule.getActivity(), BottomSheetContent.ContentPriority.LOW, false);
mHighPriorityContent = new TestBottomSheetContent( mHighPriorityContent = new TestBottomSheetContent(mActivityTestRule.getActivity(),
mActivity, BottomSheetContent.ContentPriority.HIGH, false); BottomSheetContent.ContentPriority.HIGH, false);
mBackInterceptingContent = new TestBottomSheetContent( mBackInterceptingContent = new TestBottomSheetContent(
mActivity, BottomSheetContent.ContentPriority.LOW, false); mActivityTestRule.getActivity(), BottomSheetContent.ContentPriority.LOW, false);
mBackInterceptingContent.setHandleBackPress(true); mBackInterceptingContent.setHandleBackPress(true);
mPeekableContent = new TestBottomSheetContent(mActivity); mPeekableContent = new TestBottomSheetContent(mActivityTestRule.getActivity());
mNonPeekableContent = new TestBottomSheetContent(mActivity); mNonPeekableContent = new TestBottomSheetContent(mActivityTestRule.getActivity());
mNonPeekableContent.setPeekHeight(BottomSheetContent.HeightMode.DISABLED); mNonPeekableContent.setPeekHeight(BottomSheetContent.HeightMode.DISABLED);
}); });
} }
@After
public void tearDown() {
ThreadUtils.runOnUiThreadBlocking(() -> {
mTestSupport.forceDismissAllContent();
mTestSupport.endAllAnimations();
});
}
@Test @Test
@SmallTest @SmallTest
@Feature({"BottomSheetController"}) @Feature({"BottomSheetController"})
...@@ -225,21 +206,22 @@ public class BottomSheetControllerTest { ...@@ -225,21 +206,22 @@ public class BottomSheetControllerTest {
@Feature({"BottomSheetController"}) @Feature({"BottomSheetController"})
public void testSheetHiddenAfterTabSwitcher() throws TimeoutException { public void testSheetHiddenAfterTabSwitcher() throws TimeoutException {
// Open a second tab and then reselect the original activity tab. // Open a second tab and then reselect the original activity tab.
Tab tab1 = mActivity.getActivityTab(); Tab tab1 = mActivityTestRule.getActivity().getActivityTab();
openNewTabInForeground(); ChromeTabUtils.newTabFromMenu(
Tab tab2 = mActivity.getActivityTab(); InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
Tab tab2 = mActivityTestRule.getActivity().getActivityTab();
requestContentInSheet(mLowPriorityContent, true); requestContentInSheet(mLowPriorityContent, true);
// Enter the tab switcher and select a different tab. // Enter the tab switcher and select a different tab.
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
mActivity.getLayoutManager().showOverview(false); mActivityTestRule.getActivity().getLayoutManager().showOverview(false);
mTestSupport.endAllAnimations(); mTestSupport.endAllAnimations();
assertEquals("The bottom sheet should be hidden.", assertEquals("The bottom sheet should be hidden.",
BottomSheetController.SheetState.HIDDEN, mSheetController.getSheetState()); BottomSheetController.SheetState.HIDDEN, mSheetController.getSheetState());
mActivity.getTabModelSelector().getCurrentModel().setIndex( mActivityTestRule.getActivity().getTabModelSelector().getCurrentModel().setIndex(
0, TabSelectionType.FROM_USER); 0, TabSelectionType.FROM_USER);
mActivity.getLayoutManager().hideOverview(false); mActivityTestRule.getActivity().getLayoutManager().hideOverview(false);
mTestSupport.endAllAnimations(); mTestSupport.endAllAnimations();
}); });
...@@ -304,8 +286,9 @@ public class BottomSheetControllerTest { ...@@ -304,8 +286,9 @@ public class BottomSheetControllerTest {
@MediumTest @MediumTest
@Feature({"BottomSheetController"}) @Feature({"BottomSheetController"})
public void testSwitchTabsMultipleTimes() throws TimeoutException { public void testSwitchTabsMultipleTimes() throws TimeoutException {
final int originalTabIndex = mActivity.getTabModelSelector().getCurrentModel().indexOf( ChromeTabbedActivity activity = mActivityTestRule.getActivity();
mActivity.getActivityTab()); final int originalTabIndex =
activity.getTabModelSelector().getCurrentModel().indexOf(activity.getActivityTab());
requestContentInSheet(mLowPriorityContent, true); requestContentInSheet(mLowPriorityContent, true);
assertEquals("The bottom sheet should be peeking.", BottomSheetController.SheetState.PEEK, assertEquals("The bottom sheet should be peeking.", BottomSheetController.SheetState.PEEK,
...@@ -319,7 +302,7 @@ public class BottomSheetControllerTest { ...@@ -319,7 +302,7 @@ public class BottomSheetControllerTest {
mSheetController.getCurrentSheetContent()); mSheetController.getCurrentSheetContent());
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
mActivity.getTabModelSelector().getCurrentModel().setIndex( activity.getTabModelSelector().getCurrentModel().setIndex(
originalTabIndex, TabSelectionType.FROM_USER); originalTabIndex, TabSelectionType.FROM_USER);
}); });
...@@ -341,14 +324,14 @@ public class BottomSheetControllerTest { ...@@ -341,14 +324,14 @@ public class BottomSheetControllerTest {
requestContentInSheet(mHighPriorityContent, true); requestContentInSheet(mHighPriorityContent, true);
requestContentInSheet(mLowPriorityContent, false); requestContentInSheet(mLowPriorityContent, false);
TestBottomSheetContent customLifecycleContent = TestBottomSheetContent customLifecycleContent = new TestBottomSheetContent(
new TestBottomSheetContent(mActivity, BottomSheetContent.ContentPriority.LOW, true); mActivityTestRule.getActivity(), BottomSheetContent.ContentPriority.LOW, true);
requestContentInSheet(customLifecycleContent, false); requestContentInSheet(customLifecycleContent, false);
assertEquals(mHighPriorityContent, mSheetController.getCurrentSheetContent()); assertEquals(mHighPriorityContent, mSheetController.getCurrentSheetContent());
// Change URL and wait for PageLoadStarted event. // Change URL and wait for PageLoadStarted event.
CallbackHelper pageLoadStartedHelper = new CallbackHelper(); CallbackHelper pageLoadStartedHelper = new CallbackHelper();
Tab tab = mActivity.getActivityTab(); Tab tab = mActivityTestRule.getActivity().getActivityTab();
tab.addObserver(new EmptyTabObserver() { tab.addObserver(new EmptyTabObserver() {
@Override @Override
public void onPageLoadStarted(Tab tab, String url) { public void onPageLoadStarted(Tab tab, String url) {
...@@ -384,8 +367,8 @@ public class BottomSheetControllerTest { ...@@ -384,8 +367,8 @@ public class BottomSheetControllerTest {
@Test @Test
@MediumTest @MediumTest
public void testCustomScrimLifecycle() throws TimeoutException { public void testCustomScrimLifecycle() throws TimeoutException {
TestBottomSheetContent customScrimContent = TestBottomSheetContent customScrimContent = new TestBottomSheetContent(
new TestBottomSheetContent(mActivity, BottomSheetContent.ContentPriority.LOW, true); mActivityTestRule.getActivity(), BottomSheetContent.ContentPriority.LOW, true);
customScrimContent.setHasCustomScrimLifecycle(true); customScrimContent.setHasCustomScrimLifecycle(true);
requestContentInSheet(customScrimContent, true); requestContentInSheet(customScrimContent, true);
...@@ -624,11 +607,11 @@ public class BottomSheetControllerTest { ...@@ -624,11 +607,11 @@ public class BottomSheetControllerTest {
*/ */
private void enterAndExitTabSwitcher() { private void enterAndExitTabSwitcher() {
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
mActivity.getLayoutManager().showOverview(false); mActivityTestRule.getActivity().getLayoutManager().showOverview(false);
mTestSupport.endAllAnimations(); mTestSupport.endAllAnimations();
assertEquals("The bottom sheet should be hidden.", assertEquals("The bottom sheet should be hidden.",
BottomSheetController.SheetState.HIDDEN, mSheetController.getSheetState()); BottomSheetController.SheetState.HIDDEN, mSheetController.getSheetState());
mActivity.getLayoutManager().hideOverview(false); mActivityTestRule.getActivity().getLayoutManager().hideOverview(false);
mTestSupport.endAllAnimations(); mTestSupport.endAllAnimations();
}); });
} }
...@@ -638,18 +621,20 @@ public class BottomSheetControllerTest { ...@@ -638,18 +621,20 @@ public class BottomSheetControllerTest {
*/ */
private void openNewTabInBackground() throws TimeoutException { private void openNewTabInBackground() throws TimeoutException {
CallbackHelper tabSelectedHelper = new CallbackHelper(); CallbackHelper tabSelectedHelper = new CallbackHelper();
mActivity.getTabModelSelector().getCurrentModel().addObserver(new TabModelObserver() { mActivityTestRule.getActivity().getTabModelSelector().getCurrentModel().addObserver(
@Override new TabModelObserver() {
public void didSelectTab(Tab tab, @TabSelectionType int type, int lastId) { @Override
tabSelectedHelper.notifyCalled(); public void didSelectTab(Tab tab, @TabSelectionType int type, int lastId) {
} tabSelectedHelper.notifyCalled();
}); }
});
int previousCallCount = tabSelectedHelper.getCallCount(); int previousCallCount = tabSelectedHelper.getCallCount();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
mActivity.getTabCreator(false).createNewTab(new LoadUrlParams("about:blank"), mActivityTestRule.getActivity().getTabCreator(false).createNewTab(
TabLaunchType.FROM_LONGPRESS_BACKGROUND, null); new LoadUrlParams("about:blank"), TabLaunchType.FROM_LONGPRESS_BACKGROUND,
null);
}); });
tabSelectedHelper.waitForCallback(previousCallCount, 1); tabSelectedHelper.waitForCallback(previousCallCount, 1);
...@@ -660,8 +645,8 @@ public class BottomSheetControllerTest { ...@@ -660,8 +645,8 @@ public class BottomSheetControllerTest {
* Open a new tab in front of the active tab and wait for it to be completely loaded. * Open a new tab in front of the active tab and wait for it to be completely loaded.
*/ */
private void openNewTabInForeground() { private void openNewTabInForeground() {
ChromeTabUtils.fullyLoadUrlInNewTab( ChromeTabUtils.fullyLoadUrlInNewTab(InstrumentationRegistry.getInstrumentation(),
InstrumentationRegistry.getInstrumentation(), mActivity, "about:blank", false); mActivityTestRule.getActivity(), "about:blank", false);
ThreadUtils.runOnUiThreadBlocking(() -> mTestSupport.endAllAnimations()); ThreadUtils.runOnUiThreadBlocking(() -> mTestSupport.endAllAnimations());
} }
} }
...@@ -22,13 +22,11 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -22,13 +22,11 @@ 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<T extends ChromeActivity> implements TestRule { public class BlankCTATabInitialStateRule implements TestRule {
private static ChromeActivity sActivity; private static ChromeActivity sActivity;
private final ChromeActivityTestRule<T> mActivityTestRule; private final ChromeActivityTestRule<ChromeActivity> mActivityTestRule;
private final boolean mClearAllTabState; private final boolean mClearAllTabState;
/** /**
...@@ -37,7 +35,7 @@ public class BlankCTATabInitialStateRule<T extends ChromeActivity> implements Te ...@@ -37,7 +35,7 @@ public class BlankCTATabInitialStateRule<T extends ChromeActivity> implements Te
* renderer process between each test. * renderer process between each test.
*/ */
public BlankCTATabInitialStateRule( public BlankCTATabInitialStateRule(
ChromeActivityTestRule<T> activityTestRule, boolean clearAllTabState) { ChromeActivityTestRule<ChromeActivity> activityTestRule, boolean clearAllTabState) {
super(); super();
mActivityTestRule = activityTestRule; mActivityTestRule = activityTestRule;
mClearAllTabState = clearAllTabState; mClearAllTabState = clearAllTabState;
...@@ -54,7 +52,7 @@ public class BlankCTATabInitialStateRule<T extends ChromeActivity> implements Te ...@@ -54,7 +52,7 @@ public class BlankCTATabInitialStateRule<T extends ChromeActivity> implements Te
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
sActivity = mActivityTestRule.getActivity(); sActivity = mActivityTestRule.getActivity();
} else { } else {
mActivityTestRule.setActivity((T) sActivity); mActivityTestRule.setActivity(sActivity);
if (mClearAllTabState) { if (mClearAllTabState) {
resetTabStateThorough(); resetTabStateThorough();
} else { } else {
......
...@@ -367,14 +367,6 @@ class BottomSheetControllerImpl implements ManagedBottomSheetController { ...@@ -367,14 +367,6 @@ 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();
......
...@@ -99,11 +99,6 @@ public class BottomSheetTestSupport { ...@@ -99,11 +99,6 @@ 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