| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.notifications; | 5 package org.chromium.chrome.browser.notifications; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; |
| 7 import android.app.Notification; | 8 import android.app.Notification; |
| 8 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
| 9 import android.content.Context; | 10 import android.content.Context; |
| 10 import android.content.Intent; | 11 import android.content.Intent; |
| 11 import android.graphics.Bitmap; | 12 import android.graphics.Bitmap; |
| 12 import android.graphics.BitmapFactory; | 13 import android.graphics.BitmapFactory; |
| 13 import android.graphics.Color; | 14 import android.graphics.Color; |
| 14 import android.os.Build; | 15 import android.os.Build; |
| 15 import android.test.suitebuilder.annotation.SmallTest; | 16 import android.test.suitebuilder.annotation.SmallTest; |
| 16 import android.text.SpannableStringBuilder; | 17 import android.text.SpannableStringBuilder; |
| 17 | 18 |
| 18 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
| 20 import org.chromium.base.test.util.MinAndroidSdkLevel; |
| 19 import org.chromium.chrome.R; | 21 import org.chromium.chrome.R; |
| 20 import org.chromium.chrome.browser.util.UrlUtilities; | 22 import org.chromium.chrome.browser.util.UrlUtilities; |
| 21 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 23 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
| 22 import org.chromium.content.browser.test.NativeLibraryTestBase; | 24 import org.chromium.content.browser.test.NativeLibraryTestBase; |
| 23 | 25 |
| 24 /** | 26 /** |
| 25 * Instrumentation unit tests for StandardNotificationBuilder. | 27 * Instrumentation unit tests for StandardNotificationBuilder. |
| 26 * | 28 * |
| 27 * Extends NativeLibraryTestBase so that {@link UrlUtilities#getDomainAndRegistr
y} can access | 29 * Extends NativeLibraryTestBase so that {@link UrlUtilities#getDomainAndRegistr
y} can access |
| 28 * native GetDomainAndRegistry, when called by {@link RoundedIconGenerator#getIc
onTextForUrl} during | 30 * native GetDomainAndRegistry, when called by {@link RoundedIconGenerator#getIc
onTextForUrl} during |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 .setBody("body") | 71 .setBody("body") |
| 70 .setOrigin("origin") | 72 .setOrigin("origin") |
| 71 .setTicker(new SpannableStringBuilder("ticker")) | 73 .setTicker(new SpannableStringBuilder("ticker")) |
| 72 .setImage(image) | 74 .setImage(image) |
| 73 .setLargeIcon(largeIcon) | 75 .setLargeIcon(largeIcon) |
| 74 .setSmallIcon(R.drawable.ic_chrome) | 76 .setSmallIcon(R.drawable.ic_chrome) |
| 75 .setDefaults(Notification.DEFAULT_ALL) | 77 .setDefaults(Notification.DEFAULT_ALL) |
| 76 .setVibrate(new long[] {100L}) | 78 .setVibrate(new long[] {100L}) |
| 77 .setContentIntent(outContentAndDeleteIntents[0]) | 79 .setContentIntent(outContentAndDeleteIntents[0]) |
| 78 .setDeleteIntent(outContentAndDeleteIntents[1]) | 80 .setDeleteIntent(outContentAndDeleteIntents[1]) |
| 79 .addAction(actionIcon, "button 1", null /* intent */) | 81 .addButtonAction(actionIcon, "button 1", null /* intent */) |
| 80 .addAction(actionIcon, "button 2", null /* intent */) | 82 .addButtonAction(actionIcon, "button 2", null /* intent */) |
| 81 .addSettingsAction(0 /* iconId */, "settings", null /* intent */
); | 83 .addSettingsAction(0 /* iconId */, "settings", null /* intent */
); |
| 82 } | 84 } |
| 83 | 85 |
| 84 @SmallTest | 86 @SmallTest |
| 85 @Feature({"Browser", "Notifications"}) | 87 @Feature({"Browser", "Notifications"}) |
| 86 public void testSetAll() { | 88 public void testSetAll() { |
| 87 PendingIntent[] contentAndDeleteIntents = new PendingIntent[2]; | 89 PendingIntent[] contentAndDeleteIntents = new PendingIntent[2]; |
| 88 NotificationBuilderBase builder = createAllOptionsBuilder(contentAndDele
teIntents); | 90 NotificationBuilderBase builder = createAllOptionsBuilder(contentAndDele
teIntents); |
| 89 Notification notification = builder.build(); | 91 Notification notification = builder.build(); |
| 90 | 92 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 otherBuilder.setSmallIcon(bitmap); | 179 otherBuilder.setSmallIcon(bitmap); |
| 178 Notification otherNotification = otherBuilder.build(); | 180 Notification otherNotification = otherBuilder.build(); |
| 179 assertTrue(expected.sameAs( | 181 assertTrue(expected.sameAs( |
| 180 NotificationTestUtil.getSmallIconFromNotification(context, o
therNotification))); | 182 NotificationTestUtil.getSmallIconFromNotification(context, o
therNotification))); |
| 181 } else { | 183 } else { |
| 182 Bitmap expected = | 184 Bitmap expected = |
| 183 BitmapFactory.decodeResource(context.getResources(), R.drawa
ble.ic_chrome); | 185 BitmapFactory.decodeResource(context.getResources(), R.drawa
ble.ic_chrome); |
| 184 assertTrue(expected.sameAs(result)); | 186 assertTrue(expected.sameAs(result)); |
| 185 } | 187 } |
| 186 } | 188 } |
| 189 |
| 190 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) |
| 191 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs were only added
in KITKAT_WATCH. |
| 192 @SmallTest |
| 193 @Feature({"Browser", "Notifications"}) |
| 194 public void testAddTextActionSetsRemoteInput() { |
| 195 Context context = getInstrumentation().getTargetContext(); |
| 196 NotificationBuilderBase notificationBuilder = new StandardNotificationBu
ilder( |
| 197 context).addTextAction(null, "Action Title", null, "Placeholder"
); |
| 198 |
| 199 Notification notification = notificationBuilder.build(); |
| 200 |
| 201 assertEquals(1, notification.actions.length); |
| 202 assertEquals("Action Title", notification.actions[0].title); |
| 203 assertNotNull(notification.actions[0].getRemoteInputs()); |
| 204 assertEquals(1, notification.actions[0].getRemoteInputs().length); |
| 205 assertEquals("Placeholder", notification.actions[0].getRemoteInputs()[0]
.getLabel()); |
| 206 } |
| 187 } | 207 } |
| OLD | NEW |