Commit d1f626b8 authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

Improve reliability of PrefetchFlowTest

There are two problems addressed here:
1. Synchronization was missing in TestOfflinePageService.sendPushMessage
2. Recent changes relating to prefetch GCM defer the call to GetGCMToken,
   which in turn results in an exception when calling
   FakeInstanceIDWithSubtype.getSubtypeAndAuthorizedEntityOfOnlyToken.

With these fixed, we (crosses fingers) can un-disable the test.

Bug: 959733
Change-Id: Ibfd29de884813606ab73a6520c627a4214d52432
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1600353Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657722}
parent f9f47afe
...@@ -19,7 +19,6 @@ import org.chromium.base.CommandLine; ...@@ -19,7 +19,6 @@ import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
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.DisabledTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
...@@ -253,7 +252,6 @@ public class PrefetchFlowTest implements WebServer.RequestHandler { ...@@ -253,7 +252,6 @@ public class PrefetchFlowTest implements WebServer.RequestHandler {
@Test @Test
@MediumTest @MediumTest
@Feature({"OfflinePrefetch"}) @Feature({"OfflinePrefetch"})
@DisabledTest
public void testPrefetchPageReadyLater() throws Throwable { public void testPrefetchPageReadyLater() throws Throwable {
final String url1 = "http://suggestion1.com/main"; final String url1 = "http://suggestion1.com/main";
mSuggestionsService.addSuggestion("Suggestion 1", url1, imageUrlBase() + "suggestion1"); mSuggestionsService.addSuggestion("Suggestion 1", url1, imageUrlBase() + "suggestion1");
......
...@@ -28,6 +28,7 @@ import org.chromium.components.offline_pages.core.prefetch.proto.OfflinePages.Pa ...@@ -28,6 +28,7 @@ import org.chromium.components.offline_pages.core.prefetch.proto.OfflinePages.Pa
import org.chromium.components.offline_pages.core.prefetch.proto.OfflinePages.PageParameters; import org.chromium.components.offline_pages.core.prefetch.proto.OfflinePages.PageParameters;
import org.chromium.components.offline_pages.core.prefetch.proto.OperationOuterClass.Operation; import org.chromium.components.offline_pages.core.prefetch.proto.OperationOuterClass.Operation;
import org.chromium.components.offline_pages.core.prefetch.proto.StatusOuterClass; import org.chromium.components.offline_pages.core.prefetch.proto.StatusOuterClass;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.util.WebServer; import org.chromium.net.test.util.WebServer;
import org.chromium.net.test.util.WebServer.HTTPHeader; import org.chromium.net.test.util.WebServer.HTTPHeader;
...@@ -230,7 +231,9 @@ public class TestOfflinePageService { ...@@ -230,7 +231,9 @@ public class TestOfflinePageService {
} }
mOperations.put(operationName, request); mOperations.put(operationName, request);
if (!writeOperationResponse(operationName, request, true, output)) { if (!writeOperationResponse(operationName, request, true, output)) {
mIncompleteOperations.add(operationName); synchronized (mIncompleteOperations) {
mIncompleteOperations.add(operationName);
}
} }
} }
...@@ -245,12 +248,32 @@ public class TestOfflinePageService { ...@@ -245,12 +248,32 @@ public class TestOfflinePageService {
* name that was completed. Returns null if no bundle needs to be sent. If more than one bundle * name that was completed. Returns null if no bundle needs to be sent. If more than one bundle
* needs to be sent, the first completed bundle is sent. This can be called repeatedly until no * needs to be sent, the first completed bundle is sent. This can be called repeatedly until no
* more bundles are ready. * more bundles are ready.
*
* This method is typically not called on the server thread, so access to members should be
* synchronized.
*/ */
public String sendPushMessage() throws InterruptedException, TimeoutException { public String sendPushMessage() throws InterruptedException, TimeoutException {
if (mIncompleteOperations.isEmpty()) { CriteriaHelper.pollInstrumentationThread(() -> {
return null; Boolean result;
synchronized (mIncompleteOperations) {
result = !mIncompleteOperations.isEmpty();
}
return result;
});
String operationName;
synchronized (mIncompleteOperations) {
operationName = mIncompleteOperations.remove(0);
} }
String operationName = mIncompleteOperations.remove(0); // We have to wait until Chrome gets the GCM token.
CriteriaHelper.pollInstrumentationThread(() -> {
try {
FakeInstanceIDWithSubtype.getSubtypeAndAuthorizedEntityOfOnlyToken();
return true;
} catch (IllegalStateException e) {
return false;
}
}, "GetGCMToken not complete", 15000, 500);
final Pair<String, String> appIdAndSenderId = final Pair<String, String> appIdAndSenderId =
FakeInstanceIDWithSubtype.getSubtypeAndAuthorizedEntityOfOnlyToken(); FakeInstanceIDWithSubtype.getSubtypeAndAuthorizedEntityOfOnlyToken();
final String appId = appIdAndSenderId.first; final String appId = appIdAndSenderId.first;
......
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