Index: chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeTest.java |
index 6c52883bb8aa5b053222b20068059b6752dbc99f..42ddd6cee200b3f3c6987ed6a9b4c89a8b70afef 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeTest.java |
@@ -27,9 +27,11 @@ import org.chromium.base.test.util.Feature; |
import org.chromium.base.test.util.MinAndroidSdkLevel; |
import org.chromium.base.test.util.RetryOnFailure; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.engagement.SiteEngagementService; |
import org.chromium.chrome.browser.infobar.InfoBar; |
import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
import org.chromium.chrome.browser.preferences.website.ContentSetting; |
+import org.chromium.chrome.browser.profiles.Profile; |
import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
import org.chromium.chrome.test.util.InfoBarUtil; |
@@ -56,6 +58,7 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
@Override |
protected void setUp() throws Exception { |
super.setUp(); |
+ SiteEngagementService.setParamValuesForTesting(); |
loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); |
} |
@@ -99,6 +102,17 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
assertTrue(getNotificationEntries().isEmpty()); |
} |
+ private void checkEngagementScore(final double expectedScore) { |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
Peter Beverloo
2017/03/16 12:24:14
Optional comment:
There's an overload of runOnUiT
dominickn
2017/03/16 23:25:03
Thanks! This is much nicer. Done.
|
+ @Override |
+ public void run() { |
+ assertEquals(expectedScore, |
+ SiteEngagementService.getForProfile(Profile.getLastUsedProfile()) |
+ .getScore(getOrigin())); |
+ } |
+ }); |
+ } |
+ |
/** |
* Verifies that notifcations cannot be shown without permission, and that dismissing or denying |
* the infobar works correctly. |
@@ -263,7 +277,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
/** |
* Verifies that setting a reply on the remote input of a notification action with type 'text' |
* and triggering the action's intent causes the same reply to be received in the subsequent |
- * notificationclick event on the service worker. |
+ * notificationclick event on the service worker. Verifies that site engagement is incremented |
+ * appropriately. |
*/ |
@CommandLineFlags.Add("enable-experimental-web-platform-features") |
@MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) |
@@ -274,6 +289,9 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
Context context = getInstrumentation().getTargetContext(); |
+ // We expect +5 engagement from having notification permission and +0.5 from navigating to |
+ // the test page. |
+ checkEngagementScore(5.5); |
Notification notification = showAndGetNotification("MyNotification", "{ " |
+ " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," |
+ " data: 'ACTION_REPLY'}"); |
@@ -289,13 +307,16 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
remoteInputs[0].getResultKey(), "My Reply" /* reply */); |
// Check reply was received by the service worker (see android_test_worker.js). |
+ // Expect +1 engagement from interacting with the notification. |
waitForTitle("reply: My Reply"); |
+ checkEngagementScore(6.5); |
} |
/** |
* Verifies that setting an empty reply on the remote input of a notification action with type |
* 'text' and triggering the action's intent causes an empty reply string to be received in the |
- * subsequent notificationclick event on the service worker. |
+ * subsequent notificationclick event on the service worker. Verifies that site engagement is |
+ * incremented appropriately. |
*/ |
@CommandLineFlags.Add("enable-experimental-web-platform-features") |
@MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) |
@@ -306,6 +327,9 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
Context context = getInstrumentation().getTargetContext(); |
+ // We expect +5 engagement from having notification permission and +0.5 from navigating to |
+ // the test page. |
+ checkEngagementScore(5.5); |
Notification notification = showAndGetNotification("MyNotification", "{ " |
+ " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," |
+ " data: 'ACTION_REPLY'}"); |
@@ -321,7 +345,9 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
remoteInputs[0].getResultKey(), "" /* reply */); |
// Check empty reply was received by the service worker (see android_test_worker.js). |
+ // Expect +1 engagement from interacting with the notification. |
waitForTitle("reply:"); |
+ checkEngagementScore(6.5); |
} |
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT_WATCH. |
@@ -340,7 +366,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
/** |
* Verifies that *not* setting a reply on the remote input of a notification action with type |
* 'text' and triggering the action's intent causes a null reply to be received in the |
- * subsequent notificationclick event on the service worker. |
+ * subsequent notificationclick event on the service worker. Verifies that site engagement is |
+ * incremented appropriately. |
*/ |
@TargetApi(Build.VERSION_CODES.KITKAT) // Notification.Action.actionIntent added in Android K. |
@CommandLineFlags.Add("enable-experimental-web-platform-features") |
@@ -349,6 +376,9 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
public void testReplyToNotificationWithNoRemoteInput() throws Exception { |
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
+ // We expect +5 engagement from having notification permission and +0.5 from navigating to |
+ // the test page. |
+ checkEngagementScore(5.5); |
Notification notification = showAndGetNotification("MyNotification", "{ " |
+ " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," |
+ " data: 'ACTION_REPLY'}"); |
@@ -357,7 +387,9 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
notification.actions[0].actionIntent.send(); |
// Check reply was received by the service worker (see android_test_worker.js). |
+ // Expect +1 engagement from interacting with the notification. |
waitForTitle("reply: null"); |
+ checkEngagementScore(6.5); |
} |
/** |
@@ -579,6 +611,7 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
@RetryOnFailure |
public void testNotificationContentIntentClosesNotification() throws Exception { |
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
+ checkEngagementScore(5.5); |
Notification notification = showAndGetNotification("MyNotification", "{}"); |
@@ -590,6 +623,7 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
// event. This will eventually bubble up to a call to cancel() in the NotificationManager. |
waitForNotificationManagerMutation(); |
assertTrue(getNotificationEntries().isEmpty()); |
+ checkEngagementScore(6.5); |
} |
/** |
@@ -635,6 +669,7 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
@Feature({"Browser", "Notifications"}) |
public void testNotificationTagReplacement() throws Exception { |
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
+ checkEngagementScore(5.5); |
runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {tag: 'myTag'});"); |
waitForNotificationManagerMutation(); |
@@ -657,6 +692,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
// Verify that as always, the same integer is used, also for replaced notifications. |
assertEquals(id, notifications.get(0).id); |
assertEquals(NotificationPlatformBridge.PLATFORM_ID, notifications.get(0).id); |
+ |
+ checkEngagementScore(5.5); |
} |
/** |
@@ -667,6 +704,7 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
@Feature({"Browser", "Notifications"}) |
public void testShowAndCloseMultipleNotifications() throws Exception { |
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
+ checkEngagementScore(5.5); |
// Open the first notification and verify it is displayed. |
runJavaScriptCodeInCurrentTab("showNotification('One');"); |
@@ -707,9 +745,13 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase { |
assertEquals(1, notifications.size()); |
assertEquals("Two", NotificationTestUtil.getExtraTitle(notifications.get(0).notification)); |
+ checkEngagementScore(6.5); |
+ |
// Close the last notification and verify that none remain. |
notifications.get(0).notification.contentIntent.send(); |
waitForNotificationManagerMutation(); |
assertTrue(getNotificationEntries().isEmpty()); |
+ |
+ checkEngagementScore(7.5); |
} |
} |