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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeTest.java

Issue 2748103011: Grant origins engagement for having interactions on their notifications. (Closed)
Patch Set: Unfriend Created 3 years, 9 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: 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..e12d0f583b2d34646bd90d41c144018f6ed11a0a 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;
@@ -41,6 +43,8 @@ import org.chromium.content.browser.test.util.CriteriaHelper;
import java.net.URL;
import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/**
@@ -56,6 +60,7 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
@Override
protected void setUp() throws Exception {
super.setUp();
+ SiteEngagementService.setParamValuesForTesting();
loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE));
}
@@ -99,6 +104,21 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
assertTrue(getNotificationEntries().isEmpty());
}
+ private double getEngagementScoreBlocking() {
+ try {
+ return ThreadUtils.runOnUiThreadBlocking(new Callable<Double>() {
+ @Override
+ public Double call() throws Exception {
+ return SiteEngagementService.getForProfile(Profile.getLastUsedProfile())
+ .getScore(getOrigin());
+ }
+ });
+ } catch (ExecutionException ex) {
+ assert false : "Unexpected ExecutionException";
+ }
+ return 0.0;
+ }
+
/**
* Verifies that notifcations cannot be shown without permission, and that dismissing or denying
* the infobar works correctly.
@@ -263,7 +283,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 +295,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
Context context = getInstrumentation().getTargetContext();
+ // +5 engagement from notification permission and +0.5 from navigating to the test page.
+ assertEquals(5.5, getEngagementScoreBlocking());
Notification notification = showAndGetNotification("MyNotification", "{ "
+ " actions: [{action: 'myAction', title: 'reply', type: 'text'}],"
+ " data: 'ACTION_REPLY'}");
@@ -289,13 +312,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");
+ assertEquals(6.5, getEngagementScoreBlocking());
}
/**
* 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 +332,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
Context context = getInstrumentation().getTargetContext();
+ // +5 engagement from notification permission and +0.5 from navigating to the test page.
+ assertEquals(5.5, getEngagementScoreBlocking());
Notification notification = showAndGetNotification("MyNotification", "{ "
+ " actions: [{action: 'myAction', title: 'reply', type: 'text'}],"
+ " data: 'ACTION_REPLY'}");
@@ -321,7 +349,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:");
+ assertEquals(6.5, getEngagementScoreBlocking());
}
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT_WATCH.
@@ -340,7 +370,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 +380,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
public void testReplyToNotificationWithNoRemoteInput() throws Exception {
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
+ // +5 engagement from notification permission and +0.5 from navigating to the test page.
+ assertEquals(5.5, getEngagementScoreBlocking());
Notification notification = showAndGetNotification("MyNotification", "{ "
+ " actions: [{action: 'myAction', title: 'reply', type: 'text'}],"
+ " data: 'ACTION_REPLY'}");
@@ -357,7 +390,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");
+ assertEquals(6.5, getEngagementScoreBlocking());
}
/**
@@ -579,6 +614,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
@RetryOnFailure
public void testNotificationContentIntentClosesNotification() throws Exception {
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
+ // +5 engagement from notification permission and +0.5 from navigating to the test page.
+ assertEquals(5.5, getEngagementScoreBlocking());
Notification notification = showAndGetNotification("MyNotification", "{}");
@@ -588,8 +625,10 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
// The Service Worker will close the notification upon receiving the notificationclick
// event. This will eventually bubble up to a call to cancel() in the NotificationManager.
+ // Expect +1 engagement from interacting with the notification.
waitForNotificationManagerMutation();
assertTrue(getNotificationEntries().isEmpty());
+ assertEquals(6.5, getEngagementScoreBlocking());
}
/**
@@ -635,6 +674,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
@Feature({"Browser", "Notifications"})
public void testNotificationTagReplacement() throws Exception {
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
+ // +5 engagement from notification permission and +0.5 from navigating to the test page.
+ assertEquals(5.5, getEngagementScoreBlocking());
runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {tag: 'myTag'});");
waitForNotificationManagerMutation();
@@ -657,6 +698,9 @@ 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);
+
+ // Engagement should not have changed since we didn't interact.
+ assertEquals(5.5, getEngagementScoreBlocking());
}
/**
@@ -667,6 +711,8 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
@Feature({"Browser", "Notifications"})
public void testShowAndCloseMultipleNotifications() throws Exception {
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
+ // +5 engagement from notification permission and +0.5 from navigating to the test page.
+ assertEquals(5.5, getEngagementScoreBlocking());
// Open the first notification and verify it is displayed.
runJavaScriptCodeInCurrentTab("showNotification('One');");
@@ -707,9 +753,15 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
assertEquals(1, notifications.size());
assertEquals("Two", NotificationTestUtil.getExtraTitle(notifications.get(0).notification));
+ // Expect +1 engagement from interacting with the notification.
+ assertEquals(6.5, getEngagementScoreBlocking());
+
// Close the last notification and verify that none remain.
notifications.get(0).notification.contentIntent.send();
waitForNotificationManagerMutation();
assertTrue(getNotificationEntries().isEmpty());
+
+ // Expect +1 engagement from interacting with the notification.
+ assertEquals(7.5, getEngagementScoreBlocking());
}
}

Powered by Google App Engine
This is Rietveld 408576698