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: Addressed review comments Created Aug. 23, 2017, 10:10 a.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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 message: {"en-US": "Information"} 132 message: {"en-US": "Information"}
133 }; 133 };
134 134
135 registerHandler.call(this, [information]); 135 registerHandler.call(this, [information]);
136 this.runScheduledTasks(1).then(() => 136 this.runScheduledTasks(1).then(() =>
137 { 137 {
138 test.deepEqual(showNotifications(), [information], "The notification is show n"); 138 test.deepEqual(showNotifications(), [information], "The notification is show n");
139 test.deepEqual(showNotifications(), [], "Notification is treated as type inf ormation"); 139 test.deepEqual(showNotifications(), [], "Notification is treated as type inf ormation");
140 }).catch(unexpectedError.bind(test)).then(() => test.done()); 140 }).catch(unexpectedError.bind(test)).then(() => test.done());
141 }; 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 }
142 166
143 exports.testTargetSelection = {}; 167 exports.testTargetSelection = {};
144 168
145 for (let [propName, value, result] of [ 169 for (let [propName, value, result] of [
146 ["extension", "adblockpluschrome", true], 170 ["extension", "adblockpluschrome", true],
147 ["extension", "adblockplus", false], 171 ["extension", "adblockplus", false],
148 ["extension", "adblockpluschrome2", false], 172 ["extension", "adblockpluschrome2", false],
149 ["extensionMinVersion", "1.4", true], 173 ["extensionMinVersion", "1.4", true],
150 ["extensionMinVersion", "1.4.1", true], 174 ["extensionMinVersion", "1.4.1", true],
151 ["extensionMinVersion", "1.5", false], 175 ["extensionMinVersion", "1.5", false],
(...skipping 26 matching lines...) Expand all
178 ["blockedTotalMin", "11", false], 202 ["blockedTotalMin", "11", false],
179 ["blockedTotalMin", "10", true], 203 ["blockedTotalMin", "10", true],
180 ["blockedTotalMax", "10", true], 204 ["blockedTotalMax", "10", true],
181 ["blockedTotalMax", "1", false], 205 ["blockedTotalMax", "1", false],
182 ["locales", ["en-US"], true], 206 ["locales", ["en-US"], true],
183 ["locales", ["en-US", "de-DE"], true], 207 ["locales", ["en-US", "de-DE"], true],
184 ["locales", ["de-DE"], false], 208 ["locales", ["de-DE"], false],
185 ["locales", ["en-GB", "de-DE"], false] 209 ["locales", ["en-GB", "de-DE"], false]
186 ]) 210 ])
187 { 211 {
188 exports.testTargetSelection[`${propName}=${value}`] = function(test) 212 exports.testTargetSelection[`${propName}=${value}`] = testTargetSelectionFunc( propName, value, result);
189 { 213 }
190 let targetInfo = {}; 214
191 targetInfo[propName] = value; 215 exports.testTargetSelectionNoShowStats = {
192 216
193 let information = { 217 setUp(callback)
194 id: 1, 218 {
195 type: "information", 219 this.show_statsinpopup_orig = Prefs.show_statsinpopup;
196 message: {"en-US": "Information"}, 220 Prefs.show_statsinpopup = false;
197 targets: [targetInfo] 221 callback();
198 }; 222 },
199 223 tearDown(callback)
200 registerHandler.call(this, [information]); 224 {
201 this.runScheduledTasks(1).then(() => 225 Prefs.show_statsinpopup = this.show_statsinpopup_orig;
202 { 226 callback();
203 let expected = (result ? [information] : []); 227 }
204 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets)); 228 };
205 test.deepEqual(showNotifications(), [], "No notification on second call"); 229 for (let [propName, value, result] of [
206 }).catch(unexpectedError.bind(test)).then(() => test.done()); 230 ["blockedTotalMin", "10", false],
207 }; 231 ["blockedTotalMax", "10", false]
232 ])
233 {
234 exports.testTargetSelectionNoShowStats[`${propName}=${value}`] = testTargetSel ectionFunc(propName, value, result);
208 } 235 }
209 236
210 exports.testMultipleTargets = {}; 237 exports.testMultipleTargets = {};
211 238
212 for (let [[propName1, value1, result1], [propName2, value2, result2]] of pairs([ 239 for (let [[propName1, value1, result1], [propName2, value2, result2]] of pairs([
213 ["extension", "adblockpluschrome", true], 240 ["extension", "adblockpluschrome", true],
214 ["extension", "adblockplus", false], 241 ["extension", "adblockplus", false],
215 ["extensionMinVersion", "1.4", true], 242 ["extensionMinVersion", "1.4", true],
216 ["extensionMinVersion", "1.5", false], 243 ["extensionMinVersion", "1.5", false],
217 ["application", "chrome", true], 244 ["application", "chrome", true],
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 test.done(); 551 test.done();
525 }; 552 };
526 553
527 exports.testMissingTranslation = function(test) 554 exports.testMissingTranslation = function(test)
528 { 555 {
529 let notification = {message: {"en-US": "en-US"}}; 556 let notification = {message: {"en-US": "en-US"}};
530 let texts = Notification.getLocalizedTexts(notification, "fr"); 557 let texts = Notification.getLocalizedTexts(notification, "fr");
531 test.equal(texts.message, "en-US"); 558 test.equal(texts.message, "en-US");
532 test.done(); 559 test.done();
533 }; 560 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld