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..65d81ee7f36f6043c1808b8fe08821347d4d58b7 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, |
dewittj
2014/08/14 20:54:58
nit: only indent the params 4 spaces
liyanhou
2014/08/14 21:06:07
Done.
|
+ notifierType, |
permissionLevel, |
- function (notifierExists) { |
- if (chrome.runtime.lastError || !notifierExists) { |
+ 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) { |
- reject(new Error("Unable to send onShowSettings message")); |
- return; |
+ notifierType, |
+ function (hasSettings) { |
+ if (chrome.runtime.lastError || !hasSettings) { |
+ reject(new Error("Unable to send onShowSettings message")); |
dewittj
2014/08/14 20:54:58
nit: indentation is weird here. Pretty sure git-c
liyanhou
2014/08/14 21:06:07
Done.
|
+ 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"); }) |
dewittj
2014/08/14 20:54:58
I think that all of these catch/then chains need t
liyanhou
2014/08/14 21:06:07
Done.
|
- // 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"); }) |
+ .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. |
- .catch(function () { return notifyOnCleared(myId, "doesNotExist"); }) |
+ .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"); }) |
- .then(function () { return notifyOnPermissionLevelChanged(myId, |
- "granted"); }) |
- .catch(function() { failTest("NotifyOnPermissionLevelChanged"); }) |
- .then(function () { return notifyOnShowSettings(myId); }) |
+ .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"); }) |
- .then(function() { chrome.test.succeed(); }); |
-}; |
+} |
-chrome.test.runTests([ testFunctions ]); |
+chrome.test.runTests([ testNotifyOnClicked, |
+ testNotifyOnButtonClicked, |
+ testNotifyOnClosed, |
+ testNotifyOnShowSettings ]); |