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

Side by Side Diff: chrome/test/data/extensions/api_test/notifications/api/partial_update/background.js

Issue 256503004: Allow high-res bitmaps to be passed in from notifications API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restructure code so chrome_child.dll links Created 6 years, 7 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 (c) 2012 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 notifications = chrome.notifications;
6
7 function arrayEquals(a, b) {
8 if (a === b) return true;
9 if (a == null || b == null) return false;
10 if (a.length !== b.length) return false;
11
12 for (var i = 0; i < a.length; i++) {
13 if (a[i] !== b[i]) return false;
14 }
15 return true;
16 };
17
18 function create(id, options) {
19 return new Promise(function (resolve, reject) {
20 notifications.create(id, options, function (id) {
21 if (chrome.runtime.lastError) {
22 reject(new Error("Unable to create notification"));
23 return;
24 }
25 console.log("Created with id: " + id);
26 resolve(id);
27 return;
28 });
29 });
30 };
31
32 function update(id, options) {
33 return new Promise(function (resolve, reject) {
34 notifications.update(id, options, function (ok) {
35 if (chrome.runtime.lastError || !ok) {
36 reject(new Error("Unable to update notification"));
37 return;
38 }
39 console.log("Updated id: ", id);
40 resolve(ok);
41 return;
42 });
43 });
44 }
45
46 function clear(id) {
47 return new Promise(function (resolve, reject) {
48 notifications.clear(id, function (ok) {
49 if (chrome.runtime.lastError || !ok) {
50 reject(new Error("Unable to clear notification"));
51 return;
52 }
53 resolve(ok);
54 return;
55 });
56 });
57 }
58
59 function getAll() {
60 return new Promise(function (resolve, reject) {
61 notifications.getAll(function (ids) {
62 if (chrome.runtime.lastError) {
63 reject(new Error(chrome.runtime.lastError.message));
64 return;
65 }
66
67 if (ids === undefined) {
68 resolve([]);
69 return
70 }
71
72 var id_list = Object.keys(ids);
73 resolve(id_list);
74 });
75 });
76 }
77
78 function clearAll() {
79 return getAll().then(function (ids) {
80 var idPromises = ids.map(function (id) { return clear(id); });
81 return Promise.all(idPromises);
82 });
83 }
84
85 function succeedTest(testName) {
86 return function () {
87 return clearAll().then(
88 function () { chrome.test.succeed(testName); },
89 function (error) {
90 console.log("Unknown error in clearAll: " +
91 JSON.stringify(arguments));
92 });
93 };
94 }
95
96 function failTest(testName) {
97 return function () {
98 return clearAll().then(
99 function () { chrome.test.fail(testName); },
100 function (error) {
101 console.log("Unknown error in clearAll: " +
102 JSON.stringify(error.message));
103 });
104 };
105 }
106
107 function testPartialUpdate() {
108 var testName = "testPartialUpdate";
109 console.log("Starting " + testName);
110 var succeed = succeedTest(testName);
111 var fail = failTest(testName);
112
113 const red_dot = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA" +
114 "AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO" +
115 "9TXL0Y4OHwAAAABJRU5ErkJggg==";
116
117 var basicNotificationOptions = {
118 type: "basic",
119 title: "Basic title",
120 message: "Basic message",
121 iconUrl: red_dot,
122 buttons: [{title: "Button"}]
123 };
124
125 // Create a notification.
126 create("testId", basicNotificationOptions)
127 // Then update a few items
128 .then(function () {
129 return update("testId", {
130 title: "Changed!",
131 message: "Too late! The show ended yesterday"
132 });
133 })
134 // Then update a few more items
135 .then(function () { return update("testId", {priority:2, buttons: []}); })
136 // The test will continue in C++, checking that all the updates "took"
137 .then(chrome.test.succeed, chrome.test.fail);
138 };
139
140
141 chrome.test.runTests([testPartialUpdate]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698