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.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.Notification; | 8 import android.app.Notification; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
11 import android.graphics.Bitmap; | 11 import android.graphics.Bitmap; |
12 import android.os.Build; | 12 import android.os.Build; |
13 import android.test.suitebuilder.annotation.LargeTest; | 13 import android.test.suitebuilder.annotation.LargeTest; |
14 import android.test.suitebuilder.annotation.MediumTest; | 14 import android.test.suitebuilder.annotation.MediumTest; |
15 | 15 |
16 import org.chromium.base.ThreadUtils; | |
16 import org.chromium.base.annotations.SuppressFBWarnings; | 17 import org.chromium.base.annotations.SuppressFBWarnings; |
17 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
19 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | |
18 import org.chromium.chrome.browser.preferences.website.ContentSetting; | 20 import org.chromium.chrome.browser.preferences.website.ContentSetting; |
19 import org.chromium.chrome.browser.util.UrlUtilities; | 21 import org.chromium.chrome.browser.util.UrlUtilities; |
20 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 22 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
21 import org.chromium.chrome.test.util.browser.notifications.MockNotificationManag erProxy.NotificationEntry; | 23 import org.chromium.chrome.test.util.browser.notifications.MockNotificationManag erProxy.NotificationEntry; |
22 | 24 |
23 import java.util.List; | 25 import java.util.List; |
24 | 26 |
25 /** | 27 /** |
26 * Instrumentation tests for the Notification Bridge. | 28 * Instrumentation tests for the Notification Bridge. |
27 * | 29 * |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 } | 75 } |
74 | 76 |
75 assertNotNull(notification.largeIcon); | 77 assertNotNull(notification.largeIcon); |
76 | 78 |
77 // Validate the notification's behavior. | 79 // Validate the notification's behavior. |
78 assertEquals(Notification.DEFAULT_ALL, notification.defaults); | 80 assertEquals(Notification.DEFAULT_ALL, notification.defaults); |
79 assertEquals(Notification.PRIORITY_DEFAULT, notification.priority); | 81 assertEquals(Notification.PRIORITY_DEFAULT, notification.priority); |
80 } | 82 } |
81 | 83 |
82 /** | 84 /** |
83 * Verifies that notifications created with the "silent" flag do not inherit system defaults | 85 * Verifies that the ONLY_ALERT_ONCE flag is not set when renotify is true. |
84 * in regards to their sound, vibration and light indicators. | |
85 */ | 86 */ |
86 @MediumTest | 87 @MediumTest |
87 @Feature({"Browser", "Notifications"}) | 88 @Feature({"Browser", "Notifications"}) |
88 public void testNotificationRenotifyProperty() throws Exception { | 89 public void testNotificationRenotifyProperty() throws Exception { |
89 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); | 90 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); |
90 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 91 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
91 | 92 |
92 Notification notification = | 93 Notification notification = |
93 showAndGetNotification("MyNotification", "{ tag: 'myTag', renoti fy: true }"); | 94 showAndGetNotification("MyNotification", "{ tag: 'myTag', renoti fy: true }"); |
94 | 95 |
95 // Zero indicates that no defaults should be inherited from the system. | |
96 assertEquals(0, notification.flags & Notification.FLAG_ONLY_ALERT_ONCE); | 96 assertEquals(0, notification.flags & Notification.FLAG_ONLY_ALERT_ONCE); |
97 } | 97 } |
98 | 98 |
99 /** | 99 /** |
100 * Verifies that notifications created with the "silent" flag do not inherit system defaults | 100 * Verifies that notifications created with the "silent" flag do not inherit system defaults |
101 * in regards to their sound, vibration and light indicators. | 101 * in regards to their sound, vibration and light indicators. |
102 */ | 102 */ |
103 @MediumTest | 103 @MediumTest |
104 @Feature({"Browser", "Notifications"}) | 104 @Feature({"Browser", "Notifications"}) |
105 public void testNotificationSilentProperty() throws Exception { | 105 public void testNotificationSilentProperty() throws Exception { |
106 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); | 106 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); |
107 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 107 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
108 | 108 |
109 Notification notification = showAndGetNotification("MyNotification", "{ silent: true }"); | 109 Notification notification = showAndGetNotification("MyNotification", "{ silent: true }"); |
110 | 110 |
111 // Zero indicates that no defaults should be inherited from the system. | 111 // Zero indicates that no defaults should be inherited from the system. |
112 assertEquals(0, notification.defaults); | 112 assertEquals(0, notification.defaults); |
113 } | 113 } |
114 | 114 |
115 /** | 115 /** |
116 * Verifies that when notification vibration is disabled in preferences and no custom pattern is | |
117 * specified, no vibration is requested from the framework. | |
118 */ | |
119 @MediumTest | |
120 @Feature({"Browser", "Notifications"}) | |
121 public void testNotificationVibratePreferenceDisabledDefault() throws Except ion { | |
gone
2016/06/07 17:32:54
This and the below test differ only by one line; d
Michael van Ouwerkerk
2016/06/08 13:28:13
Done.
| |
122 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); | |
123 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | |
124 | |
125 // Disable notification vibration in preferences. | |
126 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
127 @Override | |
128 public void run() { | |
129 PrefServiceBridge.getInstance().setNotificationsVibrateEnabled(f alse); | |
130 } | |
131 }); | |
132 | |
133 Notification notification = showAndGetNotification("MyNotification", "{} "); | |
134 | |
135 // Vibration should not be in the defaults. | |
136 assertEquals( | |
137 Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE, notifi cation.defaults); | |
138 | |
139 // There should be a custom no-op vibration pattern. | |
140 assertEquals(1, notification.vibrate.length); | |
141 assertEquals(0L, notification.vibrate[0]); | |
142 } | |
143 | |
144 /** | |
145 * Verifies that when notification vibration is disabled in preferences and a custom pattern is | |
146 * specified, no vibration is requested from the framework. | |
147 */ | |
148 @MediumTest | |
149 @Feature({"Browser", "Notifications"}) | |
150 public void testNotificationVibratePreferenceDisabledCustomPattern() throws Exception { | |
151 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); | |
152 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | |
153 | |
154 // Disable notification vibration in preferences. | |
155 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
156 @Override | |
157 public void run() { | |
158 PrefServiceBridge.getInstance().setNotificationsVibrateEnabled(f alse); | |
159 } | |
160 }); | |
161 | |
162 Notification notification = showAndGetNotification("MyNotification", "{ vibrate: 42}"); | |
163 | |
164 // Vibration should not be in the defaults. | |
165 assertEquals( | |
166 Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE, notifi cation.defaults); | |
167 | |
168 // There should be a custom no-op vibration pattern. | |
169 assertEquals(1, notification.vibrate.length); | |
170 assertEquals(0L, notification.vibrate[0]); | |
171 } | |
172 | |
173 /** | |
174 * Verifies that by default the notification vibration preference is enabled , and a custom | |
175 * pattern is passed along. | |
176 */ | |
177 @MediumTest | |
178 @Feature({"Browser", "Notifications"}) | |
179 public void testNotificationVibrateCustomPattern() throws Exception { | |
180 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); | |
181 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | |
182 | |
183 // By default, vibration is enabled in notifications. | |
184 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
185 @Override | |
186 public void run() { | |
187 assertTrue(PrefServiceBridge.getInstance().isNotificationsVibrat eEnabled()); | |
188 } | |
189 }); | |
190 | |
191 Notification notification = showAndGetNotification("MyNotification", "{ vibrate: 42}"); | |
192 | |
193 // Vibration should not be in the defaults, a custom pattern was provide d. | |
194 assertEquals( | |
195 Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE, notifi cation.defaults); | |
196 | |
197 // The custom pattern should have been passed along. | |
198 assertEquals(2, notification.vibrate.length); | |
199 assertEquals(0L, notification.vibrate[0]); | |
200 assertEquals(42L, notification.vibrate[1]); | |
201 } | |
202 | |
203 /** | |
116 * Verifies that notifications which specify an icon will have that icon fet ched, converted into | 204 * Verifies that notifications which specify an icon will have that icon fet ched, converted into |
117 * a Bitmap and included as the large icon in the notification. | 205 * a Bitmap and included as the large icon in the notification. |
118 */ | 206 */ |
119 @MediumTest | 207 @MediumTest |
120 @Feature({"Browser", "Notifications"}) | 208 @Feature({"Browser", "Notifications"}) |
121 public void testShowNotificationWithIcon() throws Exception { | 209 public void testShowNotificationWithIcon() throws Exception { |
122 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); | 210 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); |
123 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 211 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
124 | 212 |
125 Notification notification = showAndGetNotification("MyNotification", "{i con: 'icon.png'}"); | 213 Notification notification = showAndGetNotification("MyNotification", "{i con: 'icon.png'}"); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 assertEquals(1, notifications.size()); | 409 assertEquals(1, notifications.size()); |
322 assertEquals("Two", | 410 assertEquals("Two", |
323 notifications.get(0).notification.extras.getString(Notification. EXTRA_TITLE)); | 411 notifications.get(0).notification.extras.getString(Notification. EXTRA_TITLE)); |
324 | 412 |
325 // Close the last notification and verify that none remain. | 413 // Close the last notification and verify that none remain. |
326 notifications.get(0).notification.contentIntent.send(); | 414 notifications.get(0).notification.contentIntent.send(); |
327 waitForNotificationManagerMutation(); | 415 waitForNotificationManagerMutation(); |
328 assertTrue(getNotificationEntries().isEmpty()); | 416 assertTrue(getNotificationEntries().isEmpty()); |
329 } | 417 } |
330 } | 418 } |
OLD | NEW |