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

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: 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
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 176b4f05bdd4f001c437a72a879e5d5635c6f1d7..d7cc109d37ed7041125d75d45516424f8bdeaadf 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,19 @@
const notificationProvider = chrome.notificationProvider;
+function createNotification(notificationId, options) {
+ return new Promise(function (resolve, reject) {
+ chrome.notifications.create(notificationId, options, function (id) {
+ if (chrome.runtime.lastError) {
+ reject(new Error("Unable to create notification"));
+ return;
+ }
+ resolve(id);
+ return;
+ });
+ });
+};
+
function notifyOnCleared(senderId, notificationId) {
return new Promise(function (resolve, reject) {
notificationProvider.notifyOnCleared(senderId,
@@ -84,29 +97,41 @@ function failTest(testName) {
chrome.test.fail(testName);
};
+function listenForShowSettings() {}
+
function testFunctions() {
- var testName = "testFunctions";
- var notifierId;
- var notId;
- notificationProvider.onCreated.addListener(function(senderId,
- notificationId,
- content) {
- notifierId = senderId;
- notId = notificationId;
+ var myId = chrome.runtime.id;
+ var id1 = "id1";
+ var content = {
+ type: "basic",
+ iconUrl: "icon.png",
+ title: "Title",
+ message: "This is the message."
+ };
- notifyOnClicked(notifierId, notId)
- .catch(function() { failTest("NotifyOnClickedFailed"); })
- .then(function() { return notifyOnButtonClicked(notifierId, notId, 0); })
- .catch(function() { failTest("NotifyOnButtonClickedFailed"); })
- .then(function () { return notifyOnCleared(notifierId, notId); })
- .catch(function() { failTest("NotifyOnClearedFailed"); })
- .then(function () { return notifyOnPermissionLevelChanged(notifierId,
- "granted"); })
- .catch(function() { failTest("NotifyOnPermissionLevelChangedFailed"); })
- .then(function () { return notifyOnShowSettings(notifierId); })
- .catch(function() { failTest("NotifyOnShowSettingsFailed"); })
- .then(function() { chrome.test.succeed(testName); });
- });
+ // Add listener to onShowSettings to show that this extension has advanced
+ // settings.
+ chrome.notifications.onShowSettings.addListener(listenForShowSettings);
+
+ createNotification(id1, content)
Pete Williamson 2014/08/11 17:53:50 You probably don't need all these catch statements
liyanhou 2014/08/11 18:24:06 I was doing that for more detailed error messages
Pete Williamson 2014/08/11 18:31:49 OK, in that case these are fine. I just wanted to
+ .catch(function() { failTest("notifications.create"); })
+ .then(function() { return notifyOnClicked(myId, id1); })
+ .catch(function() { failTest("NotifyOnClickedFailed"); })
+ .then(function() { return notifyOnButtonClicked(myId, id1, 0); })
+ .catch(function() { failTest("NotifyOnButtonClickedFailed"); })
+ .then(function () { return notifyOnCleared(myId, id1); })
+ .catch(function() { failTest("NotifyOnClearedFailed"); })
+ // Notify the sender that the permission level is changed by the user
+ .then(function () { return notifyOnPermissionLevelChanged(myId,
+ "granted"); })
+ .catch(function() { failTest("NotifyOnPermissionLevelChangedFailed"); })
+ .then(function () { return notifyOnShowSettings(myId); })
+ .catch(function() { failTest("NotifyOnShowSettingsFailed1"); })
+ // Try to notify a non existent sender that a user checked its settings
+ .then(function () { return notifyOnShowSettings("DoesNotExist"); })
+ // Fail if it returns true
+ .then(function() { failTest("NotifyOnShowSettingsFailed2"); })
+ .catch(function() { chrome.test.succeed(); })
};
chrome.test.runTests([ testFunctions ]);

Powered by Google App Engine
This is Rietveld 408576698