Commit d01b9662 authored by Rohit Agarwal's avatar Rohit Agarwal Committed by Commit Bot

Audit Profile usage in RequestCoordinatorBridgeTest

Bug: 1060940
Change-Id: I523009ba4a6d9ad6d257b9b2bc0e6b3061b379cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2494724Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Rohit Agarwal <roagarwal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820276}
parent b471996d
...@@ -16,6 +16,7 @@ import org.chromium.base.Callback; ...@@ -16,6 +16,7 @@ import org.chromium.base.Callback;
import org.chromium.base.task.PostTask; import org.chromium.base.task.PostTask;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.profiles.OTRProfileID;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule; import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
...@@ -41,16 +42,12 @@ public class RequestCoordinatorBridgeTest { ...@@ -41,16 +42,12 @@ public class RequestCoordinatorBridgeTest {
private static final int TIMEOUT_MS = 5000; private static final int TIMEOUT_MS = 5000;
private RequestCoordinatorBridge mRequestCoordinatorBridge; private RequestCoordinatorBridge mRequestCoordinatorBridge;
private Profile mProfile;
private void initializeBridgeForProfile(final boolean incognitoProfile) private void initializeBridgeForProfile() throws InterruptedException {
throws InterruptedException {
final Semaphore semaphore = new Semaphore(0); final Semaphore semaphore = new Semaphore(0);
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
Profile profile = Profile.getLastUsedRegularProfile(); mRequestCoordinatorBridge = RequestCoordinatorBridge.getForProfile(mProfile);
if (incognitoProfile) {
profile = profile.getOffTheRecordProfile();
}
mRequestCoordinatorBridge = RequestCoordinatorBridge.getForProfile(profile);
semaphore.release(); semaphore.release();
}); });
Assert.assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)); Assert.assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
...@@ -68,7 +65,10 @@ public class RequestCoordinatorBridgeTest { ...@@ -68,7 +65,10 @@ public class RequestCoordinatorBridgeTest {
} }
}); });
initializeBridgeForProfile(false); TestThreadUtils.runOnUiThreadBlocking(
() -> { mProfile = Profile.getLastUsedRegularProfile(); });
initializeBridgeForProfile();
} }
@Test @Test
...@@ -106,8 +106,21 @@ public class RequestCoordinatorBridgeTest { ...@@ -106,8 +106,21 @@ public class RequestCoordinatorBridgeTest {
@Test @Test
@MediumTest @MediumTest
public void testRequestCoordinatorBridgeDisabledInIncognito() throws Exception { public void testRequestCoordinatorBridgeDisabledInIncognitoTabbedActivity() throws Exception {
initializeBridgeForProfile(true); TestThreadUtils.runOnUiThreadBlocking(
() -> { mProfile = Profile.getLastUsedRegularProfile().getPrimaryOTRProfile(); });
initializeBridgeForProfile();
Assert.assertEquals(null, mRequestCoordinatorBridge);
}
@Test
@MediumTest
public void testRequestCoordinatorBridgeDisabledInIncognitoCCT() throws Exception {
OTRProfileID otrProfileID = OTRProfileID.createUnique("CCT:Incognito");
TestThreadUtils.runOnUiThreadBlocking(() -> {
mProfile = Profile.getLastUsedRegularProfile().getOffTheRecordProfile(otrProfileID);
});
initializeBridgeForProfile();
Assert.assertEquals(null, mRequestCoordinatorBridge); Assert.assertEquals(null, mRequestCoordinatorBridge);
} }
......
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