OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 const notificationProvider = chrome.notificationProvider; | 5 const notificationProvider = chrome.notificationProvider; |
6 | 6 |
7 var myId = chrome.runtime.id; | 7 var myId = chrome.runtime.id; |
8 var id1 = "id1"; | 8 var id1 = "id1"; |
9 var returnId = myId + "-" + id1; | 9 var returnId = myId + "-" + id1; |
10 var content = { | 10 var content = { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 createNotification(id1, content) | 153 createNotification(id1, content) |
154 .catch(function() { failTest("notifications.create"); }) | 154 .catch(function() { failTest("notifications.create"); }) |
155 // Try to notify that an non-existent notification was cleared. | 155 // Try to notify that an non-existent notification was cleared. |
156 .then(function () { return notifyOnCleared(myId, "doesNotExist"); }) | 156 .then(function () { return notifyOnCleared(myId, "doesNotExist"); }) |
157 .then(function() { failTest("NotifyOnCleared"); }) | 157 .then(function() { failTest("NotifyOnCleared"); }) |
158 // Notify that the original notification was cleared. | 158 // Notify that the original notification was cleared. |
159 .catch(function() { return notifyOnCleared(myId, returnId); }) | 159 .catch(function() { return notifyOnCleared(myId, returnId); }) |
160 .catch(function() { failTest("NotifyOnCleared"); }); | 160 .catch(function() { failTest("NotifyOnCleared"); }); |
161 } | 161 } |
162 | 162 |
| 163 function testNotifyOnPermissionLevelChanged() { |
| 164 chrome.notifications.onPermissionLevelChanged.addListener(function(level) { |
| 165 chrome.test.succeed(); |
| 166 }); |
| 167 |
| 168 // Create a notification, so there will be one existing notification. |
| 169 createNotification(id1, content) |
| 170 .catch(function() { failTest("notifications.create"); }) |
| 171 // Try to notify a web type notifier its permissional level is changed. |
| 172 .then(function() { return notifyOnPermissionLevelChanged("SomeURL", |
| 173 "web", |
| 174 "granted"); }) |
| 175 .then(function() { failTest("NotifyOnPermissionLevelChanged"); }) |
| 176 // Notify that the permission level of current notifier is changed. |
| 177 .catch(function () { return notifyOnPermissionLevelChanged(myId, |
| 178 "application", |
| 179 "granted"); }) |
| 180 .catch(function() { failTest("NotifyOnPermissionLevelChanged"); }); |
| 181 } |
| 182 |
163 function testNotifyOnShowSettings() { | 183 function testNotifyOnShowSettings() { |
164 chrome.notifications.onShowSettings.addListener(function() { | 184 chrome.notifications.onShowSettings.addListener(function() { |
165 chrome.test.succeed(); | 185 chrome.test.succeed(); |
166 }); | 186 }); |
167 | 187 |
168 // Create a notification, so there will be one existing notification. | 188 // Create a notification, so there will be one existing notification. |
169 createNotification(id1, content) | 189 createNotification(id1, content) |
170 .catch(function() { failTest("notifications.create"); }) | 190 .catch(function() { failTest("notifications.create"); }) |
171 // Try to notify a non existent sender that a user checked its settings. | 191 // Try to notify a non existent sender that a user checked its settings. |
172 .then(function () { return notifyOnShowSettings("DoesNotExist", | 192 .then(function () { return notifyOnShowSettings("DoesNotExist", |
173 "application"); }) | 193 "application"); }) |
174 // Fail if it returns true. | 194 // Fail if it returns true. |
175 .then(function() { failTest("NotifyOnShowSettings"); }) | 195 .then(function() { failTest("NotifyOnShowSettings"); }) |
176 // Notify current notifier that a user checked its settings. | 196 // Notify current notifier that a user checked its settings. |
177 .catch(function () { return notifyOnShowSettings(myId, "application"); }) | 197 .catch(function () { return notifyOnShowSettings(myId, "application"); }) |
178 .catch(function() { failTest("NotifyOnShowSettings"); }) | 198 .catch(function() { failTest("NotifyOnShowSettings"); }); |
179 } | 199 } |
180 | 200 |
181 chrome.test.runTests([ testNotifyOnClicked, | 201 chrome.test.runTests([ testNotifyOnClicked, |
182 testNotifyOnButtonClicked, | 202 testNotifyOnButtonClicked, |
183 testNotifyOnClosed, | 203 testNotifyOnClosed, |
| 204 testNotifyOnPermissionLevelChanged, |
184 testNotifyOnShowSettings ]); | 205 testNotifyOnShowSettings ]); |
OLD | NEW |