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.app.Notification; | 7 import android.app.Notification; |
8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.graphics.Bitmap; | 11 import android.graphics.Bitmap; |
12 import android.graphics.BitmapFactory; | 12 import android.graphics.BitmapFactory; |
13 import android.graphics.Color; | 13 import android.graphics.Color; |
14 import android.os.Build; | 14 import android.os.Build; |
15 import android.test.InstrumentationTestCase; | |
16 import android.test.suitebuilder.annotation.SmallTest; | 15 import android.test.suitebuilder.annotation.SmallTest; |
17 import android.text.SpannableStringBuilder; | 16 import android.text.SpannableStringBuilder; |
18 | 17 |
19 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
20 import org.chromium.chrome.R; | 19 import org.chromium.chrome.R; |
| 20 import org.chromium.chrome.browser.util.UrlUtilities; |
| 21 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
| 22 import org.chromium.content.browser.test.NativeLibraryTestBase; |
21 | 23 |
22 /** | 24 /** |
23 * Instrumentation unit tests for StandardNotificationBuilder. | 25 * Instrumentation unit tests for StandardNotificationBuilder. |
| 26 * |
| 27 * Extends NativeLibraryTestBase so that {@link UrlUtilities#getDomainAndRegistr
y} can access |
| 28 * native GetDomainAndRegistry, when called by {@link RoundedIconGenerator#getIc
onTextForUrl} during |
| 29 * notification construction. |
24 */ | 30 */ |
25 public class StandardNotificationBuilderTest extends InstrumentationTestCase { | 31 public class StandardNotificationBuilderTest extends NativeLibraryTestBase { |
| 32 @Override |
| 33 public void setUp() throws Exception { |
| 34 super.setUp(); |
| 35 // Not initializing the browser process is safe because GetDomainAndRegi
stry() is |
| 36 // stand-alone. |
| 37 loadNativeLibraryNoBrowserProcess(); |
| 38 } |
| 39 |
26 private NotificationBuilderBase createAllOptionsBuilder( | 40 private NotificationBuilderBase createAllOptionsBuilder( |
27 PendingIntent[] outContentAndDeleteIntents) { | 41 PendingIntent[] outContentAndDeleteIntents) { |
28 if (outContentAndDeleteIntents == null || outContentAndDeleteIntents.len
gth != 2) | 42 if (outContentAndDeleteIntents == null || outContentAndDeleteIntents.len
gth != 2) |
29 throw new IllegalArgumentException(); | 43 throw new IllegalArgumentException(); |
30 | 44 |
31 Context context = getInstrumentation().getTargetContext(); | 45 Context context = getInstrumentation().getTargetContext(); |
32 | 46 |
33 Intent contentIntent = new Intent("contentIntent"); | 47 Intent contentIntent = new Intent("contentIntent"); |
34 outContentAndDeleteIntents[0] = PendingIntent.getBroadcast( | 48 outContentAndDeleteIntents[0] = PendingIntent.getBroadcast( |
35 context, 0 /* requestCode */, contentIntent, PendingIntent.FLAG_
UPDATE_CURRENT); | 49 context, 0 /* requestCode */, contentIntent, PendingIntent.FLAG_
UPDATE_CURRENT); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 assertEquals(Notification.DEFAULT_ALL, notification.defaults); | 111 assertEquals(Notification.DEFAULT_ALL, notification.defaults); |
98 assertEquals(1, notification.vibrate.length); | 112 assertEquals(1, notification.vibrate.length); |
99 assertEquals(100L, notification.vibrate[0]); | 113 assertEquals(100L, notification.vibrate[0]); |
100 assertEquals(contentAndDeleteIntents[0], notification.contentIntent); | 114 assertEquals(contentAndDeleteIntents[0], notification.contentIntent); |
101 assertEquals(contentAndDeleteIntents[1], notification.deleteIntent); | 115 assertEquals(contentAndDeleteIntents[1], notification.deleteIntent); |
102 Notification.Action[] actions = NotificationTestUtil.getActions(notifica
tion); | 116 Notification.Action[] actions = NotificationTestUtil.getActions(notifica
tion); |
103 assertEquals(3, actions.length); | 117 assertEquals(3, actions.length); |
104 assertEquals("button 1", NotificationTestUtil.getActionTitle(actions[0])
); | 118 assertEquals("button 1", NotificationTestUtil.getActionTitle(actions[0])
); |
105 assertEquals("button 2", NotificationTestUtil.getActionTitle(actions[1])
); | 119 assertEquals("button 2", NotificationTestUtil.getActionTitle(actions[1])
); |
106 assertEquals("settings", NotificationTestUtil.getActionTitle(actions[2])
); | 120 assertEquals("settings", NotificationTestUtil.getActionTitle(actions[2])
); |
| 121 |
| 122 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 123 // Notification.publicVersion was added in Android L. |
| 124 assertNotNull(notification.publicVersion); |
| 125 assertEquals(context.getString(R.string.notification_hidden_text), |
| 126 NotificationTestUtil.getExtraText(notification.publicVersion
)); |
| 127 } |
| 128 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { |
| 129 assertEquals( |
| 130 "origin", NotificationTestUtil.getExtraSubText(notification.
publicVersion)); |
| 131 } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 132 assertEquals("origin", NotificationTestUtil.getExtraTitle(notificati
on.publicVersion)); |
| 133 } |
107 } | 134 } |
108 | 135 |
109 @SmallTest | 136 @SmallTest |
110 @Feature({"Browser", "Notifications"}) | 137 @Feature({"Browser", "Notifications"}) |
111 public void testBigTextStyle() { | 138 public void testBigTextStyle() { |
112 PendingIntent[] contentAndDeleteIntents = new PendingIntent[2]; | 139 PendingIntent[] contentAndDeleteIntents = new PendingIntent[2]; |
113 NotificationBuilderBase builder = createAllOptionsBuilder(contentAndDele
teIntents); | 140 NotificationBuilderBase builder = createAllOptionsBuilder(contentAndDele
teIntents); |
114 builder.setImage(null); | 141 builder.setImage(null); |
115 Notification notification = builder.build(); | 142 Notification notification = builder.build(); |
116 | 143 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 Notification otherNotification = otherBuilder.build(); | 178 Notification otherNotification = otherBuilder.build(); |
152 assertTrue(expected.sameAs( | 179 assertTrue(expected.sameAs( |
153 NotificationTestUtil.getSmallIconFromNotification(context, o
therNotification))); | 180 NotificationTestUtil.getSmallIconFromNotification(context, o
therNotification))); |
154 } else { | 181 } else { |
155 Bitmap expected = | 182 Bitmap expected = |
156 BitmapFactory.decodeResource(context.getResources(), R.drawa
ble.ic_chrome); | 183 BitmapFactory.decodeResource(context.getResources(), R.drawa
ble.ic_chrome); |
157 assertTrue(expected.sameAs(result)); | 184 assertTrue(expected.sameAs(result)); |
158 } | 185 } |
159 } | 186 } |
160 } | 187 } |
OLD | NEW |