Chromium Code Reviews| Index: components/gcm_driver/instance_id/android/javatests/src/org/chromium/components/gcm_driver/instance_id/FakeInstanceIDWithSubtype.java |
| diff --git a/components/gcm_driver/instance_id/android/javatests/src/org/chromium/components/gcm_driver/instance_id/FakeInstanceIDWithSubtype.java b/components/gcm_driver/instance_id/android/javatests/src/org/chromium/components/gcm_driver/instance_id/FakeInstanceIDWithSubtype.java |
| index adb69823443786366718ac14b0c38678bfc7c6d9..733b3dde60a46b02dad39731329270d18e18360b 100644 |
| --- a/components/gcm_driver/instance_id/android/javatests/src/org/chromium/components/gcm_driver/instance_id/FakeInstanceIDWithSubtype.java |
| +++ b/components/gcm_driver/instance_id/android/javatests/src/org/chromium/components/gcm_driver/instance_id/FakeInstanceIDWithSubtype.java |
| @@ -7,6 +7,7 @@ package org.chromium.components.gcm_driver.instance_id; |
| import android.content.Context; |
| import android.os.Bundle; |
| import android.os.Looper; |
| +import android.util.Pair; |
| import com.google.android.gms.iid.InstanceID; |
| @@ -27,6 +28,8 @@ import java.util.Random; |
| public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype { |
| private String mId = null; |
| private long mCreationTime = 0; |
| + |
| + /** Map from (subtype + ',' + authorizedEntity + ',' + scope) to token. */ |
| private Map<String, String> mTokens = new HashMap<>(); |
| /** |
| @@ -52,6 +55,30 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype { |
| } |
| } |
| + /** |
| + * If exactly one instance of InstanceID exists, and it has exactly one token, this returns |
| + * the subtype of the InstanceID and the authorizedEntity of the token. Otherwise it throws. |
| + * If a test fails with no InstanceID or no tokens, it probably means subscribing failed, or |
| + * that the test subscribed in the wrong way (e.g. a GCM registration rather than an InstanceID |
| + * token). If a test fails with too many InstanceIDs/tokens, the test subscribed too many times. |
| + */ |
| + public static Pair<String, String> getSubtypeAndAuthorizedEntityOfOnlyToken() { |
| + if (InstanceIDWithSubtype.sSubtypeInstances.size() != 1) { |
|
Peter Beverloo
2016/06/02 15:53:18
I think `protected` visibility would still work fi
johnme
2016/06/07 14:16:43
org.chromium.chrome.browser.push_messaging.PushMes
|
| + throw new IllegalStateException("Expected exactly one InstanceID, but there are " |
| + + InstanceIDWithSubtype.sSubtypeInstances.size()); |
| + } |
| + FakeInstanceIDWithSubtype iid = |
| + (FakeInstanceIDWithSubtype) InstanceIDWithSubtype.sSubtypeInstances.values() |
| + .iterator() |
| + .next(); |
| + if (iid.mTokens.size() != 1) { |
| + throw new IllegalStateException( |
| + "Expected exactly one token, but there are " + iid.mTokens.size()); |
| + } |
| + String authorizedEntity = iid.mTokens.keySet().iterator().next().split(",", 3)[1]; |
| + return Pair.create(iid.getSubtype(), authorizedEntity); |
| + } |
| + |
| private FakeInstanceIDWithSubtype(Context context, String subtype) { |
| super(context, subtype); |