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

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

Issue 1394423004: Initial skeleton of custom layouts for Web Notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address peter's issues. Created 5 years, 2 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 unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698