LEFT | RIGHT |
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 }; | 61 }; |
62 | 62 |
63 exports.testSubscriptionsWithState = function(test) | 63 exports.testSubscriptionsWithState = function(test) |
64 { | 64 { |
65 compareSubscription(test, "~fl~", ["url=~fl~"]); | 65 compareSubscription(test, "~fl~", ["url=~fl~"]); |
66 compareSubscription(test, "http://test/default", ["url=http://test/default", "
title=http://test/default"]); | 66 compareSubscription(test, "http://test/default", ["url=http://test/default", "
title=http://test/default"]); |
67 compareSubscription(test, "http://test/default_titled", ["url=http://test/defa
ult_titled", "title=test"], function(subscription) | 67 compareSubscription(test, "http://test/default_titled", ["url=http://test/defa
ult_titled", "title=test"], function(subscription) |
68 { | 68 { |
69 subscription.title = "test"; | 69 subscription.title = "test"; |
70 }); | 70 }); |
71 compareSubscription(test, "http://test/non_default", ["url=http://test/non_def
ault", "title=test", "fixedTitle=true", | 71 compareSubscription(test, "http://test/non_default", [ |
72 "disabled=true", "lastSuccess=
8", "lastDownload=12", "lastCheck=16", "softExpiration=18", "expires=20", "downl
oadStatus=foo", | 72 "url=http://test/non_default", "title=test", "fixedTitle=true", |
73 "errors=3", "version=24", "req
uiredVersion=0.6"], function(subscription) | 73 "disabled=true", "lastSuccess=20015998341138", |
| 74 "lastDownload=5124097847590911", "lastCheck=18446744069414584320", |
| 75 "softExpiration=2682143778081159", "expires=4294967295", |
| 76 "downloadStatus=foo", "errors=3", "version=24", "requiredVersion=0.6" |
| 77 ], function(subscription) |
74 { | 78 { |
75 subscription.title = "test"; | 79 subscription.title = "test"; |
76 subscription.fixedTitle = true; | 80 subscription.fixedTitle = true; |
77 subscription.disabled = true; | 81 subscription.disabled = true; |
78 subscription.lastSuccess = 8; | 82 subscription.lastSuccess = 20015998341138; // 0x123456789012 |
79 subscription.lastDownload = 12; | 83 subscription.lastDownload = 5124097847590911; // 0x123456FFFFFFFF |
80 subscription.lastCheck = 16; | 84 subscription.lastCheck = 18446744069414584320; // 0xFFFFFFFF00000000 |
81 subscription.softExpiration = 18; | 85 subscription.softExpiration = 2682143778081159; // 0x9876543210987 |
82 subscription.expires = 20; | 86 subscription.expires = 4294967295; // 0xFFFFFFFF |
83 subscription.downloadStatus = "foo"; | 87 subscription.downloadStatus = "foo"; |
84 subscription.errors = 3; | 88 subscription.errors = 3; |
85 subscription.version = 24 | 89 subscription.version = 24 |
86 subscription.requiredVersion = "0.6"; | 90 subscription.requiredVersion = "0.6"; |
87 }); | 91 }); |
88 compareSubscription(test, "~wl~", ["url=~wl~", "disabled=true", "title=Test gr
oup"], function(subscription) | 92 compareSubscription(test, "~wl~", ["url=~wl~", "disabled=true", "title=Test gr
oup"], function(subscription) |
89 { | 93 { |
90 subscription.title = "Test group"; | 94 subscription.title = "Test group"; |
91 subscription.disabled = true; | 95 subscription.disabled = true; |
92 }); | 96 }); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 filter2.delete(); | 259 filter2.delete(); |
256 | 260 |
257 test.done(); | 261 test.done(); |
258 }; | 262 }; |
259 | 263 |
260 exports.testNotifications = function(test) | 264 exports.testNotifications = function(test) |
261 { | 265 { |
262 function checkNotifications(action, expected, message) | 266 function checkNotifications(action, expected, message) |
263 { | 267 { |
264 let result = null; | 268 let result = null; |
265 let listener = (topic, subscription, newValue, oldValue) => | 269 let listener = (topic, subscription) => |
266 { | 270 { |
267 if (result) | 271 if (result) |
268 test.ok(false, "Got more that one notification - " + message); | 272 test.ok(false, "Got more that one notification - " + message); |
269 else | 273 else |
270 result = [topic, subscription.url, newValue, oldValue]; | 274 result = [topic, subscription.url]; |
271 }; | 275 }; |
272 FilterNotifier.addListener(listener); | 276 FilterNotifier.addListener(listener); |
273 action(); | 277 action(); |
274 FilterNotifier.removeListener(listener); | 278 FilterNotifier.removeListener(listener); |
275 test.deepEqual(result, expected, message); | 279 test.deepEqual(result, expected, message); |
276 } | 280 } |
277 | 281 |
278 let subscription = Subscription.fromURL("http://example.com/"); | 282 let subscription = Subscription.fromURL("http://example.com/"); |
279 checkNotifications(() => | 283 checkNotifications(() => |
280 { | 284 { |
281 subscription.title = "foobar"; | 285 subscription.title = "foobar"; |
282 }, ["subscription.title", "http://example.com/", "foobar", "http://example.com
/"], "Changing subscription title"); | 286 }, ["subscription.title", "http://example.com/"], "Changing subscription title
"); |
283 checkNotifications(() => | 287 checkNotifications(() => |
284 { | 288 { |
285 subscription.title = "foobar"; | 289 subscription.title = "foobar"; |
286 }, null, "Setting subscription title to same value"); | 290 }, null, "Setting subscription title to same value"); |
287 checkNotifications(() => | 291 checkNotifications(() => |
288 { | 292 { |
289 subscription.title = null; | 293 subscription.title = null; |
290 }, ["subscription.title", "http://example.com/", "", "foobar"], "Resetting sub
scription title"); | 294 }, ["subscription.title", "http://example.com/"], "Resetting subscription titl
e"); |
291 | 295 |
292 checkNotifications(() => | 296 checkNotifications(() => |
293 { | 297 { |
294 subscription.disabled = true; | 298 subscription.disabled = true; |
295 }, ["subscription.disabled", "http://example.com/", true, false], "Disabling s
ubscription"); | 299 }, ["subscription.disabled", "http://example.com/"], "Disabling subscription")
; |
296 checkNotifications(() => | 300 checkNotifications(() => |
297 { | 301 { |
298 subscription.disabled = true; | 302 subscription.disabled = true; |
299 }, null, "Disabling already disabled subscription"); | 303 }, null, "Disabling already disabled subscription"); |
300 checkNotifications(() => | 304 checkNotifications(() => |
301 { | 305 { |
302 subscription.disabled = false; | 306 subscription.disabled = false; |
303 }, ["subscription.disabled", "http://example.com/", false, true], "Enabling su
bscription"); | 307 }, ["subscription.disabled", "http://example.com/"], "Enabling subscription"); |
304 | 308 |
305 checkNotifications(() => | 309 checkNotifications(() => |
306 { | 310 { |
307 subscription.fixedTitle = true; | 311 subscription.fixedTitle = true; |
308 }, ["subscription.fixedTitle", "http://example.com/", true, false], "Marking t
itle as fixed"); | 312 }, ["subscription.fixedTitle", "http://example.com/"], "Marking title as fixed
"); |
309 checkNotifications(() => | 313 checkNotifications(() => |
310 { | 314 { |
311 subscription.fixedTitle = false; | 315 subscription.fixedTitle = false; |
312 }, ["subscription.fixedTitle", "http://example.com/", false, true], "Marking t
itle as editable"); | 316 }, ["subscription.fixedTitle", "http://example.com/"], "Marking title as edita
ble"); |
313 | 317 |
314 checkNotifications(() => | 318 checkNotifications(() => |
315 { | 319 { |
316 subscription.homepage = "http://example.info/"; | 320 subscription.homepage = "http://example.info/"; |
317 }, ["subscription.homepage", "http://example.com/", "http://example.info/", ""
], "Changing subscription homepage"); | 321 }, ["subscription.homepage", "http://example.com/"], "Changing subscription ho
mepage"); |
318 checkNotifications(() => | 322 checkNotifications(() => |
319 { | 323 { |
320 subscription.homepage = null; | 324 subscription.homepage = null; |
321 }, ["subscription.homepage", "http://example.com/", "", "http://example.info/"
], "Resetting subscription homepage"); | 325 }, ["subscription.homepage", "http://example.com/"], "Resetting subscription h
omepage"); |
322 | 326 |
323 checkNotifications(() => | 327 checkNotifications(() => |
324 { | 328 { |
325 // Using a large number that will only fit into double but not int | 329 subscription.lastCheck = 1234; |
326 subscription.lastCheck = 123456789012345; | 330 }, ["subscription.lastCheck", "http://example.com/"], "Changing subscription.l
astCheck"); |
327 }, ["subscription.lastCheck", "http://example.com/", 123456789012345, 0], "Cha
nging subscription.lastCheck"); | 331 checkNotifications(() => |
328 checkNotifications(() => | 332 { |
329 { | 333 subscription.lastCheck = 1234; |
330 subscription.lastCheck = 123456789012345; | |
331 }, null, "Setting subscription.lastCheck to same value"); | 334 }, null, "Setting subscription.lastCheck to same value"); |
332 checkNotifications(() => | 335 checkNotifications(() => |
333 { | 336 { |
334 subscription.lastCheck = 0; | 337 subscription.lastCheck = 0; |
335 }, ["subscription.lastCheck", "http://example.com/", 0, 123456789012345], "Res
etting subscription.lastCheck"); | 338 }, ["subscription.lastCheck", "http://example.com/"], "Resetting subscription.
lastCheck"); |
336 | 339 |
337 checkNotifications(() => | 340 checkNotifications(() => |
338 { | 341 { |
339 // Using a large number that will only fit into double but not int | 342 subscription.lastDownload = 4321; |
340 subscription.lastDownload = 543210987654321; | 343 }, ["subscription.lastDownload", "http://example.com/"], "Changing subscriptio
n.lastDownload"); |
341 }, ["subscription.lastDownload", "http://example.com/", 543210987654321, 0], "
Changing subscription.lastDownload"); | |
342 checkNotifications(() => | 344 checkNotifications(() => |
343 { | 345 { |
344 subscription.lastDownload = 0; | 346 subscription.lastDownload = 0; |
345 }, ["subscription.lastDownload", "http://example.com/", 0, 543210987654321], "
Resetting subscription.lastDownload"); | 347 }, ["subscription.lastDownload", "http://example.com/"], "Resetting subscripti
on.lastDownload"); |
346 | 348 |
347 checkNotifications(() => | 349 checkNotifications(() => |
348 { | 350 { |
349 subscription.downloadStatus = "ok"; | 351 subscription.downloadStatus = "ok"; |
350 }, ["subscription.downloadStatus", "http://example.com/", "ok", ""], "Changing
subscription.downloadStatus"); | 352 }, ["subscription.downloadStatus", "http://example.com/"], "Changing subscript
ion.downloadStatus"); |
351 checkNotifications(() => | 353 checkNotifications(() => |
352 { | 354 { |
353 subscription.downloadStatus = null; | 355 subscription.downloadStatus = null; |
354 }, ["subscription.downloadStatus", "http://example.com/", "", "ok"], "Resettin
g subscription.downloadStatus"); | 356 }, ["subscription.downloadStatus", "http://example.com/"], "Resetting subscrip
tion.downloadStatus"); |
355 | 357 |
356 checkNotifications(() => | 358 checkNotifications(() => |
357 { | 359 { |
358 subscription.errors++; | 360 subscription.errors++; |
359 }, ["subscription.errors", "http://example.com/", 1, 0], "Increasing subscript
ion.errors"); | 361 }, ["subscription.errors", "http://example.com/"], "Increasing subscription.er
rors"); |
360 checkNotifications(() => | 362 checkNotifications(() => |
361 { | 363 { |
362 subscription.errors = 0; | 364 subscription.errors = 0; |
363 }, ["subscription.errors", "http://example.com/", 0, 1], "Resetting subscripti
on.erros"); | 365 }, ["subscription.errors", "http://example.com/"], "Resetting subscription.err
os"); |
364 | 366 |
365 subscription.delete(); | 367 subscription.delete(); |
366 test.done(); | 368 test.done(); |
367 }; | 369 }; |
LEFT | RIGHT |