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..5a1f609c5371acaabccc52cac1bc091c8fc67917 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,33 +63,39 @@ 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 allEventsReceived(on_clicked_received, |
+ on_button_clicked_received, |
+ on_closed_received, |
+ on_permission_level_changed_called) { |
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; |
- } |
- resolve(notifierExists); |
+ if (on_clicked_received && |
+ on_button_clicked_received && |
+ on_closed_received && |
+ on_permission_level_changed_called) { |
+ resolve(); |
return; |
- }); |
+ } |
+ reject(new Error("Not all events are fired correctly.")); |
+ return; |
}); |
}; |
@@ -108,16 +114,42 @@ 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; |
+ } |
+ |
+ chrome.notifications.onClicked.addListener(listenForOnClicked); |
+ chrome.notifications.onButtonClicked.addListener(listenForOnButtonClicked); |
+ chrome.notifications.onClosed.addListener(listenForOnClosed); |
+ chrome.notifications.onPermissionLevelChanged.addListener( |
+ listenForOnPermissionLevelChanged); |
+ |
// 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"); }) |
+ .catch(function() { failTest("NotifyOnClicked"); }) |
// 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"); }) |
+ .then(function() { failTest("NotifyOnClicked"); }) |
// Notify the sender that a notificaion button was clicked. |
.catch(function() { return notifyOnButtonClicked(myId, returnId, 0); }) |
.catch(function() { failTest("NotifyOnButtonClicked"); }) |
@@ -131,10 +163,21 @@ 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("NotifyOnShowSettings"); }) |
+ // 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("NotifyOnPermissionLevelChanged"); }) |
+ .catch(function() { return allEventsReceived( |
dewittj
2014/08/13 21:30:36
This is technically racy; imagine an environment w
liyanhou
2014/08/14 16:15:24
Done.
|
+ on_clicked_received, |
+ on_button_clicked_received, |
+ on_closed_received, |
+ on_permission_level_changed_called); }) |
+ .catch(function() { failTest("DidNotReceiveAllEvents"); }) |
.then(function() { chrome.test.succeed(); }); |
}; |