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

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

Issue 2039953002: Add a preference for disabling vibration in notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Address Dan's comments. Created 4 years, 6 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
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
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 private void verifyVibrationNotRequestedWhenDisabledInPrefs(String notificat ionOptions)
116 throws Exception {
117 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE));
118 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
119
120 // Disable notification vibration in preferences.
121 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
122 @Override
123 public void run() {
124 PrefServiceBridge.getInstance().setNotificationsVibrateEnabled(f alse);
125 }
126 });
127
128 Notification notification = showAndGetNotification("MyNotification", not ificationOptions);
129
130 // Vibration should not be in the defaults.
131 assertEquals(
132 Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE, notifi cation.defaults);
133
134 // There should be a custom no-op vibration pattern.
135 assertEquals(1, notification.vibrate.length);
136 assertEquals(0L, notification.vibrate[0]);
137 }
138
139 /**
140 * Verifies that when notification vibration is disabled in preferences and no custom pattern is
141 * specified, no vibration is requested from the framework.
142 */
143 @MediumTest
144 @Feature({"Browser", "Notifications"})
145 public void testNotificationVibratePreferenceDisabledDefault() throws Except ion {
146 verifyVibrationNotRequestedWhenDisabledInPrefs("{}");
147 }
148
149 /**
150 * Verifies that when notification vibration is disabled in preferences and a custom pattern is
151 * specified, no vibration is requested from the framework.
152 */
153 @MediumTest
154 @Feature({"Browser", "Notifications"})
155 public void testNotificationVibratePreferenceDisabledCustomPattern() throws Exception {
156 verifyVibrationNotRequestedWhenDisabledInPrefs("{ vibrate: 42 }");
157 }
158
159 /**
160 * Verifies that by default the notification vibration preference is enabled , and a custom
161 * pattern is passed along.
162 */
163 @MediumTest
164 @Feature({"Browser", "Notifications"})
165 public void testNotificationVibrateCustomPattern() throws Exception {
166 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE));
167 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
168
169 // By default, vibration is enabled in notifications.
170 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
171 @Override
172 public void run() {
173 assertTrue(PrefServiceBridge.getInstance().isNotificationsVibrat eEnabled());
174 }
175 });
176
177 Notification notification = showAndGetNotification("MyNotification", "{ vibrate: 42 }");
178
179 // Vibration should not be in the defaults, a custom pattern was provide d.
180 assertEquals(
181 Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE, notifi cation.defaults);
182
183 // The custom pattern should have been passed along.
184 assertEquals(2, notification.vibrate.length);
185 assertEquals(0L, notification.vibrate[0]);
186 assertEquals(42L, notification.vibrate[1]);
187 }
188
115 /** 189 /**
116 * Verifies that notifications which specify an icon will have that icon fet ched, converted into 190 * 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. 191 * a Bitmap and included as the large icon in the notification.
118 */ 192 */
119 @MediumTest 193 @MediumTest
120 @Feature({"Browser", "Notifications"}) 194 @Feature({"Browser", "Notifications"})
121 public void testShowNotificationWithIcon() throws Exception { 195 public void testShowNotificationWithIcon() throws Exception {
122 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); 196 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE));
123 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); 197 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
124 198
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 assertEquals(1, notifications.size()); 395 assertEquals(1, notifications.size());
322 assertEquals("Two", 396 assertEquals("Two",
323 notifications.get(0).notification.extras.getString(Notification. EXTRA_TITLE)); 397 notifications.get(0).notification.extras.getString(Notification. EXTRA_TITLE));
324 398
325 // Close the last notification and verify that none remain. 399 // Close the last notification and verify that none remain.
326 notifications.get(0).notification.contentIntent.send(); 400 notifications.get(0).notification.contentIntent.send();
327 waitForNotificationManagerMutation(); 401 waitForNotificationManagerMutation();
328 assertTrue(getNotificationEntries().isEmpty()); 402 assertTrue(getNotificationEntries().isEmpty());
329 } 403 }
330 } 404 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698