Commit f3587e87 authored by Rohit Agarwal's avatar Rohit Agarwal Committed by Chromium LUCI CQ

Close open Incognito tabs for batch tests using fast reset.

Tests relying on not having primary OTR profile can fail in batch test
where one of the test may have opened an Incognito tab.

This CL:

a) Ensures closing all Incognito tabs between each test run in the
batch to not have any Incognito residue between batch tests.

b) Modifies the ProfileTest to open an Incognito tab before
asking for the primary OTR profile as asking for primary OTR profile by
default creates a new primary OTR profile if it doesn't exists already.
Like, this we can delete the profile just by closing the Incognito tab
which is now taken care by BlankCTATabInititalStateRule.

Bug: 1161449
Change-Id: I5b4205ded48c74e8104acf240764ce4801b768d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2612271
Commit-Queue: benjamin joyce <bjoyce@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842766}
parent e1f49aca
......@@ -16,11 +16,9 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
......@@ -43,13 +41,7 @@ public class ProfileTest {
@Before
public void setUp() {
createRegularProfileOnUiThread();
}
private void createRegularProfileOnUiThread() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
sActivityTestRule.getActivity().getTabCreator(false).createNewTab(
new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHROME_UI, null);
mRegularProfile = sActivityTestRule.getActivity()
.getTabModelSelector()
.getModel(false)
......@@ -61,20 +53,21 @@ public class ProfileTest {
@Test
@LargeTest
public void testIncognitoProfileConsistency() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertNull(mRegularProfile.getOTRProfileID());
Profile incognitoProfile1 = mRegularProfile.getPrimaryOTRProfile();
Assert.assertTrue(incognitoProfile1.isOffTheRecord());
Assert.assertTrue(incognitoProfile1.isPrimaryOTRProfile());
Assert.assertTrue(incognitoProfile1.isNativeInitialized());
Assert.assertTrue(mRegularProfile.hasPrimaryOTRProfile());
Profile incognitoProfile2 = mRegularProfile.getPrimaryOTRProfile();
Assert.assertSame("Two calls to get incognito profile should return the same object.",
incognitoProfile1, incognitoProfile2);
});
Assert.assertNull(mRegularProfile.getOTRProfileID());
// Open an new Incognito Tab page to create a new primary OTR profile.
sActivityTestRule.loadUrlInNewTab("about:blank", true);
Profile incognitoProfile1 =
TestThreadUtils.runOnUiThreadBlocking(() -> mRegularProfile.getPrimaryOTRProfile());
Assert.assertTrue(incognitoProfile1.isOffTheRecord());
Assert.assertTrue(incognitoProfile1.isPrimaryOTRProfile());
Assert.assertTrue(incognitoProfile1.isNativeInitialized());
Assert.assertTrue(mRegularProfile.hasPrimaryOTRProfile());
Profile incognitoProfile2 =
TestThreadUtils.runOnUiThreadBlocking(() -> mRegularProfile.getPrimaryOTRProfile());
Assert.assertSame("Two calls to get incognito profile should return the same object.",
incognitoProfile1, incognitoProfile2);
}
/**
......@@ -84,53 +77,52 @@ public class ProfileTest {
@Test
@LargeTest
public void testNonPrimaryProfileConsistency() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> {
OTRProfileID profileID = new OTRProfileID("test::OTRProfile");
Profile nonPrimaryOtrProfile1 = mRegularProfile.getOffTheRecordProfile(profileID);
OTRProfileID profileID = new OTRProfileID("test::OTRProfile");
Profile nonPrimaryOtrProfile1 = TestThreadUtils.runOnUiThreadBlocking(
() -> mRegularProfile.getOffTheRecordProfile(profileID));
Assert.assertTrue(nonPrimaryOtrProfile1.isOffTheRecord());
Assert.assertFalse(nonPrimaryOtrProfile1.isPrimaryOTRProfile());
Assert.assertTrue(nonPrimaryOtrProfile1.isNativeInitialized());
Assert.assertTrue(mRegularProfile.hasOffTheRecordProfile(profileID));
Assert.assertFalse(mRegularProfile.hasPrimaryOTRProfile());
Assert.assertTrue(nonPrimaryOtrProfile1.isOffTheRecord());
Assert.assertFalse(nonPrimaryOtrProfile1.isPrimaryOTRProfile());
Assert.assertTrue(nonPrimaryOtrProfile1.isNativeInitialized());
Assert.assertTrue(mRegularProfile.hasOffTheRecordProfile(profileID));
Assert.assertFalse(mRegularProfile.hasPrimaryOTRProfile());
Assert.assertEquals("OTR profile id should be returned as it is set.",
nonPrimaryOtrProfile1.getOTRProfileID(), profileID);
Assert.assertEquals("OTR profile id should be returned as it is set.",
nonPrimaryOtrProfile1.getOTRProfileID(), profileID);
Profile nonPrimaryOtrProfile2 =
mRegularProfile.getOffTheRecordProfile(new OTRProfileID("test::OTRProfile"));
Profile nonPrimaryOtrProfile2 = TestThreadUtils.runOnUiThreadBlocking(
() -> mRegularProfile.getOffTheRecordProfile(new OTRProfileID("test::OTRProfile")));
Assert.assertSame("Two calls to get non-primary OTR profile with the same ID "
+ "should return the same object.",
nonPrimaryOtrProfile1, nonPrimaryOtrProfile2);
});
Assert.assertSame("Two calls to get non-primary OTR profile with the same ID "
+ "should return the same object.",
nonPrimaryOtrProfile1, nonPrimaryOtrProfile2);
}
/** Test if creating two non-primary profiles result in different objects. */
@Test
@LargeTest
public void testCreatingTwoNonPrimaryProfiles() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> {
OTRProfileID profileID1 = new OTRProfileID("test::OTRProfile-1");
Profile nonPrimaryOtrProfile1 = mRegularProfile.getOffTheRecordProfile(profileID1);
OTRProfileID profileID2 = new OTRProfileID("test::OTRProfile-2");
Profile nonPrimaryOtrProfile2 = mRegularProfile.getOffTheRecordProfile(profileID2);
Assert.assertTrue(nonPrimaryOtrProfile1.isOffTheRecord());
Assert.assertFalse(nonPrimaryOtrProfile1.isPrimaryOTRProfile());
Assert.assertTrue(nonPrimaryOtrProfile1.isNativeInitialized());
Assert.assertTrue(mRegularProfile.hasOffTheRecordProfile(profileID1));
Assert.assertTrue(nonPrimaryOtrProfile2.isOffTheRecord());
Assert.assertFalse(nonPrimaryOtrProfile2.isPrimaryOTRProfile());
Assert.assertTrue(nonPrimaryOtrProfile2.isNativeInitialized());
Assert.assertTrue(mRegularProfile.hasOffTheRecordProfile(profileID2));
Assert.assertNotSame("Two calls to get non-primary OTR profile with different IDs"
+ "should return different objects.",
nonPrimaryOtrProfile1, nonPrimaryOtrProfile2);
});
OTRProfileID profileID1 = new OTRProfileID("test::OTRProfile-1");
Profile nonPrimaryOtrProfile1 = TestThreadUtils.runOnUiThreadBlocking(
() -> mRegularProfile.getOffTheRecordProfile(profileID1));
OTRProfileID profileID2 = new OTRProfileID("test::OTRProfile-2");
Profile nonPrimaryOtrProfile2 = TestThreadUtils.runOnUiThreadBlocking(
() -> mRegularProfile.getOffTheRecordProfile(profileID2));
Assert.assertTrue(nonPrimaryOtrProfile1.isOffTheRecord());
Assert.assertFalse(nonPrimaryOtrProfile1.isPrimaryOTRProfile());
Assert.assertTrue(nonPrimaryOtrProfile1.isNativeInitialized());
Assert.assertTrue(mRegularProfile.hasOffTheRecordProfile(profileID1));
Assert.assertTrue(nonPrimaryOtrProfile2.isOffTheRecord());
Assert.assertFalse(nonPrimaryOtrProfile2.isPrimaryOTRProfile());
Assert.assertTrue(nonPrimaryOtrProfile2.isNativeInitialized());
Assert.assertTrue(mRegularProfile.hasOffTheRecordProfile(profileID2));
Assert.assertNotSame("Two calls to get non-primary OTR profile with different IDs"
+ "should return different objects.",
nonPrimaryOtrProfile1, nonPrimaryOtrProfile2);
}
/** Test if creating unique otr profile ids works as expected. */
......
......@@ -11,7 +11,9 @@ import org.junit.runners.model.Statement;
import org.chromium.base.test.util.Batch;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
......@@ -81,9 +83,12 @@ public class BlankCTATabInitialStateRule implements TestRule {
// quickly, at the cost of thoroughness. This should be adequate for most tests.
private void resetTabStateFast() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Close all but the first tab as these tests expect to start with a single
IncognitoUtils.closeAllIncognitoTabs();
// Close all but the first regular tab as these tests expect to start with a single
// tab.
while (TabModelUtils.closeTabByIndex(sActivity.getCurrentTabModel(), 1)) {
TabModel regularTabModel =
sActivity.getTabModelSelector().getModel(/*incognito=*/false);
while (TabModelUtils.closeTabByIndex(regularTabModel, 1)) {
}
});
mActivityTestRule.loadUrl("about:blank");
......
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