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

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

Issue 416423006: Add a browser test for functions in notification provider API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bug fix 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 const notificationProvider = chrome.notificationProvider;
6
7 function notifyOnCleared(senderId, notificationId) {
8 return new Promise(function (resolve, reject) {
9 notificationProvider.notifyOnCleared(senderId,
10 notificationId,
11 function (wasCleared) {
12 if (chrome.runtime.lastError || !wasCleared) {
13 reject(new Error("Unable to send onClear message"));
14 return;
15 }
16 resolve(wasCleared);
17 return;
18 });
19 });
20 };
21
22 function notifyOnClicked(senderId, notificationId) {
23 return new Promise(function (resolve, reject) {
24 notificationProvider.notifyOnClicked(senderId,
25 notificationId,
26 function (matchExists) {
27 if (chrome.runtime.lastError || !matchExists) {
28 reject(new Error("Unable to send onClick message"));
29 return;
30 }
31 resolve(matchExists);
32 return;
33 });
34 });
35 };
36
37 function notifyOnButtonClicked(senderId, notificationId, buttonIndex) {
38 return new Promise(function (resolve, reject) {
39 notificationProvider.notifyOnButtonClicked(senderId,
40 notificationId,
41 buttonIndex,
42 function (matchExists) {
43 if (chrome.runtime.lastError || !matchExists) {
44 reject(new Error("Unable to send onButtonClick message"));
45 return;
46 }
47 resolve(matchExists);
48 return;
49 });
50 });
51 };
52
53 function notifyOnPermissionLevelChanged(senderId, permissionLevel) {
54 return new Promise(function (resolve, reject) {
55 notificationProvider.notifyOnPermissionLevelChanged(
56 senderId,
57 permissionLevel,
58 function (notifierExists) {
59 if (chrome.runtime.lastError || !notifierExists) {
60 reject(new Error("Unable to send onPermissionLevelChanged message"));
61 return;
62 }
63 resolve(notifierExists);
64 return;
65 });
66 });
67 };
68
69 function notifyOnShowSettings(senderId) {
70 return new Promise(function (resolve, reject) {
71 notificationProvider.notifyOnShowSettings(senderId,
72 function (notifierExists) {
73 if (chrome.runtime.lastError || !notifierExists) {
74 reject(new Error("Unable to send onShowSettings message"));
75 return;
76 }
77 resolve(notifierExists);
78 return;
79 });
80 });
81 };
82
83 function failTest(testName) {
84 chrome.test.fail(testName);
85 };
86
87 function testFunctions() {
88 var testName = "testFunctions";
89 var notifierId;
90 var notId;
91 notificationProvider.onCreated.addListener(function(senderId,
92 notificationId,
93 content) {
94 notifierId = senderId;
95 notId = notificationId;
96
97 notifyOnClicked(notifierId, notId)
98 .catch(function() { failTest("NotifyOnClickedFailed"); })
99 .then(function() { return notifyOnButtonClicked(notifierId, notId, 0); })
100 .catch(function() { failTest("NotifyOnButtonClickedFailed"); })
101 .then(function () { return notifyOnCleared(notifierId, notId); })
102 .catch(function() { failTest("NotifyOnClearedFailed"); })
103 .then(function () { return notifyOnPermissionLevelChanged(notifierId,
104 "granted"); })
105 .catch(function() { failTest("NotifyOnPermissionLevelChangedFailed"); })
106 .then(function () { return notifyOnShowSettings(notifierId); })
107 .catch(function() { failTest("NotifyOnShowSettingsFailed"); })
108 .then(function() { chrome.test.succeed(testName); });
109 });
110 };
111
112 chrome.test.runTests([ testFunctions ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698