Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1197)

Unified Diff: components/gcm_driver/instance_id/android/java/src/org/chromium/components/gcm_driver/instance_id/InstanceIDWithSubtype.java

Issue 1829023002: Add fake for InstanceIDWithSubtype.java, in order to re-use unit test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid2jni
Patch Set: Tweaks Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698