| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.notifications; |
| 6 |
| 7 import android.annotation.SuppressLint; |
| 8 import android.app.Notification; |
| 9 import android.app.PendingIntent; |
| 10 import android.content.Context; |
| 11 import android.content.Intent; |
| 12 import android.graphics.Bitmap; |
| 13 import android.graphics.Color; |
| 14 import android.test.InstrumentationTestCase; |
| 15 import android.test.suitebuilder.annotation.SmallTest; |
| 16 import android.text.SpannableStringBuilder; |
| 17 |
| 18 import org.chromium.base.test.util.Feature; |
| 19 import org.chromium.chrome.R; |
| 20 |
| 21 /** |
| 22 * Instrumentation unit tests for StandardNotificationBuilder. |
| 23 */ |
| 24 // TODO(peter): remove @SuppressLint once crbug.com/501900 is fixed. |
| 25 @SuppressLint("NewApi") |
| 26 public class StandardNotificationBuilderTest extends InstrumentationTestCase { |
| 27 @SmallTest |
| 28 @Feature({"Browser", "Notifications"}) |
| 29 public void testSetAll() { |
| 30 Context context = getInstrumentation().getTargetContext(); |
| 31 |
| 32 Intent contentIntent = new Intent("contentIntent"); |
| 33 PendingIntent pendingContentIntent = PendingIntent.getBroadcast( |
| 34 context, 0 /* requestCode */, contentIntent, PendingIntent.FLAG_
UPDATE_CURRENT); |
| 35 |
| 36 Intent deleteIntent = new Intent("deleteIntent"); |
| 37 PendingIntent pendingDeleteIntent = PendingIntent.getBroadcast( |
| 38 context, 1 /* requestCode */, deleteIntent, PendingIntent.FLAG_U
PDATE_CURRENT); |
| 39 |
| 40 Bitmap largeIcon = Bitmap.createBitmap( |
| 41 new int[] {Color.RED}, 1 /* width */, 1 /* height */, Bitmap.Con
fig.ARGB_8888); |
| 42 |
| 43 Notification notification = new StandardNotificationBuilder(context) |
| 44 .setSmallIcon(R.drawable.ic_chrome) |
| 45 .setLargeIcon(largeIcon) |
| 46 .setTitle("title") |
| 47 .setBody("body") |
| 48 .setOrigin("origin") |
| 49 .setTicker(new SpannableStringBuilde
r("ticker")) |
| 50 .setDefaults(Notification.DEFAULT_AL
L) |
| 51 .setVibrate(new long[] {100L}) |
| 52 .setContentIntent(pendingContentInte
nt) |
| 53 .setDeleteIntent(pendingDeleteIntent
) |
| 54 .build(); |
| 55 |
| 56 assertEquals(R.drawable.ic_chrome, notification.icon); |
| 57 assertNotNull(notification.largeIcon); |
| 58 assertEquals("title", notification.extras.getString(Notification.EXTRA_T
ITLE)); |
| 59 assertEquals("body", notification.extras.getString(Notification.EXTRA_TE
XT)); |
| 60 assertEquals("origin", notification.extras.getString(Notification.EXTRA_
SUB_TEXT)); |
| 61 assertEquals("ticker", notification.tickerText.toString()); |
| 62 assertEquals(Notification.DEFAULT_ALL, notification.defaults); |
| 63 assertEquals(1, notification.vibrate.length); |
| 64 assertEquals(100L, notification.vibrate[0]); |
| 65 assertEquals(pendingContentIntent, notification.contentIntent); |
| 66 assertEquals(pendingDeleteIntent, notification.deleteIntent); |
| 67 // TODO(mvanouwerkerk): Add coverage for action buttons. |
| 68 } |
| 69 } |
| OLD | NEW |