Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js |
| diff --git a/chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js b/chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js |
| index 176b4f05bdd4f001c437a72a879e5d5635c6f1d7..d7cc109d37ed7041125d75d45516424f8bdeaadf 100644 |
| --- a/chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js |
| +++ b/chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js |
| @@ -4,6 +4,19 @@ |
| const notificationProvider = chrome.notificationProvider; |
| +function createNotification(notificationId, options) { |
| + return new Promise(function (resolve, reject) { |
| + chrome.notifications.create(notificationId, options, function (id) { |
| + if (chrome.runtime.lastError) { |
| + reject(new Error("Unable to create notification")); |
| + return; |
| + } |
| + resolve(id); |
| + return; |
| + }); |
| + }); |
| +}; |
| + |
| function notifyOnCleared(senderId, notificationId) { |
| return new Promise(function (resolve, reject) { |
| notificationProvider.notifyOnCleared(senderId, |
| @@ -84,29 +97,41 @@ function failTest(testName) { |
| chrome.test.fail(testName); |
| }; |
| +function listenForShowSettings() {} |
| + |
| function testFunctions() { |
| - var testName = "testFunctions"; |
| - var notifierId; |
| - var notId; |
| - notificationProvider.onCreated.addListener(function(senderId, |
| - notificationId, |
| - content) { |
| - notifierId = senderId; |
| - notId = notificationId; |
| + var myId = chrome.runtime.id; |
| + var id1 = "id1"; |
| + var content = { |
| + type: "basic", |
| + iconUrl: "icon.png", |
| + title: "Title", |
| + message: "This is the message." |
| + }; |
| - notifyOnClicked(notifierId, notId) |
| - .catch(function() { failTest("NotifyOnClickedFailed"); }) |
| - .then(function() { return notifyOnButtonClicked(notifierId, notId, 0); }) |
| - .catch(function() { failTest("NotifyOnButtonClickedFailed"); }) |
| - .then(function () { return notifyOnCleared(notifierId, notId); }) |
| - .catch(function() { failTest("NotifyOnClearedFailed"); }) |
| - .then(function () { return notifyOnPermissionLevelChanged(notifierId, |
| - "granted"); }) |
| - .catch(function() { failTest("NotifyOnPermissionLevelChangedFailed"); }) |
| - .then(function () { return notifyOnShowSettings(notifierId); }) |
| - .catch(function() { failTest("NotifyOnShowSettingsFailed"); }) |
| - .then(function() { chrome.test.succeed(testName); }); |
| - }); |
| + // Add listener to onShowSettings to show that this extension has advanced |
| + // settings. |
| + chrome.notifications.onShowSettings.addListener(listenForShowSettings); |
| + |
| + createNotification(id1, content) |
|
Pete Williamson
2014/08/11 17:53:50
You probably don't need all these catch statements
liyanhou
2014/08/11 18:24:06
I was doing that for more detailed error messages
Pete Williamson
2014/08/11 18:31:49
OK, in that case these are fine. I just wanted to
|
| + .catch(function() { failTest("notifications.create"); }) |
| + .then(function() { return notifyOnClicked(myId, id1); }) |
| + .catch(function() { failTest("NotifyOnClickedFailed"); }) |
| + .then(function() { return notifyOnButtonClicked(myId, id1, 0); }) |
| + .catch(function() { failTest("NotifyOnButtonClickedFailed"); }) |
| + .then(function () { return notifyOnCleared(myId, id1); }) |
| + .catch(function() { failTest("NotifyOnClearedFailed"); }) |
| + // Notify the sender that the permission level is changed by the user |
| + .then(function () { return notifyOnPermissionLevelChanged(myId, |
| + "granted"); }) |
| + .catch(function() { failTest("NotifyOnPermissionLevelChangedFailed"); }) |
| + .then(function () { return notifyOnShowSettings(myId); }) |
| + .catch(function() { failTest("NotifyOnShowSettingsFailed1"); }) |
| + // Try to notify a non existent sender that a user checked its settings |
| + .then(function () { return notifyOnShowSettings("DoesNotExist"); }) |
| + // Fail if it returns true |
| + .then(function() { failTest("NotifyOnShowSettingsFailed2"); }) |
| + .catch(function() { chrome.test.succeed(); }) |
| }; |
| chrome.test.runTests([ testFunctions ]); |