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..4a6168584d7e753fd45feca78e334dd9cf0dd690 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 |
@@ -63,36 +63,51 @@ function notifyOnButtonClicked(senderId, notificationId, buttonIndex) { |
}); |
}; |
-function notifyOnPermissionLevelChanged(senderId, permissionLevel) { |
+function notifyOnPermissionLevelChanged(senderId, |
+ notifierType, |
+ permissionLevel) { |
return new Promise(function (resolve, reject) { |
notificationProvider.notifyOnPermissionLevelChanged( |
senderId, |
+ 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) { |
+ notifierType, |
+ function (hasSettings) { |
+ if (chrome.runtime.lastError || !hasSettings) { |
reject(new Error("Unable to send onShowSettings message")); |
return; |
} |
- resolve(notifierExists); |
+ resolve(hasSettings); |
return; |
}); |
}); |
}; |
+function allEventesReceived(a, b, c, d, e) { |
Pete Williamson
2014/08/13 19:54:01
nit: Eventes -> Events
Let's use more descriptive
liyanhou
2014/08/14 16:15:24
Done.
|
+ return new Promise(function (resolve, reject) { |
+ if (a && b && c && d && e) { |
+ resolve(); |
+ return; |
+ } |
+ reject(new Error("Not all events are fired correctly.")); |
+ return; |
+ }); |
+}; |
+ |
function failTest(testName) { |
chrome.test.fail(testName); |
}; |
@@ -108,6 +123,38 @@ function testFunctions() { |
message: "This is the message." |
}; |
+ var on_clicked_received = false; |
+ function listenForOnClicked() { |
+ on_clicked_received = true; |
+ } |
+ |
+ var on_button_clicked_received = false; |
+ function listenForOnButtonClicked() { |
+ on_button_clicked_received = true; |
+ } |
+ |
+ var on_closed_received = false; |
+ function listenForOnClosed() { |
+ on_closed_received = true; |
+ } |
+ |
+ var on_permission_level_changed_called = false; |
+ function listenForOnPermissionLevelChanged() { |
+ on_permission_level_changed_called = true; |
+ } |
+ |
+ var on_show_settings_called = false; |
+ function listenForShowSettings() { |
+ on_show_settings_called = true; |
+ } |
+ |
+ chrome.notifications.onClicked.addListener(listenForOnClicked); |
+ chrome.notifications.onButtonClicked.addListener(listenForOnButtonClicked); |
+ chrome.notifications.onClosed.addListener(listenForOnClosed); |
+ chrome.notifications.onPermissionLevelChanged.addListener( |
+ listenForOnPermissionLevelChanged); |
+ chrome.notifications.onShowSettings.addListener(listenForShowSettings); |
+ |
// Create a notification, so there will be one existing notification |
createNotification(id1, content) |
.catch(function() { failTest("notifications.create"); }) |
@@ -131,10 +178,26 @@ function testFunctions() { |
.catch(function() { return notifyOnCleared(myId, returnId); }) |
.catch(function() { failTest("NotifyOnCleared"); }) |
.then(function () { return notifyOnPermissionLevelChanged(myId, |
+ "application", |
"granted"); }) |
- .catch(function() { failTest("NotifyOnPermissionLevelChanged"); }) |
- .then(function () { return notifyOnShowSettings(myId); }) |
+ .catch(function() { failTest("NotifyOnPermissionLevelChanged1"); }) |
+ // Try to notify a web type notifier its permissional level is changed |
+ .then(function() { return notifyOnPermissionLevelChanged("SomeURL", |
+ "web", |
+ "granted"); }) |
+ // Fail if it returns true |
+ .then(function() { failTest("NotifyOnPermissionLevelChanged2"); }) |
+ .catch(function() { return notifyOnShowSettings(myId, "application"); }) |
.catch(function() { failTest("NotifyOnShowSettings"); }) |
+ .then(function() { return allEventesReceived( |
+ on_clicked_received, |
+ on_button_clicked_received, |
+ on_closed_received, |
+ on_permission_level_changed_called, |
+ // notifyOnShowSettings is not |
+ // implemented yet |
+ true); }) |
+ .catch(function() { failTest("DidNotReceiveAllEvents"); }) |
.then(function() { chrome.test.succeed(); }); |
}; |