| 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 f725c324a5d391afdd7f6a9d267cac2e494ee9c0..acadebd06427bd2166eeef4cd961def8c3977c93 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
|
| @@ -47,14 +47,16 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
|
| public void testDefaultNotificationProperties() throws Exception {
|
| loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE));
|
| setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
|
| + Context context = getInstrumentation().getTargetContext();
|
|
|
| Notification notification = showAndGetNotification("MyNotification", "{ body: 'Hello' }");
|
| + String expectedOrigin =
|
| + UrlFormatter.formatUrlForSecurityDisplay(getOrigin(), false /* showScheme */);
|
|
|
| // Validate the contents of the notification.
|
| assertEquals("MyNotification", NotificationTestUtil.getExtraTitle(notification));
|
| assertEquals("Hello", NotificationTestUtil.getExtraText(notification));
|
| - assertEquals(UrlFormatter.formatUrlForSecurityDisplay(getOrigin(), false /* showScheme */),
|
| - NotificationTestUtil.getExtraSubText(notification));
|
| + assertEquals(expectedOrigin, NotificationTestUtil.getExtraSubText(notification));
|
|
|
| // Verify that the ticker text contains the notification's title and body.
|
| String tickerText = notification.tickerText.toString();
|
| @@ -62,12 +64,21 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
|
| assertTrue(tickerText.contains("MyNotification"));
|
| assertTrue(tickerText.contains("Hello"));
|
|
|
| + // On L+, verify the public version of the notification contains the notification's origin,
|
| + // and that the body text has been replaced.
|
| + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
| + assertNotNull(notification.publicVersion);
|
| + assertEquals(
|
| + expectedOrigin, NotificationTestUtil.getExtraTitle(notification.publicVersion));
|
| + assertEquals(context.getString(R.string.notification_hidden_text),
|
| + NotificationTestUtil.getExtraText(notification.publicVersion));
|
| + }
|
| +
|
| // Verify that the notification's timestamp is set in the past 60 seconds. This number has
|
| // no significance, but needs to be high enough to not cause flakiness as it's set by the
|
| // renderer process on notification creation.
|
| assertTrue(Math.abs(System.currentTimeMillis() - notification.when) < 60 * 1000);
|
|
|
| - Context context = getInstrumentation().getTargetContext();
|
| assertNotNull(NotificationTestUtil.getLargeIconFromNotification(context, notification));
|
|
|
| // Validate the notification's behavior.
|
| @@ -182,8 +193,9 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
|
|
|
| /**
|
| * Verifies that on Android M+, notifications which specify a badge will have that icon
|
| - * fetched and included as the small icon in the notification.
|
| - * If the test target is L or below, verifies the small icon is the expected chrome logo.
|
| + * fetched and included as the small icon in the notification and public version.
|
| + * If the test target is L or below, verifies the small icon (and public small icon on L) is
|
| + * the expected chrome logo.
|
| */
|
| @MediumTest
|
| @Feature({"Browser", "Notifications"})
|
| @@ -201,16 +213,33 @@ public class NotificationPlatformBridgeTest extends NotificationTestBase {
|
| assertNotNull(smallIcon);
|
|
|
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
| + // Custom badges are only supported on M+.
|
| + // 1. Check the notification badge.
|
| URL badgeUrl =
|
| new URL(getTestServer().getURL("/chrome/test/data/notifications/badge.png"));
|
| Bitmap bitmap = BitmapFactory.decodeStream(badgeUrl.openStream());
|
| Bitmap expected = bitmap.copy(bitmap.getConfig(), true);
|
| NotificationBuilderBase.applyWhiteOverlayToBitmap(expected);
|
| assertTrue(expected.sameAs(smallIcon));
|
| +
|
| + // 2. Check the public notification badge.
|
| + assertNotNull(notification.publicVersion);
|
| + Bitmap publicSmallIcon = NotificationTestUtil.getSmallIconFromNotification(
|
| + context, notification.publicVersion);
|
| + assertNotNull(publicSmallIcon);
|
| + assertTrue(expected.sameAs(publicSmallIcon));
|
| } else {
|
| Bitmap expected =
|
| BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_chrome);
|
| assertTrue(expected.sameAs(smallIcon));
|
| +
|
| + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
| + // Public versions of notifications are only supported on L+.
|
| + assertNotNull(notification.publicVersion);
|
| + Bitmap publicSmallIcon = NotificationTestUtil.getSmallIconFromNotification(
|
| + context, notification.publicVersion);
|
| + assertTrue(expected.sameAs(publicSmallIcon));
|
| + }
|
| }
|
| }
|
|
|
|
|