Index: chrome/android/javatests/src/org/chromium/chrome/browser/push_messaging/PushMessagingTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/push_messaging/PushMessagingTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/push_messaging/PushMessagingTest.java |
index d7af8a3b7e0058e86f60d65467512b9e613b19f2..89e495a6df2be2da0b3edf59df10a6cb067a30d8 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/push_messaging/PushMessagingTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/push_messaging/PushMessagingTest.java |
@@ -22,8 +22,9 @@ import org.chromium.chrome.browser.preferences.website.ContentSetting; |
import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.test.util.browser.TabTitleObserver; |
import org.chromium.chrome.test.util.browser.notifications.MockNotificationManagerProxy.NotificationEntry; |
-import org.chromium.components.gcm_driver.FakeGoogleCloudMessagingSubscriber; |
import org.chromium.components.gcm_driver.GCMDriver; |
+import org.chromium.components.gcm_driver.instance_id.FakeInstanceIDWithSubtype; |
+import org.chromium.components.gcm_driver.instance_id.InstanceIDWithSubtype; |
import org.chromium.content.browser.test.util.CallbackHelper; |
import org.chromium.content.browser.test.util.JavaScriptUtils; |
@@ -56,6 +57,7 @@ public class PushMessagingTest |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
+ FakeInstanceIDWithSubtype.clearDataAndSetEnabled(true); |
PushMessagingServiceObserver.setListenerForTesting(listener); |
} |
}); |
@@ -68,6 +70,7 @@ public class PushMessagingTest |
@Override |
public void run() { |
PushMessagingServiceObserver.setListenerForTesting(null); |
+ FakeInstanceIDWithSubtype.clearDataAndSetEnabled(false); |
} |
}); |
super.tearDown(); |
@@ -84,15 +87,11 @@ public class PushMessagingTest |
@MediumTest |
@Feature({"Browser", "PushMessaging"}) |
public void testPushAndShowNotification() throws InterruptedException, TimeoutException { |
- FakeGoogleCloudMessagingSubscriber subscriber = new FakeGoogleCloudMessagingSubscriber(); |
- GCMDriver.overrideSubscriberForTesting(subscriber); |
- |
loadUrl(mPushTestPage); |
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
runScriptAndWaitForTitle("subscribePush()", "subscribe ok"); |
- sendPushAndWaitForCallback( |
- subscriber.getLastSubscribeSubtype(), subscriber.getLastSubscribeSource()); |
+ sendPushAndWaitForCallback(getSubscribedSubtype(), getSubscribedSenderId()); |
NotificationEntry notificationEntry = waitForNotification(); |
assertEquals("push notification 1", |
notificationEntry.notification.extras.getString(Notification.EXTRA_TITLE)); |
@@ -105,9 +104,6 @@ public class PushMessagingTest |
@LargeTest |
@Feature({"Browser", "PushMessaging"}) |
public void testDefaultNotification() throws InterruptedException, TimeoutException { |
- FakeGoogleCloudMessagingSubscriber subscriber = new FakeGoogleCloudMessagingSubscriber(); |
- GCMDriver.overrideSubscriberForTesting(subscriber); |
- |
// Load the push test page into the first tab. |
loadUrl(mPushTestPage); |
assertEquals(1, getActivity().getCurrentTabModel().getCount()); |
@@ -118,8 +114,8 @@ public class PushMessagingTest |
// Set up the push subscription and capture its details. |
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
runScriptAndWaitForTitle("subscribePush()", "subscribe ok"); |
- String appId = subscriber.getLastSubscribeSubtype(); |
- String senderId = subscriber.getLastSubscribeSource(); |
+ String appId = getSubscribedSubtype(); |
+ String senderId = getSubscribedSenderId(); |
// Make the tab invisible by opening another one with a different origin. |
loadUrlInNewTab(ABOUT_BLANK); |
@@ -166,6 +162,19 @@ public class PushMessagingTest |
waitForTitle(tab, expectedTitle); |
} |
+ private String getSubscribedSubtype() { |
+ assertEquals(1, InstanceIDWithSubtype.sSubtypeInstances.size()); |
+ return InstanceIDWithSubtype.sSubtypeInstances.keySet().iterator().next(); |
+ } |
+ |
+ private String getSubscribedSenderId() { |
+ assertEquals(1, InstanceIDWithSubtype.sSubtypeInstances.size()); |
+ InstanceIDWithSubtype iid = |
+ InstanceIDWithSubtype.sSubtypeInstances.values().iterator().next(); |
+ assertEquals(1, iid.mTokens.size()); |
+ return iid.mTokens.keySet().iterator().next().split(",", 3)[1]; |
Peter Beverloo
2016/04/21 13:26:18
Please document this— how should a Chromium Sherif
johnme
2016/05/25 14:11:50
Done (I added a comment to FakeInstanceIDWithSubty
|
+ } |
+ |
private void sendPushAndWaitForCallback(final String appId, final String senderId) |
throws InterruptedException, TimeoutException { |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |