Commit 4525c071 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

PreviewTab: Add a test closing all incognito tabs

Closing all incognito tabs also closes the preview tab open on
the active incognito tab. A new tests ensures that the operation
works without crashing due to concurrent attempts to destroy
the shared incognito profile.

Bug: 1029677
Change-Id: I28573182750f2cc7714c5e087fb88f56e25f6ad1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2371962
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802163}
parent ed6409e7
......@@ -22,6 +22,7 @@ import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTa
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
import org.chromium.chrome.browser.firstrun.DisableFirstRun;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabbed_mode.TabbedRootUiCoordinator;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -29,6 +30,8 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController.SheetState;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetTestSupport;
import org.chromium.content_public.browser.test.util.DOMUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
......@@ -77,6 +80,10 @@ public class PreviewTabTest {
.getBottomSheetController());
}
/**
* End all animations that already started before so that the UI will be in a state ready
* for the next command.
*/
private void endAnimations() {
TestThreadUtils.runOnUiThreadBlocking(mSheetTestSupport::endAllAnimations);
}
......@@ -114,6 +121,39 @@ public class PreviewTabTest {
closePreviewTab();
}
/**
* Test that closing all incognito tabs successfully handles the base tab and
* its preview tab opened in incognito mode. This makes sure an incognito profile
* shared by the tabs is destroyed safely.
*/
@Test
@MediumTest
@Feature({"PreviewTab"})
public void testCloseAllIncognitoTabsClosesPreviewTab() throws Throwable {
Assert.assertFalse("Test should have started without any Preview Tab",
mEphemeralTabCoordinator.isOpened());
mActivityTestRule.loadUrlInNewTab(mTestServer.getServer().getURL(BASE_PAGE),
/*incognito=*/true);
mActivityTestRule.getActivity().getTabModelSelector().selectModel(true);
ChromeActivity activity = mActivityTestRule.getActivity();
Tab tab = activity.getActivityTab();
Assert.assertTrue(tab.isIncognito());
ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
activity, tab, PREVIEW_TAB_DOM_ID, R.id.contextmenu_open_in_ephemeral_tab);
endAnimations();
BottomSheetController bottomSheet =
activity.getRootUiCoordinatorForTesting().getBottomSheetController();
TestThreadUtils.runOnUiThreadBlocking(() -> {
bottomSheet.expandSheet();
endAnimations();
IncognitoUtils.closeAllIncognitoTabs();
endAnimations();
});
Assert.assertEquals(SheetState.HIDDEN, bottomSheet.getSheetState());
}
/**
* Test preview tab suppresses contextual search.
*/
......
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