Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/notification.js

Issue 29501607: Issue 5459 - Add support to show a notification based on the number of ads blocked (Closed)
Left Patch Set: Made blockedTotal and locales part of targets Created Aug. 21, 2017, 3:10 p.m.
Right Patch Set: Show notification for blockedTotal* only if Prefs.show_statsinpopup Created Aug. 24, 2017, 4:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/notification.js ('k') | test/stub-modules/prefs.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 19 matching lines...) Expand all
30 // within the sandbox succeed even with data passed in from outside. 30 // within the sandbox succeed even with data passed in from outside.
31 let globals = Object.assign({Array, JSON}, 31 let globals = Object.assign({Array, JSON},
32 setupTimerAndXMLHttp.call(this), setupRandomResult.call(this)); 32 setupTimerAndXMLHttp.call(this), setupRandomResult.call(this));
33 33
34 let sandboxedRequire = createSandbox({globals}); 34 let sandboxedRequire = createSandbox({globals});
35 ( 35 (
36 {Prefs} = sandboxedRequire("./stub-modules/prefs"), 36 {Prefs} = sandboxedRequire("./stub-modules/prefs"),
37 {Notification} = sandboxedRequire("../lib/notification") 37 {Notification} = sandboxedRequire("../lib/notification")
38 ); 38 );
39 39
40 sandboxedRequire("./stub-modules/utils");
Wladimir Palant 2017/08/22 07:54:58 This change seems unnecessary?
wspee 2017/08/23 10:12:20 Acknowledged.
41
42 callback(); 40 callback();
43 }; 41 };
44 42
45 function showNotifications(url) 43 function showNotifications(url)
46 { 44 {
47 let shownNotifications = []; 45 let shownNotifications = [];
48 function showListener(notification) 46 function showListener(notification)
49 { 47 {
50 shownNotifications.push(notification); 48 shownNotifications.push(notification);
51 Notification.markAsShown(notification.id); 49 Notification.markAsShown(notification.id);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 message: {"en-US": "Information"} 132 message: {"en-US": "Information"}
135 }; 133 };
136 134
137 registerHandler.call(this, [information]); 135 registerHandler.call(this, [information]);
138 this.runScheduledTasks(1).then(() => 136 this.runScheduledTasks(1).then(() =>
139 { 137 {
140 test.deepEqual(showNotifications(), [information], "The notification is show n"); 138 test.deepEqual(showNotifications(), [information], "The notification is show n");
141 test.deepEqual(showNotifications(), [], "Notification is treated as type inf ormation"); 139 test.deepEqual(showNotifications(), [], "Notification is treated as type inf ormation");
142 }).catch(unexpectedError.bind(test)).then(() => test.done()); 140 }).catch(unexpectedError.bind(test)).then(() => test.done());
143 }; 141 };
142
143 function testTargetSelectionFunc(propName, value, result)
144 {
145 return function(test)
146 {
147 let targetInfo = {};
148 targetInfo[propName] = value;
149
150 let information = {
151 id: 1,
152 type: "information",
153 message: {"en-US": "Information"},
154 targets: [targetInfo]
155 };
156
157 registerHandler.call(this, [information]);
158 this.runScheduledTasks(1).then(() =>
159 {
160 let expected = (result ? [information] : []);
161 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets));
162 test.deepEqual(showNotifications(), [], "No notification on second call");
163 }).catch(unexpectedError.bind(test)).then(() => test.done());
164 };
165 }
144 166
145 exports.testTargetSelection = {}; 167 exports.testTargetSelection = {};
146 168
147 for (let [propName, value, result] of [ 169 for (let [propName, value, result] of [
148 ["extension", "adblockpluschrome", true], 170 ["extension", "adblockpluschrome", true],
149 ["extension", "adblockplus", false], 171 ["extension", "adblockplus", false],
150 ["extension", "adblockpluschrome2", false], 172 ["extension", "adblockpluschrome2", false],
151 ["extensionMinVersion", "1.4", true], 173 ["extensionMinVersion", "1.4", true],
152 ["extensionMinVersion", "1.4.1", true], 174 ["extensionMinVersion", "1.4.1", true],
153 ["extensionMinVersion", "1.5", false], 175 ["extensionMinVersion", "1.5", false],
(...skipping 26 matching lines...) Expand all
180 ["blockedTotalMin", "11", false], 202 ["blockedTotalMin", "11", false],
181 ["blockedTotalMin", "10", true], 203 ["blockedTotalMin", "10", true],
182 ["blockedTotalMax", "10", true], 204 ["blockedTotalMax", "10", true],
183 ["blockedTotalMax", "1", false], 205 ["blockedTotalMax", "1", false],
184 ["locales", ["en-US"], true], 206 ["locales", ["en-US"], true],
185 ["locales", ["en-US", "de-DE"], true], 207 ["locales", ["en-US", "de-DE"], true],
186 ["locales", ["de-DE"], false], 208 ["locales", ["de-DE"], false],
187 ["locales", ["en-GB", "de-DE"], false] 209 ["locales", ["en-GB", "de-DE"], false]
188 ]) 210 ])
189 { 211 {
190 exports.testTargetSelection[`${propName}=${value}`] = function(test) 212 exports.testTargetSelection[`${propName}=${value}`] = testTargetSelectionFunc( propName, value, result);
191 { 213 }
192 let targetInfo = {}; 214
193 targetInfo[propName] = value; 215 exports.testTargetSelectionNoShowStats = {
194 216
195 let information = { 217 setUp(callback)
196 id: 1, 218 {
197 type: "information", 219 this.show_statsinpopup_orig = Prefs.show_statsinpopup;
198 message: {"en-US": "Information"}, 220 Prefs.show_statsinpopup = false;
199 targets: [targetInfo] 221 callback();
200 }; 222 },
201 223 tearDown(callback)
202 registerHandler.call(this, [information]); 224 {
203 this.runScheduledTasks(1).then(() => 225 Prefs.show_statsinpopup = this.show_statsinpopup_orig;
204 { 226 callback();
205 let expected = (result ? [information] : []); 227 }
206 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets)); 228 };
207 test.deepEqual(showNotifications(), [], "No notification on second call"); 229 for (let [propName, value, result] of [
208 }).catch(unexpectedError.bind(test)).then(() => test.done()); 230 ["blockedTotalMin", "10", false],
209 }; 231 ["blockedTotalMax", "10", false]
232 ])
233 {
234 exports.testTargetSelectionNoShowStats[`${propName}=${value}`] = testTargetSel ectionFunc(propName, value, result);
210 } 235 }
211 236
212 exports.testMultipleTargets = {}; 237 exports.testMultipleTargets = {};
213 238
214 for (let [[propName1, value1, result1], [propName2, value2, result2]] of pairs([ 239 for (let [[propName1, value1, result1], [propName2, value2, result2]] of pairs([
215 ["extension", "adblockpluschrome", true], 240 ["extension", "adblockpluschrome", true],
216 ["extension", "adblockplus", false], 241 ["extension", "adblockplus", false],
217 ["extensionMinVersion", "1.4", true], 242 ["extensionMinVersion", "1.4", true],
218 ["extensionMinVersion", "1.5", false], 243 ["extensionMinVersion", "1.5", false],
219 ["application", "chrome", true], 244 ["application", "chrome", true],
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 test.done(); 551 test.done();
527 }; 552 };
528 553
529 exports.testMissingTranslation = function(test) 554 exports.testMissingTranslation = function(test)
530 { 555 {
531 let notification = {message: {"en-US": "en-US"}}; 556 let notification = {message: {"en-US": "en-US"}};
532 let texts = Notification.getLocalizedTexts(notification, "fr"); 557 let texts = Notification.getLocalizedTexts(notification, "fr");
533 test.equal(texts.message, "en-US"); 558 test.equal(texts.message, "en-US");
534 test.done(); 559 test.done();
535 }; 560 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld