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

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

Issue 2337963003: Plumb through notification action types and placeholders on Android (Closed)
Patch Set: Responding to review comments Created 4 years, 3 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/CustomNotificationBuilderTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilderTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilderTest.java
index 1c9d80da0b719a2dcb08c76a64cb4a42e74da7d6..7f440954d6dc00f54cdecebcfe5272d4dfa960dd 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilderTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilderTest.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.notifications;
+import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
@@ -23,6 +24,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import org.chromium.base.test.util.Feature;
+import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.chrome.R;
import org.chromium.content.browser.test.NativeLibraryTestBase;
@@ -59,23 +61,24 @@ public class CustomNotificationBuilderTest extends NativeLibraryTestBase {
new int[] {Color.WHITE}, 1 /* width */, 1 /* height */, Bitmap.Config.ARGB_8888);
actionIcon = actionIcon.copy(Bitmap.Config.ARGB_8888, true /* isMutable */);
- Notification notification =
- new CustomNotificationBuilder(context)
- .setSmallIcon(R.drawable.ic_chrome)
- .setLargeIcon(largeIcon)
- .setTitle("title")
- .setBody("body")
- .setOrigin("origin")
- .setTicker("ticker")
- .setDefaults(Notification.DEFAULT_ALL)
- .setVibrate(new long[] {100L})
- .setContentIntent(contentIntent)
- .setDeleteIntent(deleteIntent)
- .addAction(actionIcon, "button", createIntent(context, "ActionButtonOne"))
- .addAction(actionIcon, "button", createIntent(context, "ActionButtonTwo"))
- .addSettingsAction(
- 0 /* iconId */, "settings", createIntent(context, "SettingsButton"))
- .build();
+ Notification notification = new CustomNotificationBuilder(
+ context).setSmallIcon(R.drawable.ic_chrome)
awdf 2016/09/26 15:33:29 git cl format is responsible for this ugly linebre
Peter Beverloo 2016/09/26 16:04:34 I don't think we force "git cl format" over our Ja
awdf 2016/09/27 14:45:27 Done. Manually overriding the auto format tool th
Peter Beverloo 2016/09/27 15:28:31 https://chromium.googlesource.com/chromium/src/+/m
+ .setLargeIcon(largeIcon)
+ .setTitle("title")
+ .setBody("body")
+ .setOrigin("origin")
+ .setTicker("ticker")
+ .setDefaults(Notification.DEFAULT_ALL)
+ .setVibrate(new long[] {100L})
+ .setContentIntent(contentIntent)
+ .setDeleteIntent(deleteIntent)
+ .addButtonAction(actionIcon, "button",
+ createIntent(context, "ActionButtonOne"))
+ .addButtonAction(actionIcon, "button",
+ createIntent(context, "ActionButtonTwo"))
+ .addSettingsAction(0 /* iconId */, "settings",
+ createIntent(context, "SettingsButton"))
+ .build();
assertSmallNotificationIconAsExpected(context, notification, smallIcon);
assertLargeNotificationIconAsExpected(context, notification, largeIcon);
@@ -137,12 +140,12 @@ public class CustomNotificationBuilderTest extends NativeLibraryTestBase {
public void testMaxActionButtons() {
Context context = getInstrumentation().getTargetContext();
NotificationBuilderBase builder = new CustomNotificationBuilder(context)
- .addAction(null /* iconBitmap */, "button",
+ .addButtonAction(null /* iconBitmap */, "button",
createIntent(context, "ActionButtonOne"))
- .addAction(null /* iconBitmap */, "button",
+ .addButtonAction(null /* iconBitmap */, "button",
createIntent(context, "ActionButtonTwo"));
try {
- builder.addAction(
+ builder.addButtonAction(
null /* iconBitmap */, "button", createIntent(context, "ActionButtonThree"));
fail("This statement should not be reached as the previous statement should throw.");
} catch (IllegalStateException e) {
@@ -173,12 +176,12 @@ public class CustomNotificationBuilderTest extends NativeLibraryTestBase {
new int[] {Color.RED}, 1 /* width */, 1 /* height */, Bitmap.Config.ARGB_8888);
actionIcon = actionIcon.copy(Bitmap.Config.ARGB_8888, true /* isMutable */);
- Notification notification =
- new CustomNotificationBuilder(context)
- .setLargeIcon(largeIcon)
- .setSmallIcon(smallIcon)
- .addAction(actionIcon, "button", createIntent(context, "ActionButton"))
- .build();
+ Notification notification = new CustomNotificationBuilder(
+ context).setLargeIcon(largeIcon)
+ .setSmallIcon(smallIcon)
+ .addButtonAction(actionIcon, "button",
+ createIntent(context, "ActionButton"))
+ .build();
// The large icon should be unchanged.
assertLargeNotificationIconAsExpected(context, notification, largeIcon);
@@ -207,7 +210,7 @@ public class CustomNotificationBuilderTest extends NativeLibraryTestBase {
.setBody(createString('b', maxLength + 1))
.setOrigin(createString('c', maxLength + 1))
.setTicker(createString('d', maxLength + 1))
- .addAction(null /* iconBitmap */, createString('e', maxLength + 1),
+ .addButtonAction(null /* iconBitmap */, createString('e', maxLength + 1),
createIntent(context, "ActionButtonOne"))
.build();
View compactView = notification.contentView.apply(context, new LinearLayout(context));
@@ -279,6 +282,30 @@ public class CustomNotificationBuilderTest extends NativeLibraryTestBase {
assertLargeNotificationIconAsExpected(context, notification, expectedIcon);
}
+ /**
+ * Tests that adding a text action results in a notification action with a RemoteInput attached.
+ *
+ * Note that the action buttons in custom layouts will not trigger an inline reply, but we can
+ * still check the notification's action properties since these are used on Android Wear.
+ */
+ @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH)
+ @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs were only added in KITKAT_WATCH.
+ @SmallTest
+ @Feature({"Browser", "Notifications"})
+ public void testAddTextActionSetsRemoteInput() {
+ Context context = getInstrumentation().getTargetContext();
+ NotificationBuilderBase notificationBuilder = new CustomNotificationBuilder(
+ context).addTextAction(null, "Action Title", null, "Placeholder");
+
+ Notification notification = notificationBuilder.build();
+
+ assertEquals(1, notification.actions.length);
+ assertEquals("Action Title", notification.actions[0].title);
+ assertNotNull(notification.actions[0].getRemoteInputs());
+ assertEquals(1, notification.actions[0].getRemoteInputs().length);
+ assertEquals("Placeholder", notification.actions[0].getRemoteInputs()[0].getLabel());
+ }
+
private static void assertLargeNotificationIconAsExpected(
Context context, Notification notification, Bitmap expectedIcon) {
// 1. Check large icon property on the notification.

Powered by Google App Engine
This is Rietveld 408576698