Left: | ||
Right: |
OLD | NEW |
---|---|
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 let {createSandbox} = require("./_common"); | 20 let {createSandbox} = require("./_common"); |
21 | 21 |
22 let Filter = null; | 22 let Filter = null; |
23 let Subscription = null; | 23 let Subscription = null; |
24 let SpecialSubscription = null; | 24 let SpecialSubscription = null; |
25 let DownloadableSubscription = null; | 25 let DownloadableSubscription = null; |
26 let RegularSubscription = null; | 26 let RegularSubscription = null; |
27 let ExternalSubscription = null; | 27 let ExternalSubscription = null; |
28 let FilterNotifier = null; | |
28 | 29 |
29 exports.setUp = function(callback) | 30 exports.setUp = function(callback) |
30 { | 31 { |
31 let sandboxedRequire = createSandbox(); | 32 let sandboxedRequire = createSandbox(); |
32 ({Filter} = sandboxedRequire("../lib/filterClasses")); | 33 ({Filter} = sandboxedRequire("../lib/filterClasses")); |
33 ( | 34 ( |
34 { | 35 { |
35 Subscription, SpecialSubscription, DownloadableSubscription | 36 Subscription, SpecialSubscription, DownloadableSubscription |
36 } = sandboxedRequire("../lib/subscriptionClasses") | 37 } = sandboxedRequire("../lib/subscriptionClasses") |
37 ); | 38 ); |
39 ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier")); | |
38 callback(); | 40 callback(); |
39 }; | 41 }; |
40 | 42 |
41 function compareSubscription(test, url, expected, postInit) | 43 function compareSubscription(test, url, expected, postInit) |
42 { | 44 { |
43 expected.push("[Subscription]") | 45 expected.push("[Subscription]") |
44 let subscription = Subscription.fromURL(url); | 46 let subscription = Subscription.fromURL(url); |
45 if (postInit) | 47 if (postInit) |
46 postInit(subscription) | 48 postInit(subscription) |
47 let result = subscription.serialize().trim().split("\n"); | 49 let result = subscription.serialize().trim().split("\n"); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 | 253 |
252 subscription.removeFilterAt(0); | 254 subscription.removeFilterAt(0); |
253 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\n filter1\n", "One filter removed"); | 255 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\n filter1\n", "One filter removed"); |
254 | 256 |
255 subscription.delete(); | 257 subscription.delete(); |
256 filter1.delete(); | 258 filter1.delete(); |
257 filter2.delete(); | 259 filter2.delete(); |
258 | 260 |
259 test.done(); | 261 test.done(); |
260 }; | 262 }; |
263 | |
264 exports.testNotifications = function(test) | |
265 { | |
266 function checkNotifications(action, expected, message) | |
267 { | |
268 let result = null; | |
269 let listener = (topic, subscription, newValue, oldValue) => | |
sergei
2017/04/19 12:18:03
newValue and oldValue arguments are not used anymo
Wladimir Palant
2017/04/20 08:03:14
Done.
| |
270 { | |
271 if (result) | |
272 test.ok(false, "Got more that one notification - " + message); | |
273 else | |
274 result = [topic, subscription.url]; | |
275 }; | |
276 FilterNotifier.addListener(listener); | |
277 action(); | |
278 FilterNotifier.removeListener(listener); | |
279 test.deepEqual(result, expected, message); | |
280 } | |
281 | |
282 let subscription = Subscription.fromURL("http://example.com/"); | |
283 checkNotifications(() => | |
284 { | |
285 subscription.title = "foobar"; | |
286 }, ["subscription.title", "http://example.com/"], "Changing subscription title "); | |
287 checkNotifications(() => | |
288 { | |
289 subscription.title = "foobar"; | |
290 }, null, "Setting subscription title to same value"); | |
291 checkNotifications(() => | |
292 { | |
293 subscription.title = null; | |
294 }, ["subscription.title", "http://example.com/"], "Resetting subscription titl e"); | |
295 | |
296 checkNotifications(() => | |
297 { | |
298 subscription.disabled = true; | |
299 }, ["subscription.disabled", "http://example.com/"], "Disabling subscription") ; | |
300 checkNotifications(() => | |
301 { | |
302 subscription.disabled = true; | |
303 }, null, "Disabling already disabled subscription"); | |
304 checkNotifications(() => | |
305 { | |
306 subscription.disabled = false; | |
307 }, ["subscription.disabled", "http://example.com/"], "Enabling subscription"); | |
308 | |
309 checkNotifications(() => | |
310 { | |
311 subscription.fixedTitle = true; | |
312 }, ["subscription.fixedTitle", "http://example.com/"], "Marking title as fixed "); | |
313 checkNotifications(() => | |
314 { | |
315 subscription.fixedTitle = false; | |
316 }, ["subscription.fixedTitle", "http://example.com/"], "Marking title as edita ble"); | |
317 | |
318 checkNotifications(() => | |
319 { | |
320 subscription.homepage = "http://example.info/"; | |
321 }, ["subscription.homepage", "http://example.com/"], "Changing subscription ho mepage"); | |
322 checkNotifications(() => | |
323 { | |
324 subscription.homepage = null; | |
325 }, ["subscription.homepage", "http://example.com/"], "Resetting subscription h omepage"); | |
326 | |
327 checkNotifications(() => | |
328 { | |
329 subscription.lastCheck = 1234; | |
330 }, ["subscription.lastCheck", "http://example.com/"], "Changing subscription.l astCheck"); | |
331 checkNotifications(() => | |
332 { | |
333 subscription.lastCheck = 1234; | |
334 }, null, "Setting subscription.lastCheck to same value"); | |
335 checkNotifications(() => | |
336 { | |
337 subscription.lastCheck = 0; | |
338 }, ["subscription.lastCheck", "http://example.com/"], "Resetting subscription. lastCheck"); | |
339 | |
340 checkNotifications(() => | |
341 { | |
342 subscription.lastDownload = 4321; | |
343 }, ["subscription.lastDownload", "http://example.com/"], "Changing subscriptio n.lastDownload"); | |
344 checkNotifications(() => | |
345 { | |
346 subscription.lastDownload = 0; | |
347 }, ["subscription.lastDownload", "http://example.com/"], "Resetting subscripti on.lastDownload"); | |
348 | |
349 checkNotifications(() => | |
350 { | |
351 subscription.downloadStatus = "ok"; | |
352 }, ["subscription.downloadStatus", "http://example.com/"], "Changing subscript ion.downloadStatus"); | |
353 checkNotifications(() => | |
354 { | |
355 subscription.downloadStatus = null; | |
356 }, ["subscription.downloadStatus", "http://example.com/"], "Resetting subscrip tion.downloadStatus"); | |
357 | |
358 checkNotifications(() => | |
359 { | |
360 subscription.errors++; | |
361 }, ["subscription.errors", "http://example.com/"], "Increasing subscription.er rors"); | |
362 checkNotifications(() => | |
363 { | |
364 subscription.errors = 0; | |
365 }, ["subscription.errors", "http://example.com/"], "Resetting subscription.err os"); | |
366 | |
367 subscription.delete(); | |
368 test.done(); | |
369 }; | |
OLD | NEW |