| 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.app.Notification; |
| 8 import android.app.PendingIntent; |
| 9 import android.content.Context; |
| 10 import android.content.Intent; |
| 11 import android.graphics.Bitmap; |
| 12 import android.graphics.Color; |
| 13 import android.test.InstrumentationTestCase; |
| 14 import android.test.suitebuilder.annotation.SmallTest; |
| 15 import android.text.SpannableStringBuilder; |
| 16 import android.view.View; |
| 17 import android.widget.ImageView; |
| 18 import android.widget.LinearLayout; |
| 19 import android.widget.TextView; |
| 20 |
| 21 import org.chromium.base.test.util.Feature; |
| 22 import org.chromium.chrome.R; |
| 23 |
| 24 /** |
| 25 * Instrumentation unit tests for CustomNotificationBuilder. |
| 26 */ |
| 27 public class CustomNotificationBuilderTest extends InstrumentationTestCase { |
| 28 @SmallTest |
| 29 @Feature({"Browser", "Notifications"}) |
| 30 public void testSetAll() { |
| 31 Context context = getInstrumentation().getTargetContext(); |
| 32 |
| 33 Intent contentIntent = new Intent("contentIntent"); |
| 34 PendingIntent pendingContentIntent = PendingIntent.getBroadcast( |
| 35 context, 0 /* requestCode */, contentIntent, PendingIntent.FLAG_
UPDATE_CURRENT); |
| 36 |
| 37 Intent deleteIntent = new Intent("deleteIntent"); |
| 38 PendingIntent pendingDeleteIntent = PendingIntent.getBroadcast( |
| 39 context, 1 /* requestCode */, deleteIntent, PendingIntent.FLAG_U
PDATE_CURRENT); |
| 40 |
| 41 Bitmap largeIcon = Bitmap.createBitmap( |
| 42 new int[] {Color.RED}, 1 /* width */, 1 /* height */, Bitmap.Con
fig.ARGB_8888); |
| 43 |
| 44 Notification notification = new CustomNotificationBuilder(context) |
| 45 .setSmallIcon(R.drawable.ic_chrome) |
| 46 .setLargeIcon(largeIcon) |
| 47 .setTitle("title") |
| 48 .setBody("body") |
| 49 .setOrigin("origin") |
| 50 .setTicker(new SpannableStringBuilde
r("ticker")) |
| 51 .setDefaults(Notification.DEFAULT_AL
L) |
| 52 .setVibrate(new long[] {100L}) |
| 53 .setContentIntent(pendingContentInte
nt) |
| 54 .setDeleteIntent(pendingDeleteIntent
) |
| 55 .build(); |
| 56 View view = notification.contentView.apply(context, new LinearLayout(con
text)); |
| 57 |
| 58 assertEquals(R.drawable.ic_chrome, notification.icon); |
| 59 assertNotNull(((ImageView) view.findViewById(R.id.icon)).getDrawable()); |
| 60 assertEquals("title", ((TextView) view.findViewById(R.id.title)).getText
()); |
| 61 assertEquals("body", ((TextView) view.findViewById(R.id.body)).getText()
); |
| 62 assertEquals("origin", ((TextView) view.findViewById(R.id.origin)).getTe
xt()); |
| 63 assertEquals("ticker", notification.tickerText.toString()); |
| 64 assertEquals(Notification.DEFAULT_ALL, notification.defaults); |
| 65 assertEquals(1, notification.vibrate.length); |
| 66 assertEquals(100L, notification.vibrate[0]); |
| 67 assertEquals(pendingContentIntent, notification.contentIntent); |
| 68 assertEquals(pendingDeleteIntent, notification.deleteIntent); |
| 69 // TODO(mvanouwerkerk): Add coverage for action buttons. |
| 70 } |
| 71 } |
| OLD | NEW |