Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Unified Diff: chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js

Issue 456223002: Add NotifyOnShowSettings implementation of notification provider API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comments in IDL file Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/api/notification_provider.idl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6d757680fbdcb759754292c0cdcc960c037b7c5e 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) {
+ 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,16 +123,48 @@ 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"); })
// 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"); })
@@ -130,11 +177,27 @@ function testFunctions() {
// Notify that the original notification was cleared.
.catch(function() { return notifyOnCleared(myId, returnId); })
.catch(function() { failTest("NotifyOnCleared"); })
+ // Notify the sender that the permission level is changed by the user
.then(function () { return notifyOnPermissionLevelChanged(myId,
+ "application",
"granted"); })
.catch(function() { failTest("NotifyOnPermissionLevelChanged"); })
- .then(function () { return notifyOnShowSettings(myId); })
+ .then(function () { return notifyOnShowSettings(myId, "application"); })
.catch(function() { failTest("NotifyOnShowSettings"); })
+ // 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"); })
+ .catch(function() { return allEventesReceived(
dewittj 2014/08/13 21:35:45 Same comment as the other CL; this doesn't actuall
liyanhou 2014/08/14 16:18:14 Done.
+ on_clicked_received,
+ on_button_clicked_received,
+ on_closed_received,
+ // OnPermissionLevelChanged not
+ // implemented yet.
+ true,
+ on_show_settings_called); })
+ .catch(function() { failTest("DidNotReceiveAllEvents"); })
.then(function() { chrome.test.succeed(); });
};
« no previous file with comments | « chrome/common/extensions/api/notification_provider.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698