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

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

Issue 1899753002: Make InstanceIDBridge fully async to fix strict mode violations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid3test
Patch Set: |this| 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/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 ebdba3c9af5dc8630475baa95a73ceab7c4b0ae1..adb69823443786366718ac14b0c38678bfc7c6d9 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
@@ -54,10 +54,22 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
private FakeInstanceIDWithSubtype(Context context, String subtype) {
super(context, subtype);
+
+ // The first call to InstanceIDWithSubtype.getInstance calls InstanceID.getInstance which
+ // triggers a strict mode violation if it's called on the main thread, by reading from
+ // SharedPreferences. Since we can't override those static methods to simulate the strict
+ // mode violation in tests, check the thread here (which is only called from getInstance).
+ if (Looper.getMainLooper() == Looper.myLooper())
+ throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
}
@Override
public String getId() {
+ // InstanceID.getId sometimes triggers a strict mode violation if it's called on the main
+ // thread, by reading from SharedPreferences.
+ if (Looper.getMainLooper() == Looper.myLooper())
+ throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
+
if (mId == null) {
mCreationTime = System.currentTimeMillis();
mId = randomBase64(11 /* length */);
@@ -67,6 +79,11 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
@Override
public long getCreationTime() {
+ // InstanceID.getCreationTime sometimes triggers a strict mode violation if it's called on
+ // the main thread, by reading from SharedPreferences.
+ if (Looper.getMainLooper() == Looper.myLooper())
+ throw new AssertionError(InstanceID.ERROR_MAIN_THREAD);
+
return mCreationTime;
}
@@ -78,9 +95,11 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
@Override
public String getToken(String authorizedEntity, String scope, Bundle extras)
throws IOException {
+ // InstanceID.getToken enforces this.
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new IOException(InstanceID.ERROR_MAIN_THREAD);
}
+
String key = getSubtype() + ',' + authorizedEntity + ',' + scope;
String token = mTokens.get(key);
if (token == null) {
@@ -93,9 +112,11 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
@Override
public void deleteToken(String authorizedEntity, String scope) throws IOException {
+ // InstanceID.deleteToken enforces this.
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new IOException(InstanceID.ERROR_MAIN_THREAD);
}
+
String key = getSubtype() + ',' + authorizedEntity + ',' + scope;
mTokens.remove(key);
// Calling deleteToken causes ID to be generated; can be observed though getCreationTime.
@@ -106,9 +127,12 @@ public class FakeInstanceIDWithSubtype extends InstanceIDWithSubtype {
public void deleteInstanceID() throws IOException {
synchronized (InstanceID.class) {
sSubtypeInstances.remove(getSubtype());
+
+ // InstanceID.deleteInstanceID calls InstanceID.deleteToken which enforces this.
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new IOException(InstanceID.ERROR_MAIN_THREAD);
}
+
mTokens.clear();
mCreationTime = 0;
mId = null;

Powered by Google App Engine
This is Rietveld 408576698