| Index: components/gcm_driver/instance_id/android/java/src/org/chromium/components/gcm_driver/instance_id/InstanceIDWithSubtype.java
|
| diff --git a/components/gcm_driver/instance_id/android/java/src/org/chromium/components/gcm_driver/instance_id/InstanceIDWithSubtype.java b/components/gcm_driver/instance_id/android/java/src/org/chromium/components/gcm_driver/instance_id/InstanceIDWithSubtype.java
|
| index ca3cc8f90f062a870b54f97dc3b4720f12251794..a806317ea626c02c4f6ea94ecd7e731d924b5254 100644
|
| --- a/components/gcm_driver/instance_id/android/java/src/org/chromium/components/gcm_driver/instance_id/InstanceIDWithSubtype.java
|
| +++ b/components/gcm_driver/instance_id/android/java/src/org/chromium/components/gcm_driver/instance_id/InstanceIDWithSubtype.java
|
| @@ -26,9 +26,10 @@ public class InstanceIDWithSubtype extends InstanceID {
|
| private long mNativeInstanceIDAndroid;
|
| private final String mSubtype;
|
|
|
| + private static boolean sUseFakeForTesting = false;
|
| private static Map<String, InstanceIDWithSubtype> sSubtypeInstances = new HashMap<>();
|
|
|
| - private InstanceIDWithSubtype(long nativeInstanceIDAndroid, Context context, String subtype) {
|
| + protected InstanceIDWithSubtype(long nativeInstanceIDAndroid, Context context, String subtype) {
|
| super(context, subtype, null /* options */);
|
| mNativeInstanceIDAndroid = nativeInstanceIDAndroid;
|
| mSubtype = subtype;
|
| @@ -43,7 +44,7 @@ public class InstanceIDWithSubtype extends InstanceID {
|
| }
|
| context = context.getApplicationContext();
|
|
|
| - if (sSubtypeInstances.isEmpty()) {
|
| + if (sSubtypeInstances.isEmpty() && !sUseFakeForTesting) {
|
| // Warm up the InstanceID system, by getting then discarding the default InstanceID.
|
| // This causes some important static fields to be initialized.
|
| InstanceID.getInstance(context);
|
| @@ -51,13 +52,28 @@ public class InstanceIDWithSubtype extends InstanceID {
|
|
|
| InstanceIDWithSubtype existing = sSubtypeInstances.get(subtype);
|
| if (existing == null) {
|
| - existing = new InstanceIDWithSubtype(nativeInstanceIDAndroid, context, subtype);
|
| + if (sUseFakeForTesting) {
|
| + existing = new FakeInstanceIDWithSubtype(
|
| + nativeInstanceIDAndroid, context, subtype);
|
| + } else {
|
| + existing = new InstanceIDWithSubtype(nativeInstanceIDAndroid, context, subtype);
|
| + }
|
| sSubtypeInstances.put(subtype, existing);
|
| }
|
| return existing;
|
| }
|
| }
|
|
|
| + @CalledByNative
|
| + public static void clearDataAndSetUseFakeForTesting(boolean useFake) {
|
| + sSubtypeInstances.clear();
|
| + sUseFakeForTesting = useFake;
|
| + }
|
| +
|
| + public static Map<String, InstanceIDWithSubtype> getInstanceIDsForTesting() {
|
| + return sSubtypeInstances;
|
| + }
|
| +
|
| @Override
|
| public void deleteInstanceID() throws IOException {
|
| synchronized (InstanceID.class) {
|
|
|