| 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 58e524266a1ae0fcb1c4d545cb68bc3ca2d14ce1..f62df7753cf55bba8317df70e066ad13090373fe 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,16 @@
|
|
|
| const notificationProvider = chrome.notificationProvider;
|
|
|
| +var myId = chrome.runtime.id;
|
| +var id1 = "id1";
|
| +var returnId = myId + "-" + id1;
|
| +var content = {
|
| + type: "basic",
|
| + iconUrl: "icon.png",
|
| + title: "Title",
|
| + message: "This is the message."
|
| +};
|
| +
|
| function createNotification(notificationId, options) {
|
| return new Promise(function (resolve, reject) {
|
| chrome.notifications.create(notificationId, options, function (id) {
|
| @@ -63,31 +73,35 @@ function notifyOnButtonClicked(senderId, notificationId, buttonIndex) {
|
| });
|
| };
|
|
|
| -function notifyOnPermissionLevelChanged(senderId, permissionLevel) {
|
| +function notifyOnPermissionLevelChanged(senderId,
|
| + notifierType,
|
| + permissionLevel) {
|
| return new Promise(function (resolve, reject) {
|
| notificationProvider.notifyOnPermissionLevelChanged(
|
| - senderId,
|
| - permissionLevel,
|
| - function (notifierExists) {
|
| - if (chrome.runtime.lastError || !notifierExists) {
|
| + senderId,
|
| + notifierType,
|
| + permissionLevel,
|
| + function (wasChanged) {
|
| + if (chrome.runtime.lastError || !wasChanged) {
|
| reject(new Error("Unable to send onPermissionLevelChanged message"));
|
| return;
|
| }
|
| - resolve(notifierExists);
|
| + resolve(wasChanged);
|
| return;
|
| });
|
| });
|
| };
|
|
|
| -function notifyOnShowSettings(senderId) {
|
| +function notifyOnShowSettings(senderId, notifierType) {
|
| return new Promise(function (resolve, reject) {
|
| notificationProvider.notifyOnShowSettings(senderId,
|
| - function (notifierExists) {
|
| - if (chrome.runtime.lastError || !notifierExists) {
|
| + notifierType,
|
| + function (hasSettings) {
|
| + if (chrome.runtime.lastError || !hasSettings) {
|
| reject(new Error("Unable to send onShowSettings message"));
|
| return;
|
| }
|
| - resolve(notifierExists);
|
| + resolve(hasSettings);
|
| return;
|
| });
|
| });
|
| @@ -97,45 +111,74 @@ function failTest(testName) {
|
| chrome.test.fail(testName);
|
| };
|
|
|
| -function testFunctions() {
|
| - var myId = chrome.runtime.id;
|
| - var id1 = "id1";
|
| - var returnId = myId + "-" + id1;
|
| - var content = {
|
| - type: "basic",
|
| - iconUrl: "icon.png",
|
| - title: "Title",
|
| - message: "This is the message."
|
| - };
|
| -
|
| - // Create a notification, so there will be one existing notification
|
| +function testNotifyOnClicked(){
|
| + chrome.notifications.onClicked.addListener(function(id) {
|
| + chrome.test.succeed();
|
| + });
|
| +
|
| + // Create a notification, so there will be one existing notification.
|
| createNotification(id1, content)
|
| - .catch(function() { failTest("notifications.create"); })
|
| - // Notify the sender that a notificaion was clicked.
|
| - .then(function() { return notifyOnClicked(myId, returnId); })
|
| - .catch(function() { failTest("NotifyOnClicked1"); })
|
| - // Try to notify that an non-existent notification was clicked.
|
| - .then(function() { return notifyOnClicked(myId, "doesNotExist"); })
|
| - // Fail if it returns true.
|
| - .then(function() { failTest("NotifyOnClicked2"); })
|
| - // Notify the sender that a notificaion button was clicked.
|
| - .catch(function() { return notifyOnButtonClicked(myId, returnId, 0); })
|
| - .catch(function() { failTest("NotifyOnButtonClicked"); })
|
| - // Try to notify that a non-existent notification button was clicked.
|
| - .then(function() { return notifyOnButtonClicked(myId, "doesNotExist", 0)})
|
| - .then(function() { failTest("NotifyOnButtonClicked"); })
|
| - // Try to notify that an non-existent notification was cleared.
|
| - .catch(function () { return notifyOnCleared(myId, "doesNotExist"); })
|
| - .then(function() { failTest("NotifyOnCleared"); })
|
| - // Notify that the original notification was cleared.
|
| - .catch(function() { return notifyOnCleared(myId, returnId); })
|
| - .catch(function() { failTest("NotifyOnCleared"); })
|
| - .then(function () { return notifyOnPermissionLevelChanged(myId,
|
| - "granted"); })
|
| - .catch(function() { failTest("NotifyOnPermissionLevelChanged"); })
|
| - .then(function () { return notifyOnShowSettings(myId); })
|
| - .catch(function() { failTest("NotifyOnShowSettings"); })
|
| - .then(function() { chrome.test.succeed(); });
|
| -};
|
| + .catch(function() { failTest("notifications.create"); })
|
| + // Try to notify that an non-existent notification was clicked.
|
| + .then(function() { return notifyOnClicked(myId, "doesNotExist"); })
|
| + // Fail if it returns true.
|
| + .then(function() { failTest("NotifyOnClicked"); })
|
| + // Notify the sender that a notificaion was clicked.
|
| + .catch(function() { return notifyOnClicked(myId, returnId); })
|
| + .catch(function() { failTest("NotifyOnClicked"); });
|
| +}
|
| +
|
| +function testNotifyOnButtonClicked() {
|
| + chrome.notifications.onButtonClicked.addListener(function(id, buttonIndex) {
|
| + chrome.test.succeed();
|
| + });
|
| +
|
| + // Create a notification, so there will be one existing notification.
|
| + createNotification(id1, content)
|
| + .catch(function() { failTest("notifications.create"); })
|
| + // Try to notify that a non-existent notification button was clicked.
|
| + .then(function() { return notifyOnButtonClicked(myId, "doesNotExist", 0)})
|
| + .then(function() { failTest("NotifyOnButtonClicked"); })
|
| + // Notify the sender that a notificaion button was clicked.
|
| + .catch(function() { return notifyOnButtonClicked(myId, returnId, 0); })
|
| + .catch(function() { failTest("NotifyOnButtonClicked"); });
|
| +}
|
| +
|
| +function testNotifyOnClosed() {
|
| + chrome.notifications.onClosed.addListener(function(id, byUser) {
|
| + chrome.test.succeed();
|
| + });
|
| +
|
| + // Create a notification, so there will be one existing notification.
|
| + createNotification(id1, content)
|
| + .catch(function() { failTest("notifications.create"); })
|
| + // Try to notify that an non-existent notification was cleared.
|
| + .then(function () { return notifyOnCleared(myId, "doesNotExist"); })
|
| + .then(function() { failTest("NotifyOnCleared"); })
|
| + // Notify that the original notification was cleared.
|
| + .catch(function() { return notifyOnCleared(myId, returnId); })
|
| + .catch(function() { failTest("NotifyOnCleared"); });
|
| +}
|
| +
|
| +function testNotifyOnShowSettings() {
|
| + chrome.notifications.onShowSettings.addListener(function() {
|
| + chrome.test.succeed();
|
| + });
|
| +
|
| + // Create a notification, so there will be one existing notification.
|
| + createNotification(id1, content)
|
| + .catch(function() { failTest("notifications.create"); })
|
| + // Try to notify a non existent sender that a user checked its settings.
|
| + .then(function () { return notifyOnShowSettings("DoesNotExist",
|
| + "application"); })
|
| + // Fail if it returns true.
|
| + .then(function() { failTest("NotifyOnShowSettings"); })
|
| + // Notify current notifier that a user checked its settings.
|
| + .catch(function () { return notifyOnShowSettings(myId, "application"); })
|
| + .catch(function() { failTest("NotifyOnShowSettings"); })
|
| +}
|
|
|
| -chrome.test.runTests([ testFunctions ]);
|
| +chrome.test.runTests([ testNotifyOnClicked,
|
| + testNotifyOnButtonClicked,
|
| + testNotifyOnClosed,
|
| + testNotifyOnShowSettings ]);
|
|
|