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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 this.randomResult = currentTest.randomResult; | 265 this.randomResult = currentTest.randomResult; |
266 | 266 |
267 let maxHours = Math.round(Math.max.apply(null, currentTest.requests)) + 1; | 267 let maxHours = Math.round(Math.max.apply(null, currentTest.requests)) + 1; |
268 this.runScheduledTasks(maxHours, currentTest.skipAfter, currentTest.skip).th
en(() => | 268 this.runScheduledTasks(maxHours, currentTest.skipAfter, currentTest.skip).th
en(() => |
269 { | 269 { |
270 test.deepEqual(requests, currentTest.requests, "Requests"); | 270 test.deepEqual(requests, currentTest.requests, "Requests"); |
271 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 271 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
272 }; | 272 }; |
273 } | 273 } |
274 | 274 |
275 exports.testChecksumVerification = {}; | |
276 | |
277 for (let [testName, subscriptionBody, expectedResult] of [ | |
278 ["Correct checksum", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\nfoo\nbar\
n", true], | |
279 ["Wrong checksum", "[Adblock]\n! Checksum: wrongggny6Fn24b7JHsq/A\nfoo\nbar\n"
, false], | |
280 ["Empty lines ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\n\nfoo\
n\nbar\n\n", true], | |
281 ["CR LF line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7
JHsq/A\nfoo\r\nbar\r\n", true], | |
282 ["CR line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHs
q/A\nfoo\rbar\r", true], | |
283 ["Trailing line break not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JH
sq/A\nfoo\nbar", false], | |
284 ["Line breaks between lines not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn
24b7JHsq/A\nfoobar", false], | |
285 ["Lines with spaces not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq
/A\n \nfoo\n\nbar\n", false], | |
286 ["Extra content in checksum line is part of the checksum", "[Adblock]\n! Check
sum: e/JCmqXny6Fn24b7JHsq/A foobar\nfoo\nbar\n", false], | |
287 ["= symbols after checksum are ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn2
4b7JHsq/A===\nfoo\nbar\n", true], | |
288 ["Header line is part of the checksum", "[Adblock Plus]\n! Checksum: e/JCmqXny
6Fn24b7JHsq/A\nfoo\nbar\n", false], | |
289 ["Special comments are part of the checksum", "[Adblock]\n! Checksum: e/JCmqXn
y6Fn24b7JHsq/A\n! Expires: 1\nfoo\nbar\n", false] | |
290 ]) | |
291 { | |
292 exports.testChecksumVerification[testName] = function(test) | |
293 { | |
294 let subscription = Subscription.fromURL("http://example.com/subscription"); | |
295 FilterStorage.addSubscription(subscription); | |
296 | |
297 this.registerHandler("/subscription", metadata => | |
298 { | |
299 return [Cr.NS_OK, 200, subscriptionBody]; | |
300 }); | |
301 | |
302 this.runScheduledTasks(2).then(() => | |
303 { | |
304 test.equal(subscription.downloadStatus, expectedResult ? "synchronize_ok"
: "synchronize_checksum_mismatch"); | |
305 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
306 }; | |
307 } | |
308 | |
309 exports.testSpecialComments = {}; | 275 exports.testSpecialComments = {}; |
310 | 276 |
311 for (let [comment, check] of [ | 277 for (let [comment, check] of [ |
312 ["! Homepage: http://example.com/", (test, subscription) => | 278 ["! Homepage: http://example.com/", (test, subscription) => |
313 { | 279 { |
314 test.equal(subscription.homepage, "http://example.com/", "Valid homepage com
ment"); | 280 test.equal(subscription.homepage, "http://example.com/", "Valid homepage com
ment"); |
315 }], | 281 }], |
316 ["! Homepage: ssh://example.com/", (test, subscription) => | 282 ["! Homepage: ssh://example.com/", (test, subscription) => |
317 { | 283 { |
318 test.equal(subscription.homepage, null, "Invalid homepage comment"); | 284 test.equal(subscription.homepage, null, "Invalid homepage comment"); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"]; | 432 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"]; |
467 }); | 433 }); |
468 | 434 |
469 return this.runScheduledTasks(100); | 435 return this.runScheduledTasks(100); |
470 }).then(() => | 436 }).then(() => |
471 { | 437 { |
472 test.equal(FilterStorage.subscriptions[0].url, "http://example.com/redirecte
d", "Valid redirect from fallback is followed"); | 438 test.equal(FilterStorage.subscriptions[0].url, "http://example.com/redirecte
d", "Valid redirect from fallback is followed"); |
473 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay], "Stop polling original URL after a valid redirect from fallback"); | 439 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay], "Stop polling original URL after a valid redirect from fallback"); |
474 test.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay, 96
+ initialDelay], "Request new URL after a valid redirect from fallback"); | 440 test.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay, 96
+ initialDelay], "Request new URL after a valid redirect from fallback"); |
475 | 441 |
476 // Checksum mismatch | |
477 | |
478 this.registerHandler("/subscription", metadata => | |
479 { | |
480 return [Cr.NS_OK, 200, "[Adblock]\n! Checksum: wrong\nfoo\nbar"]; | |
481 }); | |
482 | |
483 subscription = Subscription.fromURL("http://example.com/subscription"); | |
484 resetSubscription(subscription); | |
485 FilterStorage.removeSubscription(FilterStorage.subscriptions[0]); | |
486 FilterStorage.addSubscription(subscription); | |
487 | |
488 return this.runScheduledTasks(100); | |
489 }).then(() => | |
490 { | |
491 test.equal(FilterStorage.subscriptions[0].url, "http://example.com/redirecte
d", "Wrong checksum produces fallback request"); | |
492 | |
493 // Redirect loop | 442 // Redirect loop |
494 | 443 |
495 this.registerHandler("/subscription", metadata => | 444 this.registerHandler("/subscription", metadata => |
496 { | 445 { |
497 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion2"]; | 446 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion2"]; |
498 }); | 447 }); |
499 this.registerHandler("/subscription2", metadata => | 448 this.registerHandler("/subscription2", metadata => |
500 { | 449 { |
501 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion"]; | 450 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion"]; |
502 }); | 451 }); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 return this.runScheduledTasks(24); | 503 return this.runScheduledTasks(24); |
555 }).then(() => | 504 }).then(() => |
556 { | 505 { |
557 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); | 506 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); |
558 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); | 507 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); |
559 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after download error"); | 508 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after download error"); |
560 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); | 509 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); |
561 test.equal(subscription.errors, 2, "errors after download error"); | 510 test.equal(subscription.errors, 2, "errors after download error"); |
562 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 511 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
563 }; | 512 }; |
OLD | NEW |