Commit 320bc955 authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

Fix assumption about GCM in prefetch java tests

We were assuming that there is only GCM subtype in play, but this assumption
will not hold soon. This change gets the gcm authorization for the prefetch
subtype explicitly.

This change should unblock
https://chromium-review.googlesource.com/c/chromium/src/+/1695346

Change-Id: I275aaeea6c43ee027130c9dbdc0ba10bed698555
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1699369Reviewed-by: default avatarJian Li <jianli@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677085}
parent 4b4c32b4
...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.offlinepages.prefetch; ...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.offlinepages.prefetch;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.util.Pair;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
...@@ -265,19 +264,18 @@ public class TestOfflinePageService { ...@@ -265,19 +264,18 @@ public class TestOfflinePageService {
synchronized (mIncompleteOperations) { synchronized (mIncompleteOperations) {
operationName = mIncompleteOperations.remove(0); operationName = mIncompleteOperations.remove(0);
} }
final String prefetchSubtype = "com.google.chrome.OfflinePagePrefetch";
// We have to wait until Chrome gets the GCM token. // We have to wait until Chrome gets the GCM token.
CriteriaHelper.pollInstrumentationThread(() -> { CriteriaHelper.pollInstrumentationThread(() -> {
try { try {
FakeInstanceIDWithSubtype.getSubtypeAndAuthorizedEntityOfOnlyToken(); FakeInstanceIDWithSubtype.getAuthorizedEntityForSubtype(prefetchSubtype);
return true; return true;
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
return false; return false;
} }
}, "GetGCMToken not complete", 15000, 500); }, "GetGCMToken not complete", 15000, 500);
final Pair<String, String> appIdAndSenderId = final String senderId =
FakeInstanceIDWithSubtype.getSubtypeAndAuthorizedEntityOfOnlyToken(); FakeInstanceIDWithSubtype.getAuthorizedEntityForSubtype(prefetchSubtype);
final String appId = appIdAndSenderId.first;
final String senderId = appIdAndSenderId.second;
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
Context context = InstrumentationRegistry.getInstrumentation() Context context = InstrumentationRegistry.getInstrumentation()
.getTargetContext() .getTargetContext()
...@@ -285,7 +283,7 @@ public class TestOfflinePageService { ...@@ -285,7 +283,7 @@ public class TestOfflinePageService {
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString("pageBundle", operationName); extras.putString("pageBundle", operationName);
extras.putString("subtype", appId); // is this necessary? extras.putString("subtype", prefetchSubtype); // is this necessary?
GCMMessage message = new GCMMessage(senderId, extras); GCMMessage message = new GCMMessage(senderId, extras);
try { try {
......
...@@ -67,14 +67,27 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype { ...@@ -67,14 +67,27 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
throw new IllegalStateException("Expected exactly one InstanceID, but there are " throw new IllegalStateException("Expected exactly one InstanceID, but there are "
+ sSubtypeInstances.size()); + sSubtypeInstances.size());
} }
final String subType = sSubtypeInstances.values().iterator().next().getSubtype();
return Pair.create(subType, getAuthorizedEntityForSubtype(subType));
}
}
/**
* If an instanceID exists for subtype, and it has exactly one token, this returns
* the authorizedEntity of the token. Otherwise it throws.
*/
public static String getAuthorizedEntityForSubtype(String subtype) {
synchronized (sSubtypeInstancesLock) {
FakeInstanceIDWithSubtype iid = FakeInstanceIDWithSubtype iid =
(FakeInstanceIDWithSubtype) sSubtypeInstances.values().iterator().next(); (FakeInstanceIDWithSubtype) sSubtypeInstances.get(subtype);
if (iid == null) {
throw new IllegalStateException("No subtype instance found for " + subtype);
}
if (iid.mTokens.size() != 1) { if (iid.mTokens.size() != 1) {
throw new IllegalStateException( throw new IllegalStateException(
"Expected exactly one token, but there are " + iid.mTokens.size()); "Expected exactly one token, but there are " + iid.mTokens.size());
} }
String authorizedEntity = iid.mTokens.keySet().iterator().next().split(",", 3)[1]; return iid.mTokens.keySet().iterator().next().split(",", 3)[1];
return Pair.create(iid.getSubtype(), authorizedEntity);
} }
} }
......
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