Commit 257cdc8f authored by Benoît Lizé's avatar Benoît Lizé Committed by Commit Bot

customtabs: Allow detached requests before native is fully initialized.

Relax the restriction on parallel requests.
Most of the changes are in tests:
- Don't always initialize the browser in tests
- Detached requests are tried before and after native is loaded.

Bug: 901835
Change-Id: Iecd16e976eb3bdea44871097528ef799b9678051
Reviewed-on: https://chromium-review.googlesource.com/c/1350891Reviewed-by: default avatarAlexandr Ilin <alexilin@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611085}
parent 1d7e84e1
...@@ -846,7 +846,8 @@ public class CustomTabsConnection { ...@@ -846,7 +846,8 @@ public class CustomTabsConnection {
*/ */
public void onHandledIntent(CustomTabsSessionToken session, String url, Intent intent) { public void onHandledIntent(CustomTabsSessionToken session, String url, Intent intent) {
if (mLogRequests) { if (mLogRequests) {
Log.w(TAG, "onHandledIntent, URL: %s, extras:", bundleToJson(intent.getExtras())); Log.w(TAG, "onHandledIntent, URL: %s, extras: %s", url,
bundleToJson(intent.getExtras()));
} }
// If we still have pending warmup tasks, don't continue as they would only delay intent // If we still have pending warmup tasks, don't continue as they would only delay intent
...@@ -1001,14 +1002,7 @@ public class CustomTabsConnection { ...@@ -1001,14 +1002,7 @@ public class CustomTabsConnection {
@VisibleForTesting @VisibleForTesting
boolean canDoParallelRequest(CustomTabsSessionToken session, Uri referrer) { boolean canDoParallelRequest(CustomTabsSessionToken session, Uri referrer) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
// The restrictions are: return mClientManager.isFirstPartyOriginForSession(session, new Origin(referrer));
// - Native initialization: Required to get the profile, and the feature state.
// - The referrer's origin is allowed.
//
// TODO(lizeb): Relax the restrictions.
return ChromeBrowserInitializer.getInstance(ContextUtils.getApplicationContext())
.hasNativeInitializationCompleted()
&& mClientManager.isFirstPartyOriginForSession(session, new Origin(referrer));
} }
/** See {@link ClientManager#getReferrerForSession(CustomTabsSessionToken)} */ /** See {@link ClientManager#getReferrerForSession(CustomTabsSessionToken)} */
......
...@@ -26,8 +26,6 @@ import org.junit.runner.RunWith; ...@@ -26,8 +26,6 @@ import org.junit.runner.RunWith;
import org.chromium.base.PathUtils; import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.MetricsUtils.HistogramDelta; import org.chromium.base.test.util.MetricsUtils.HistogramDelta;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
...@@ -72,7 +70,6 @@ public class DetachedResourceRequestTest { ...@@ -72,7 +70,6 @@ public class DetachedResourceRequestTest {
public void setUp() throws Exception { public void setUp() throws Exception {
ThreadUtils.runOnUiThreadBlocking(() -> FirstRunStatus.setFirstRunFlowComplete(true)); ThreadUtils.runOnUiThreadBlocking(() -> FirstRunStatus.setFirstRunFlowComplete(true));
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
LibraryLoader.getInstance().ensureInitialized(LibraryProcessType.PROCESS_BROWSER);
mConnection = CustomTabsTestUtils.setUpConnection(); mConnection = CustomTabsTestUtils.setUpConnection();
mContext = InstrumentationRegistry.getInstrumentation() mContext = InstrumentationRegistry.getInstrumentation()
.getTargetContext() .getTargetContext()
...@@ -93,10 +90,7 @@ public class DetachedResourceRequestTest { ...@@ -93,10 +90,7 @@ public class DetachedResourceRequestTest {
CustomTabsSessionToken session = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken session = CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mConnection.newSession(session)); Assert.assertTrue(mConnection.newSession(session));
ThreadUtils.runOnUiThreadBlocking( ThreadUtils.runOnUiThreadBlocking(
() -> { Assert.assertFalse(mConnection.canDoParallelRequest(session, ORIGIN)); }); () -> Assert.assertFalse(mConnection.canDoParallelRequest(session, ORIGIN)));
CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThreadBlocking(
() -> { Assert.assertFalse(mConnection.canDoParallelRequest(session, ORIGIN)); });
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
String packageName = mContext.getPackageName(); String packageName = mContext.getPackageName();
OriginVerifier.addVerifiedOriginForPackage(packageName, new Origin(ORIGIN.toString()), OriginVerifier.addVerifiedOriginForPackage(packageName, new Origin(ORIGIN.toString()),
...@@ -119,25 +113,23 @@ public class DetachedResourceRequestTest { ...@@ -119,25 +113,23 @@ public class DetachedResourceRequestTest {
}); });
Intent intent = prepareIntentForResourcePrefetch( Intent intent = prepareIntentForResourcePrefetch(
Arrays.asList(Uri.parse("https://foo.bar")), ORIGIN); Arrays.asList(Uri.parse("https://foo.bar")), ORIGIN);
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(
Assert.assertEquals(0, mConnection.maybePrefetchResources(session, intent)); () -> Assert.assertEquals(0, mConnection.maybePrefetchResources(session, intent)));
});
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(
Assert.assertEquals(0, mConnection.maybePrefetchResources(session, intent)); () -> Assert.assertEquals(0, mConnection.maybePrefetchResources(session, intent)));
});
mConnection.mClientManager.setAllowResourcePrefetchForSession(session, true); mConnection.mClientManager.setAllowResourcePrefetchForSession(session, true);
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(
Assert.assertEquals(1, mConnection.maybePrefetchResources(session, intent)); () -> Assert.assertEquals(1, mConnection.maybePrefetchResources(session, intent)));
});
} }
@Test @Test
@SmallTest @SmallTest
public void testStartParallelRequestValidation() throws Exception { public void testStartParallelRequestValidation() throws Exception {
CustomTabsSessionToken session = prepareSession(); CustomTabsSessionToken session = prepareSession();
CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
int expected = CustomTabsConnection.ParallelRequestStatus.NO_REQUEST; int expected = CustomTabsConnection.ParallelRequestStatus.NO_REQUEST;
...@@ -181,6 +173,7 @@ public class DetachedResourceRequestTest { ...@@ -181,6 +173,7 @@ public class DetachedResourceRequestTest {
@EnableFeatures(ChromeFeatureList.CCT_RESOURCE_PREFETCH) @EnableFeatures(ChromeFeatureList.CCT_RESOURCE_PREFETCH)
public void testStartResourcePrefetchUrlsValidation() throws Exception { public void testStartResourcePrefetchUrlsValidation() throws Exception {
CustomTabsSessionToken session = prepareSession(); CustomTabsSessionToken session = prepareSession();
CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals(0, mConnection.maybePrefetchResources(session, new Intent())); Assert.assertEquals(0, mConnection.maybePrefetchResources(session, new Intent()));
...@@ -214,27 +207,14 @@ public class DetachedResourceRequestTest { ...@@ -214,27 +207,14 @@ public class DetachedResourceRequestTest {
@SmallTest @SmallTest
@EnableFeatures(ChromeFeatureList.CCT_REPORT_PARALLEL_REQUEST_STATUS) @EnableFeatures(ChromeFeatureList.CCT_REPORT_PARALLEL_REQUEST_STATUS)
public void testCanStartParallelRequest() throws Exception { public void testCanStartParallelRequest() throws Exception {
final CallbackHelper cb = new CallbackHelper(); testCanStartParallelRequest(true);
setUpTestServerWithListener(new EmbeddedTestServer.ConnectionListener() { }
@Override
public void readFromSocket(long socketId) {
cb.notifyCalled();
}
});
Uri url = Uri.parse(mServer.getURL("/echotitle"));
DetachedResourceRequestCheckCallback customTabsCallback =
new DetachedResourceRequestCheckCallback(
url, CustomTabsConnection.ParallelRequestStatus.SUCCESS, NET_OK);
CustomTabsSessionToken session = prepareSession(ORIGIN, customTabsCallback);
ThreadUtils.runOnUiThread(() -> { @Test
Assert.assertEquals(CustomTabsConnection.ParallelRequestStatus.SUCCESS, @SmallTest
mConnection.handleParallelRequest(session, prepareIntent(url, ORIGIN))); @EnableFeatures(ChromeFeatureList.CCT_REPORT_PARALLEL_REQUEST_STATUS)
}); public void testCanStartParallelRequestBeforeNative() throws Exception {
customTabsCallback.waitForRequest(); testCanStartParallelRequest(false);
cb.waitForCallback(0, 1);
customTabsCallback.waitForCompletion();
} }
@Test @Test
...@@ -247,6 +227,7 @@ public class DetachedResourceRequestTest { ...@@ -247,6 +227,7 @@ public class DetachedResourceRequestTest {
DetachedResourceRequestCheckCallback customTabsCallback = DetachedResourceRequestCheckCallback customTabsCallback =
new DetachedResourceRequestCheckCallback(url, status, 0); new DetachedResourceRequestCheckCallback(url, status, 0);
CustomTabsSessionToken session = prepareSession(ORIGIN, customTabsCallback); CustomTabsSessionToken session = prepareSession(ORIGIN, customTabsCallback);
CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThread(() -> { ThreadUtils.runOnUiThread(() -> {
Assert.assertEquals(status, Assert.assertEquals(status,
...@@ -275,10 +256,9 @@ public class DetachedResourceRequestTest { ...@@ -275,10 +256,9 @@ public class DetachedResourceRequestTest {
Math.abs(NetError.ERR_EMPTY_RESPONSE)); Math.abs(NetError.ERR_EMPTY_RESPONSE));
CustomTabsSessionToken session = prepareSession(ORIGIN, customTabsCallback); CustomTabsSessionToken session = prepareSession(ORIGIN, customTabsCallback);
ThreadUtils.runOnUiThread(() -> { ThreadUtils.runOnUiThread(
Assert.assertEquals(CustomTabsConnection.ParallelRequestStatus.SUCCESS, () -> mConnection.onHandledIntent(session, "", prepareIntent(url, ORIGIN)));
mConnection.handleParallelRequest(session, prepareIntent(url, ORIGIN))); CustomTabsTestUtils.warmUpAndWait();
});
customTabsCallback.waitForRequest(); customTabsCallback.waitForRequest();
cb.waitForCallback(0, 1); cb.waitForCallback(0, 1);
customTabsCallback.waitForCompletion(); customTabsCallback.waitForCompletion();
...@@ -288,6 +268,8 @@ public class DetachedResourceRequestTest { ...@@ -288,6 +268,8 @@ public class DetachedResourceRequestTest {
@SmallTest @SmallTest
public void testCanStartResourcePrefetch() throws Exception { public void testCanStartResourcePrefetch() throws Exception {
CustomTabsSessionToken session = prepareSession(); CustomTabsSessionToken session = prepareSession();
CustomTabsTestUtils.warmUpAndWait();
final CallbackHelper cb = new CallbackHelper(); final CallbackHelper cb = new CallbackHelper();
// We expect one read per prefetched url. // We expect one read per prefetched url.
setUpTestServerWithListener(new EmbeddedTestServer.ConnectionListener() { setUpTestServerWithListener(new EmbeddedTestServer.ConnectionListener() {
...@@ -312,29 +294,14 @@ public class DetachedResourceRequestTest { ...@@ -312,29 +294,14 @@ public class DetachedResourceRequestTest {
@SmallTest @SmallTest
@EnableFeatures(ChromeFeatureList.CCT_REPORT_PARALLEL_REQUEST_STATUS) @EnableFeatures(ChromeFeatureList.CCT_REPORT_PARALLEL_REQUEST_STATUS)
public void testCanSetCookie() throws Exception { public void testCanSetCookie() throws Exception {
mServer = EmbeddedTestServer.createAndStartServer(mContext); testCanSetCookie(true);
final Uri url = Uri.parse(mServer.getURL("/set-cookie?acookie")); }
DetachedResourceRequestCheckCallback customTabsCallback =
new DetachedResourceRequestCheckCallback(
url, CustomTabsConnection.ParallelRequestStatus.SUCCESS, NET_OK);
CustomTabsSessionToken session = prepareSession(ORIGIN, customTabsCallback);
ThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals(CustomTabsConnection.ParallelRequestStatus.SUCCESS,
mConnection.handleParallelRequest(session, prepareIntent(url, ORIGIN)));
});
customTabsCallback.waitForRequest();
customTabsCallback.waitForCompletion();
String echoUrl = mServer.getURL("/echoheader?Cookie");
Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(mContext, echoUrl);
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab(); @Test
String content = JavaScriptUtils.executeJavaScriptAndWaitForResult( @SmallTest
tab.getWebContents(), "document.body.textContent"); @EnableFeatures(ChromeFeatureList.CCT_REPORT_PARALLEL_REQUEST_STATUS)
Assert.assertEquals("\"acookie\"", content); public void testCanSetCookieBeforeNative() throws Exception {
testCanSetCookie(false);
} }
/** /**
...@@ -344,30 +311,7 @@ public class DetachedResourceRequestTest { ...@@ -344,30 +311,7 @@ public class DetachedResourceRequestTest {
@Test @Test
@SmallTest @SmallTest
public void testSafeBrowsingMainResource() throws Exception { public void testSafeBrowsingMainResource() throws Exception {
SafeBrowsingApiBridge.setSafeBrowsingHandlerType( testSafeBrowsingMainResource(true);
new MockSafeBrowsingApiHandler().getClass());
CustomTabsSessionToken session = prepareSession();
String cacheable = "/cachetime";
CallbackHelper readFromSocketCallback = waitForDetachedRequest(session, cacheable);
Uri url = Uri.parse(mServer.getURL(cacheable));
try {
MockSafeBrowsingApiHandler.addMockResponse(
url.toString(), "{\"matches\":[{\"threat_type\":\"5\"}]}");
Intent intent =
CustomTabsTestUtils.createMinimalCustomTabIntent(mContext, url.toString());
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab();
ThreadUtils.runOnUiThreadBlocking(
() -> Assert.assertTrue(tab.getWebContents().isShowingInterstitialPage()));
// 1 read from the detached request, and 0 from the page load, as
// the response comes from the cache, and SafeBrowsing blocks it.
Assert.assertEquals(1, readFromSocketCallback.getCallCount());
} finally {
MockSafeBrowsingApiHandler.clearMockResponses();
}
} }
/** /**
...@@ -377,34 +321,34 @@ public class DetachedResourceRequestTest { ...@@ -377,34 +321,34 @@ public class DetachedResourceRequestTest {
@Test @Test
@SmallTest @SmallTest
public void testSafeBrowsingSubresource() throws Exception { public void testSafeBrowsingSubresource() throws Exception {
SafeBrowsingApiBridge.setSafeBrowsingHandlerType( testSafeBrowsingSubresource(true);
new MockSafeBrowsingApiHandler().getClass()); }
CustomTabsSessionToken session = prepareSession();
String cacheable = "/cachetime";
waitForDetachedRequest(session, cacheable);
Uri url = Uri.parse(mServer.getURL(cacheable));
try {
MockSafeBrowsingApiHandler.addMockResponse(
url.toString(), "{\"matches\":[{\"threat_type\":\"5\"}]}");
String pageUrl = mServer.getURL("/chrome/test/data/android/cacheable_subresource.html"); /**
Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(mContext, pageUrl); * Tests that cached detached resource requests that are forbidden by SafeBrowsing don't end up
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent); * in the content area, for a main resource.
*/
@Test
@SmallTest
public void testSafeBrowsingMainResourceBeforeNative() throws Exception {
testSafeBrowsingMainResource(false);
}
Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab(); /**
WebContents webContents = tab.getWebContents(); * Tests that cached detached resource requests that are forbidden by SafeBrowsing don't end up
// Need to poll as the subresource request is async. * in the content area, for a subresource.
CriteriaHelper.pollUiThread(() -> webContents.isShowingInterstitialPage()); */
} finally { @Test
MockSafeBrowsingApiHandler.clearMockResponses(); @SmallTest
} public void testSafeBrowsingSubresourceBeforeNative() throws Exception {
testSafeBrowsingSubresource(false);
} }
@Test @Test
@SmallTest @SmallTest
public void testCanBlockThirdPartyCookies() throws Exception { public void testCanBlockThirdPartyCookies() throws Exception {
CustomTabsSessionToken session = prepareSession(); CustomTabsSessionToken session = prepareSession();
CustomTabsTestUtils.warmUpAndWait();
mServer = EmbeddedTestServer.createAndStartServer(mContext); mServer = EmbeddedTestServer.createAndStartServer(mContext);
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
PrefServiceBridge prefs = PrefServiceBridge.getInstance(); PrefServiceBridge prefs = PrefServiceBridge.getInstance();
...@@ -456,6 +400,112 @@ public class DetachedResourceRequestTest { ...@@ -456,6 +400,112 @@ public class DetachedResourceRequestTest {
Assert.assertEquals("\"acookie\"", content); Assert.assertEquals("\"acookie\"", content);
} }
private void testCanStartParallelRequest(boolean afterNative) throws Exception {
final CallbackHelper cb = new CallbackHelper();
setUpTestServerWithListener(new EmbeddedTestServer.ConnectionListener() {
@Override
public void readFromSocket(long socketId) {
cb.notifyCalled();
}
});
Uri url = Uri.parse(mServer.getURL("/echotitle"));
DetachedResourceRequestCheckCallback customTabsCallback =
new DetachedResourceRequestCheckCallback(
url, CustomTabsConnection.ParallelRequestStatus.SUCCESS, NET_OK);
CustomTabsSessionToken session = prepareSession(ORIGIN, customTabsCallback);
if (afterNative) CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThread(
() -> mConnection.onHandledIntent(session, "", prepareIntent(url, ORIGIN)));
if (!afterNative) CustomTabsTestUtils.warmUpAndWait();
customTabsCallback.waitForRequest();
cb.waitForCallback(0, 1);
customTabsCallback.waitForCompletion();
}
private void testCanSetCookie(boolean afterNative) throws Exception {
mServer = EmbeddedTestServer.createAndStartServer(mContext);
final Uri url = Uri.parse(mServer.getURL("/set-cookie?acookie"));
DetachedResourceRequestCheckCallback customTabsCallback =
new DetachedResourceRequestCheckCallback(
url, CustomTabsConnection.ParallelRequestStatus.SUCCESS, NET_OK);
CustomTabsSessionToken session = prepareSession(ORIGIN, customTabsCallback);
if (afterNative) CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThreadBlocking(
() -> mConnection.onHandledIntent(session, "", prepareIntent(url, ORIGIN)));
if (!afterNative) CustomTabsTestUtils.warmUpAndWait();
customTabsCallback.waitForRequest();
customTabsCallback.waitForCompletion();
String echoUrl = mServer.getURL("/echoheader?Cookie");
Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(mContext, echoUrl);
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab();
String content = JavaScriptUtils.executeJavaScriptAndWaitForResult(
tab.getWebContents(), "document.body.textContent");
Assert.assertEquals("\"acookie\"", content);
}
private void testSafeBrowsingMainResource(boolean afterNative) throws Exception {
SafeBrowsingApiBridge.setSafeBrowsingHandlerType(
new MockSafeBrowsingApiHandler().getClass());
CustomTabsSessionToken session = prepareSession();
String cacheable = "/cachetime";
CallbackHelper readFromSocketCallback =
waitForDetachedRequest(session, cacheable, afterNative);
Uri url = Uri.parse(mServer.getURL(cacheable));
try {
MockSafeBrowsingApiHandler.addMockResponse(
url.toString(), "{\"matches\":[{\"threat_type\":\"5\"}]}");
Intent intent =
CustomTabsTestUtils.createMinimalCustomTabIntent(mContext, url.toString());
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab();
ThreadUtils.runOnUiThreadBlocking(
() -> Assert.assertTrue(tab.getWebContents().isShowingInterstitialPage()));
// 1 read from the detached request, and 0 from the page load, as
// the response comes from the cache, and SafeBrowsing blocks it.
Assert.assertEquals(1, readFromSocketCallback.getCallCount());
} finally {
MockSafeBrowsingApiHandler.clearMockResponses();
}
}
private void testSafeBrowsingSubresource(boolean afterNative) throws Exception {
SafeBrowsingApiBridge.setSafeBrowsingHandlerType(
new MockSafeBrowsingApiHandler().getClass());
CustomTabsSessionToken session = prepareSession();
String cacheable = "/cachetime";
waitForDetachedRequest(session, cacheable, afterNative);
Uri url = Uri.parse(mServer.getURL(cacheable));
try {
MockSafeBrowsingApiHandler.addMockResponse(
url.toString(), "{\"matches\":[{\"threat_type\":\"5\"}]}");
String pageUrl = mServer.getURL("/chrome/test/data/android/cacheable_subresource.html");
Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(mContext, pageUrl);
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab();
WebContents webContents = tab.getWebContents();
// Need to poll as the subresource request is async.
CriteriaHelper.pollUiThread(() -> webContents.isShowingInterstitialPage());
} finally {
MockSafeBrowsingApiHandler.clearMockResponses();
}
}
private CustomTabsSessionToken prepareSession() throws Exception { private CustomTabsSessionToken prepareSession() throws Exception {
return prepareSession(ORIGIN, null); return prepareSession(ORIGIN, null);
} }
...@@ -472,7 +522,6 @@ public class DetachedResourceRequestTest { ...@@ -472,7 +522,6 @@ public class DetachedResourceRequestTest {
Assert.assertTrue(mConnection.newSession(token)); Assert.assertTrue(mConnection.newSession(token));
mConnection.mClientManager.setAllowParallelRequestForSession(token, true); mConnection.mClientManager.setAllowParallelRequestForSession(token, true);
mConnection.mClientManager.setAllowResourcePrefetchForSession(token, true); mConnection.mClientManager.setAllowResourcePrefetchForSession(token, true);
CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
OriginVerifier.addVerifiedOriginForPackage(mContext.getPackageName(), OriginVerifier.addVerifiedOriginForPackage(mContext.getPackageName(),
new Origin(origin.toString()), CustomTabsService.RELATION_USE_AS_ORIGIN); new Origin(origin.toString()), CustomTabsService.RELATION_USE_AS_ORIGIN);
...@@ -492,7 +541,7 @@ public class DetachedResourceRequestTest { ...@@ -492,7 +541,7 @@ public class DetachedResourceRequestTest {
} }
private CallbackHelper waitForDetachedRequest(CustomTabsSessionToken session, private CallbackHelper waitForDetachedRequest(CustomTabsSessionToken session,
String relativeUrl) throws InterruptedException, TimeoutException { String relativeUrl, boolean afterNative) throws InterruptedException, TimeoutException {
// Count the number of times data is read from the socket. // Count the number of times data is read from the socket.
// We expect 1 for the detached request. // We expect 1 for the detached request.
// Cannot count connections as Chrome opens multiple sockets at page load time. // Cannot count connections as Chrome opens multiple sockets at page load time.
...@@ -504,11 +553,11 @@ public class DetachedResourceRequestTest { ...@@ -504,11 +553,11 @@ public class DetachedResourceRequestTest {
} }
}); });
Uri url = Uri.parse(mServer.getURL(relativeUrl)); Uri url = Uri.parse(mServer.getURL(relativeUrl));
if (afterNative) CustomTabsTestUtils.warmUpAndWait();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(
Assert.assertEquals(CustomTabsConnection.ParallelRequestStatus.SUCCESS, () -> mConnection.onHandledIntent(session, "", prepareIntent(url, ORIGIN)));
mConnection.handleParallelRequest(session, prepareIntent(url, ORIGIN))); if (!afterNative) CustomTabsTestUtils.warmUpAndWait();
});
readFromSocketCallback.waitForCallback(0); readFromSocketCallback.waitForCallback(0);
return readFromSocketCallback; return readFromSocketCallback;
} }
......
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