| Left: | ||
| Right: |
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 } | 72 } |
| 73 }, | 73 }, |
| 74 | 74 |
| 75 cancel: function() | 75 cancel: function() |
| 76 { | 76 { |
| 77 this.nextExecution = -1; | 77 this.nextExecution = -1; |
| 78 } | 78 } |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 let requests = []; | 81 let requests = []; |
| 82 function XMLHttpRequest() | 82 function XMLHttpRequest() |
|
kzar
2016/10/05 11:36:51
Seems kind of wasteful to define XMLHttpRequest an
Wladimir Palant
2016/10/05 12:12:51
Not really - we want a clean environment for every
kzar
2016/10/05 12:18:16
Fair enough.
| |
| 83 { | 83 { |
| 84 this._host = "http://example.com"; | 84 this._host = "http://example.com"; |
| 85 this._loadHandlers = []; | 85 this._loadHandlers = []; |
| 86 this._errorHandlers = []; | 86 this._errorHandlers = []; |
| 87 }; | 87 }; |
| 88 XMLHttpRequest.prototype = | 88 XMLHttpRequest.prototype = |
| 89 { | 89 { |
| 90 _path: null, | 90 _path: null, |
| 91 _data: null, | 91 _data: null, |
| 92 _queryString: null, | 92 _queryString: null, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 } | 343 } |
| 344 | 344 |
| 345 let initialDelay = 1 / 60; | 345 let initialDelay = 1 / 60; |
| 346 | 346 |
| 347 exports.testOneSubscriptionDownloads = function(test) | 347 exports.testOneSubscriptionDownloads = function(test) |
| 348 { | 348 { |
| 349 let subscription = Subscription.fromURL("http://example.com/subscription"); | 349 let subscription = Subscription.fromURL("http://example.com/subscription"); |
| 350 FilterStorage.addSubscription(subscription); | 350 FilterStorage.addSubscription(subscription); |
| 351 | 351 |
| 352 let requests = []; | 352 let requests = []; |
| 353 this.registerHandler("/subscription", metadata => | 353 this.registerHandler("/subscription", metadata => |
|
kzar
2016/10/05 11:36:51
I guess we could avoid declaring all the module va
Wladimir Palant
2016/10/05 12:12:51
Not during the initial migration - the fewer chang
| |
| 354 { | 354 { |
| 355 requests.push([this.getTimeOffset(), metadata.method, metadata.path]); | 355 requests.push([this.getTimeOffset(), metadata.method, metadata.path]); |
| 356 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; | 356 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; |
| 357 }); | 357 }); |
| 358 | 358 |
| 359 this.runScheduledTasks(50).then(() => | 359 this.runScheduledTasks(50).then(() => |
| 360 { | 360 { |
| 361 test.deepEqual(requests, [ | 361 test.deepEqual(requests, [ |
| 362 [0 + initialDelay, "GET", "/subscription"], | 362 [0 + initialDelay, "GET", "/subscription"], |
| 363 [24 + initialDelay, "GET", "/subscription"], | 363 [24 + initialDelay, "GET", "/subscription"], |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 393 [0 + initialDelay, "GET", "/subscription1"], | 393 [0 + initialDelay, "GET", "/subscription1"], |
| 394 [2 + initialDelay, "GET", "/subscription2"], | 394 [2 + initialDelay, "GET", "/subscription2"], |
| 395 [24 + initialDelay, "GET", "/subscription1"], | 395 [24 + initialDelay, "GET", "/subscription1"], |
| 396 [26 + initialDelay, "GET", "/subscription2"], | 396 [26 + initialDelay, "GET", "/subscription2"], |
| 397 [48 + initialDelay, "GET", "/subscription1"], | 397 [48 + initialDelay, "GET", "/subscription1"], |
| 398 [50 + initialDelay, "GET", "/subscription2"], | 398 [50 + initialDelay, "GET", "/subscription2"], |
| 399 ], "Requests after 55 hours"); | 399 ], "Requests after 55 hours"); |
| 400 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 400 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 401 }; | 401 }; |
| 402 | 402 |
| 403 exports.testSubscriptionHeaders = function(test) | 403 exports.testSubscriptionHeaders = {}; |
| 404 { | 404 |
| 405 let currentTest; | 405 for (let currentTest of [ |
| 406 let subscription = Subscription.fromURL("http://example.com/subscription"); | 406 {header: "[Adblock]", downloadStatus: "synchronize_ok", requiredVersion: null} , |
| 407 FilterStorage.addSubscription(subscription); | 407 {header: "[Adblock Plus]", downloadStatus: "synchronize_ok", requiredVersion: null}, |
| 408 | 408 {header: "(something)[Adblock]", downloadStatus: "synchronize_ok", requiredVer sion: null}, |
| 409 this.registerHandler("/subscription", metadata => | 409 {header: "[Adblock Plus 0.0.1]", downloadStatus: "synchronize_ok", requiredVer sion: "0.0.1"}, |
| 410 { | 410 {header: "[Adblock Plus 99.9]", downloadStatus: "synchronize_ok", requiredVers ion: "99.9"}, |
| 411 return [Cr.NS_OK, 200, currentTest.header + "\n!Expires: 8 hours\nfoo\n!bar\ n\n@@bas\n#bam"]; | 411 {header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVersion: null} |
| 412 }); | 412 ]) |
| 413 | 413 { |
| 414 let tests = [ | 414 exports.testSubscriptionHeaders[currentTest.header] = function(test) |
| 415 {header: "[Adblock]", downloadStatus: "synchronize_ok", requiredVersion: nul l}, | 415 { |
| 416 {header: "[Adblock Plus]", downloadStatus: "synchronize_ok", requiredVersion : null}, | 416 let subscription = Subscription.fromURL("http://example.com/subscription"); |
| 417 {header: "(something)[Adblock]", downloadStatus: "synchronize_ok", requiredV ersion: null}, | 417 FilterStorage.addSubscription(subscription); |
| 418 {header: "[Adblock Plus 0.0.1]", downloadStatus: "synchronize_ok", requiredV ersion: "0.0.1"}, | 418 |
| 419 {header: "[Adblock Plus 99.9]", downloadStatus: "synchronize_ok", requiredVe rsion: "99.9"}, | 419 this.registerHandler("/subscription", metadata => |
| 420 {header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVersio n: null} | 420 { |
| 421 ]; | 421 return [Cr.NS_OK, 200, currentTest.header + "\n!Expires: 8 hours\nfoo\n!ba r\n\n@@bas\n#bam"]; |
| 422 | 422 }); |
| 423 let runTest = () => | 423 |
| 424 { | 424 this.runScheduledTasks(2).then(() => |
| 425 if (!tests.length) | 425 { |
| 426 return; | 426 test.equal(subscription.downloadStatus, currentTest.downloadStatus, "Downl oad status"); |
| 427 | 427 test.equal(subscription.requiredVersion, currentTest.requiredVersion, "Req uired version"); |
| 428 currentTest = tests.shift(); | |
| 429 | |
| 430 resetSubscription(subscription) | |
| 431 return this.runScheduledTasks(2).then(() => | |
| 432 { | |
| 433 test.equal(subscription.downloadStatus, currentTest.downloadStatus, "Downl oad status for " + currentTest.header); | |
| 434 test.equal(subscription.requiredVersion, currentTest.requiredVersion, "Req uired version for " + currentTest.header); | |
| 435 | 428 |
| 436 if (currentTest.downloadStatus == "synchronize_ok") | 429 if (currentTest.downloadStatus == "synchronize_ok") |
| 437 { | 430 { |
| 438 test.deepEqual(subscription.filters, [ | 431 test.deepEqual(subscription.filters, [ |
| 439 Filter.fromText("foo"), | 432 Filter.fromText("foo"), |
| 440 Filter.fromText("!bar"), | 433 Filter.fromText("!bar"), |
| 441 Filter.fromText("@@bas"), | 434 Filter.fromText("@@bas"), |
| 442 Filter.fromText("#bam"), | 435 Filter.fromText("#bam"), |
| 443 ], "Resulting subscription filters for " + currentTest.header); | 436 ], "Resulting subscription filters"); |
| 444 } | 437 } |
| 445 else | 438 else |
| 446 { | 439 { |
| 447 test.deepEqual(subscription.filters, [ | 440 test.deepEqual(subscription.filters, [ |
| 448 ], "Resulting subscription filters for " + currentTest.header); | 441 ], "Resulting subscription filters"); |
| 449 } | 442 } |
| 450 }).then(runTest); | 443 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 451 }; | 444 }; |
| 452 | 445 } |
| 453 runTest().catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 454 }; | |
| 455 | 446 |
| 456 exports.testsDisabledUpdates = function(test) | 447 exports.testsDisabledUpdates = function(test) |
| 457 { | 448 { |
| 458 Prefs.subscriptions_autoupdate = false; | 449 Prefs.subscriptions_autoupdate = false; |
| 459 | 450 |
| 460 let subscription = Subscription.fromURL("http://example.com/subscription"); | 451 let subscription = Subscription.fromURL("http://example.com/subscription"); |
| 461 FilterStorage.addSubscription(subscription); | 452 FilterStorage.addSubscription(subscription); |
| 462 | 453 |
| 463 let requests = 0; | 454 let requests = 0; |
| 464 this.registerHandler("/subscription", metadata => | 455 this.registerHandler("/subscription", metadata => |
| 465 { | 456 { |
| 466 requests++; | 457 requests++; |
| 467 throw new Error("Unexpected request"); | 458 throw new Error("Unexpected request"); |
| 468 }); | 459 }); |
| 469 | 460 |
| 470 this.runScheduledTasks(50).then(() => | 461 this.runScheduledTasks(50).then(() => |
| 471 { | 462 { |
| 472 test.equal(requests, 0, "Request count"); | 463 test.equal(requests, 0, "Request count"); |
| 473 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 464 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 474 }; | 465 }; |
| 475 | 466 |
| 476 exports.testExpirationTime = function(test) | 467 exports.testExpirationTime = {}; |
| 477 { | 468 |
| 478 let subscription = Subscription.fromURL("http://example.com/subscription"); | 469 for (let currentTest of [ |
| 479 FilterStorage.addSubscription(subscription); | 470 { |
| 480 | 471 expiration: "default", |
| 481 let currentTest; | 472 randomResult: 0.5, |
| 482 let requests = []; | 473 requests: [0 + initialDelay, 5 * 24 + initialDelay] |
| 483 this.registerHandler("/subscription", metadata => | 474 }, |
| 484 { | 475 { |
| 485 requests.push(this.getTimeOffset()); | 476 expiration: "1 hours", // Minimal expiration interval |
| 486 return [Cr.NS_OK, 200, "[Adblock]\nfoo\n!Expires: " + currentTest.expiration + "\nbar"]; | 477 randomResult: 0.5, |
| 487 }); | 478 requests: [0 + initialDelay, 1 + initialDelay, 2 + initialDelay, 3 + initial Delay] |
| 488 | 479 }, |
| 489 let tests = [ | 480 { |
| 490 { | 481 expiration: "26 hours", |
| 491 expiration: "default", | 482 randomResult: 0.5, |
| 492 randomResult: 0.5, | 483 requests: [0 + initialDelay, 26 + initialDelay] |
| 493 requests: [0 + initialDelay, 5 * 24 + initialDelay] | 484 }, |
| 494 }, | 485 { |
| 495 { | 486 expiration: "2 days", |
| 496 expiration: "1 hours", // Minimal expiration interval | 487 randomResult: 0.5, |
| 497 randomResult: 0.5, | 488 requests: [0 + initialDelay, 48 + initialDelay] |
| 498 requests: [0 + initialDelay, 1 + initialDelay, 2 + initialDelay, 3 + initi alDelay] | 489 }, |
| 499 }, | 490 { |
| 500 { | 491 expiration: "20 days", // Too large, will be corrected |
| 501 expiration: "26 hours", | 492 randomResult: 0.5, |
| 502 randomResult: 0.5, | 493 requests: [0 + initialDelay, 14 * 24 + initialDelay] |
| 503 requests: [0 + initialDelay, 26 + initialDelay] | 494 }, |
| 504 }, | 495 { |
| 505 { | 496 expiration: "35 hours", |
| 506 expiration: "2 days", | 497 randomResult: 0, // Changes interval by factor 0.8 |
| 507 randomResult: 0.5, | 498 requests: [0 + initialDelay, 28 + initialDelay] |
| 508 requests: [0 + initialDelay, 48 + initialDelay] | 499 }, |
| 509 }, | 500 { |
| 510 { | 501 expiration: "35 hours", |
| 511 expiration: "20 days", // Too large, will be corrected | 502 randomResult: 1, // Changes interval by factor 1.2 |
| 512 randomResult: 0.5, | 503 requests: [0 + initialDelay, 42 + initialDelay] |
| 513 requests: [0 + initialDelay, 14 * 24 + initialDelay] | 504 }, |
| 514 }, | 505 { |
| 515 { | 506 expiration: "35 hours", |
| 516 expiration: "35 hours", | 507 randomResult: 0.25, // Changes interval by factor 0.9 |
| 517 randomResult: 0, // Changes interval by factor 0.8 | 508 requests: [0 + initialDelay, 32 + initialDelay] |
| 518 requests: [0 + initialDelay, 28 + initialDelay] | 509 }, |
| 519 }, | 510 { |
| 520 { | 511 expiration: "40 hours", |
| 521 expiration: "35 hours", | 512 randomResult: 0.5, |
| 522 randomResult: 1, // Changes interval by factor 1.2 | 513 skipAfter: 5 + initialDelay, |
| 523 requests: [0 + initialDelay, 42 + initialDelay] | 514 skip: 10, // Short break should not increase soft expiration |
| 524 }, | 515 requests: [0 + initialDelay, 40 + initialDelay] |
| 525 { | 516 }, |
| 526 expiration: "35 hours", | 517 { |
| 527 randomResult: 0.25, // Changes interval by factor 0.9 | 518 expiration: "40 hours", |
| 528 requests: [0 + initialDelay, 32 + initialDelay] | 519 randomResult: 0.5, |
| 529 }, | 520 skipAfter: 5 + initialDelay, |
| 530 { | 521 skip: 30, // Long break should increase soft expiration |
| 531 expiration: "40 hours", | 522 requests: [0 + initialDelay, 70 + initialDelay] |
| 532 randomResult: 0.5, | 523 }, |
| 533 skipAfter: 5 + initialDelay, | 524 { |
| 534 skip: 10, // Short break should not increase soft expiration | 525 expiration: "40 hours", |
| 535 requests: [0 + initialDelay, 40 + initialDelay] | 526 randomResult: 0.5, |
| 536 }, | 527 skipAfter: 5 + initialDelay, |
| 537 { | 528 skip: 80, // Hitting hard expiration, immediate download |
| 538 expiration: "40 hours", | 529 requests: [0 + initialDelay, 85 + initialDelay] |
| 539 randomResult: 0.5, | 530 } |
| 540 skipAfter: 5 + initialDelay, | 531 ]) |
| 541 skip: 30, // Long break should increase soft expiration | 532 { |
| 542 requests: [0 + initialDelay, 70 + initialDelay] | 533 let testId = `"${currentTest.expiration}"`; |
| 543 }, | 534 if (currentTest.randomResult != 0.5) |
| 544 { | 535 testId += " with Math.random() returning " + currentTest.randomResult; |
| 545 expiration: "40 hours", | 536 if (currentTest.skip) |
| 546 randomResult: 0.5, | 537 testId += " skipping " + currentTest.skip + " hours after " + currentTest.sk ipAfter + " hours"; |
| 547 skipAfter: 5 + initialDelay, | 538 exports.testExpirationTime[testId] = function(test) |
| 548 skip: 80, // Hitting hard expiration, immediate download | 539 { |
| 549 requests: [0 + initialDelay, 85 + initialDelay] | 540 let subscription = Subscription.fromURL("http://example.com/subscription"); |
| 550 } | 541 FilterStorage.addSubscription(subscription); |
| 551 ] | 542 |
| 552 | 543 let requests = []; |
| 553 let runTest = () => | 544 this.registerHandler("/subscription", metadata => |
| 554 { | 545 { |
| 555 if (!tests.length) | 546 requests.push(this.getTimeOffset()); |
| 556 return; | 547 return [Cr.NS_OK, 200, "[Adblock]\nfoo\n!Expires: " + currentTest.expirati on + "\nbar"]; |
| 557 | 548 }); |
| 558 currentTest = tests.shift(); | 549 |
| 559 | |
| 560 requests = []; | |
| 561 this.randomResult = currentTest.randomResult; | 550 this.randomResult = currentTest.randomResult; |
| 562 resetSubscription(subscription); | |
| 563 | 551 |
| 564 let maxHours = Math.round(Math.max.apply(null, currentTest.requests)) + 1; | 552 let maxHours = Math.round(Math.max.apply(null, currentTest.requests)) + 1; |
| 565 return this.runScheduledTasks(maxHours, currentTest.skipAfter, currentTest.s kip).then(() => | 553 this.runScheduledTasks(maxHours, currentTest.skipAfter, currentTest.skip).th en(() => |
| 566 { | 554 { |
| 567 let randomAddendum = (this.randomResult == 0.5 ? "" : " with Math.random() returning " + this.randomResult); | 555 test.deepEqual(requests, currentTest.requests, "Requests"); |
| 568 let skipAddendum = (typeof currentTest.skip != "number" ? "" : " skipping " + currentTest.skip + " hours after " + currentTest.skipAfter + " hours"); | 556 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 569 test.deepEqual(requests, currentTest.requests, "Requests for \"" + current Test.expiration + "\"" + randomAddendum + skipAddendum); | 557 }; |
| 570 }).then(runTest); | 558 } |
| 571 }; | 559 |
| 572 | 560 exports.testChecksumVerification = {}; |
| 573 runTest().catch(unexpectedError.bind(test)).then(() => test.done()); | 561 |
| 574 }; | 562 for (let [testName, subscriptionBody, expectedResult] of [ |
| 575 | 563 ["Correct checksum", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\nfoo\nbar\ n", true], |
| 576 exports.testChecksumVerification = function(test) | 564 ["Wrong checksum", "[Adblock]\n! Checksum: wrongggny6Fn24b7JHsq/A\nfoo\nbar\n" , false], |
| 577 { | 565 ["Empty lines ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\n\nfoo\ n\nbar\n\n", true], |
| 578 let subscription = Subscription.fromURL("http://example.com/subscription"); | 566 ["CR LF line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7 JHsq/A\nfoo\r\nbar\r\n", true], |
| 579 FilterStorage.addSubscription(subscription); | 567 ["CR line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHs q/A\nfoo\rbar\r", true], |
| 580 | 568 ["Trailing line break not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JH sq/A\nfoo\nbar", false], |
| 581 let testName, subscriptionBody, expectedResult; | 569 ["Line breaks between lines not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn 24b7JHsq/A\nfoobar", false], |
| 582 let tests = [ | 570 ["Lines with spaces not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq /A\n \nfoo\n\nbar\n", false], |
| 583 ["Correct checksum", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\nfoo\nba r\n", true], | 571 ["Extra content in checksum line is part of the checksum", "[Adblock]\n! Check sum: e/JCmqXny6Fn24b7JHsq/A foobar\nfoo\nbar\n", false], |
| 584 ["Wrong checksum", "[Adblock]\n! Checksum: wrongggny6Fn24b7JHsq/A\nfoo\nbar\ n", false], | 572 ["= symbols after checksum are ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn2 4b7JHsq/A===\nfoo\nbar\n", true], |
| 585 ["Empty lines ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\n\nfo o\n\nbar\n\n", true], | 573 ["Header line is part of the checksum", "[Adblock Plus]\n! Checksum: e/JCmqXny 6Fn24b7JHsq/A\nfoo\nbar\n", false], |
| 586 ["CR LF line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24 b7JHsq/A\nfoo\r\nbar\r\n", true], | 574 ["Special comments are part of the checksum", "[Adblock]\n! Checksum: e/JCmqXn y6Fn24b7JHsq/A\n! Expires: 1\nfoo\nbar\n", false], |
| 587 ["CR line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7J Hsq/A\nfoo\rbar\r", true], | 575 ]) |
| 588 ["Trailing line break not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7 JHsq/A\nfoo\nbar", false], | 576 { |
| 589 ["Line breaks between lines not ignored", "[Adblock]\n! Checksum: e/JCmqXny6 Fn24b7JHsq/A\nfoobar", false], | 577 exports.testChecksumVerification[testName] = function(test) |
| 590 ["Lines with spaces not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JH sq/A\n \nfoo\n\nbar\n", false], | 578 { |
| 591 ["Extra content in checksum line is part of the checksum", "[Adblock]\n! Che cksum: e/JCmqXny6Fn24b7JHsq/A foobar\nfoo\nbar\n", false], | 579 let subscription = Subscription.fromURL("http://example.com/subscription"); |
| 592 ["= symbols after checksum are ignored", "[Adblock]\n! Checksum: e/JCmqXny6F n24b7JHsq/A===\nfoo\nbar\n", true], | 580 FilterStorage.addSubscription(subscription); |
| 593 ["Header line is part of the checksum", "[Adblock Plus]\n! Checksum: e/JCmqX ny6Fn24b7JHsq/A\nfoo\nbar\n", false], | 581 |
| 594 ["Special comments are part of the checksum", "[Adblock]\n! Checksum: e/JCmq Xny6Fn24b7JHsq/A\n! Expires: 1\nfoo\nbar\n", false], | 582 this.registerHandler("/subscription", metadata => |
| 595 ]; | 583 { |
| 596 | 584 return [Cr.NS_OK, 200, subscriptionBody]; |
| 597 this.registerHandler("/subscription", metadata => | 585 }); |
| 598 { | 586 |
| 599 return [Cr.NS_OK, 200, subscriptionBody]; | 587 this.runScheduledTasks(2).then(() => |
| 600 }); | 588 { |
| 601 | 589 test.equal(subscription.downloadStatus, expectedResult ? "synchronize_ok" : "synchronize_checksum_mismatch"); |
| 602 let runTest = () => | 590 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 603 { | 591 }; |
| 604 if (!tests.length) | 592 } |
| 605 return; | 593 |
| 606 | 594 exports.testSpecialComments = {}; |
| 607 [testName, subscriptionBody, expectedResult] = tests.shift(); | 595 |
| 608 | 596 for (let [comment, check] of [ |
| 609 resetSubscription(subscription); | 597 ["! Homepage: http://example.com/", (test, subscription) => |
| 610 return this.runScheduledTasks(2).then(() => | 598 { |
| 611 { | 599 test.equal(subscription.homepage, "http://example.com/", "Valid homepage com ment"); |
| 612 test.equal(subscription.downloadStatus, expectedResult ? "synchronize_ok" : "synchronize_checksum_mismatch", testName); | 600 }], |
| 613 }).then(runTest); | 601 ["! Homepage: ssh://example.com/", (test, subscription) => |
| 614 }; | 602 { |
| 615 | 603 test.equal(subscription.homepage, null, "Invalid homepage comment"); |
| 616 runTest().catch(unexpectedError.bind(test)).then(() => test.done()); | 604 }], |
| 617 }; | 605 ["! Title: foo", (test, subscription) => |
| 618 | 606 { |
| 619 exports.testSpecialComments = function(test) | 607 test.equal(subscription.title, "foo", "Title comment"); |
| 620 { | 608 test.equal(subscription.fixedTitle, true, "Fixed title"); |
| 621 let subscription = Subscription.fromURL("http://example.com/subscription"); | 609 }], |
| 622 FilterStorage.addSubscription(subscription); | 610 ["! Version: 1234", (test, subscription) => |
| 623 | 611 { |
| 624 let comment, check; | 612 test.equal(subscription.version, 1234, "Version comment"); |
| 625 let tests = [ | 613 }] |
| 626 ["! Homepage: http://example.com/", () => test.equal(subscription.homepage, "http://example.com/", "Valid homepage comment")], | 614 ]) |
| 627 ["! Homepage: ssh://example.com/", () => test.equal(subscription.homepage, n ull, "Invalid homepage comment")], | 615 { |
| 628 ["! Title: foo", function() | 616 exports.testSpecialComments[comment] = function(test) |
| 629 { | 617 { |
| 630 test.equal(subscription.title, "foo", "Title comment"); | 618 let subscription = Subscription.fromURL("http://example.com/subscription"); |
| 631 test.equal(subscription.fixedTitle, true, "Fixed title"); | 619 FilterStorage.addSubscription(subscription); |
| 632 }], | 620 |
| 633 ["! Version: 1234", () => test.equal(subscription.version, 1234, "Version co mment")] | 621 this.registerHandler("/subscription", metadata => |
| 634 ]; | 622 { |
| 635 | 623 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"]; |
| 636 this.registerHandler("/subscription", metadata => | 624 }); |
| 637 { | 625 |
| 638 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"]; | 626 this.runScheduledTasks(2).then(() => |
| 639 }); | 627 { |
| 640 | 628 check(test, subscription); |
| 641 let runTest = () => | |
| 642 { | |
| 643 if (!tests.length) | |
| 644 return; | |
| 645 | |
| 646 [comment, check] = tests.shift(); | |
| 647 | |
| 648 resetSubscription(subscription); | |
| 649 return this.runScheduledTasks(2).then(() => | |
| 650 { | |
| 651 check(); | |
| 652 test.deepEqual(subscription.filters, [Filter.fromText("foo"), Filter.fromT ext("bar")], "Special comment not added to filters"); | 629 test.deepEqual(subscription.filters, [Filter.fromText("foo"), Filter.fromT ext("bar")], "Special comment not added to filters"); |
| 653 }).then(runTest); | 630 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 654 }; | 631 }; |
| 655 | 632 } |
| 656 runTest().catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 657 }; | |
| 658 | 633 |
| 659 exports.testRedirects = function(test) | 634 exports.testRedirects = function(test) |
| 660 { | 635 { |
| 661 let subscription = Subscription.fromURL("http://example.com/subscription"); | 636 let subscription = Subscription.fromURL("http://example.com/subscription"); |
| 662 FilterStorage.addSubscription(subscription); | 637 FilterStorage.addSubscription(subscription); |
| 663 | 638 |
| 664 this.registerHandler("/subscription", metadata => | 639 this.registerHandler("/subscription", metadata => |
| 665 { | 640 { |
| 666 return [Cr.NS_OK, 200, "[Adblock]\nfoo\n!Redirect: http://example.com/redire cted\nbar"]; | 641 return [Cr.NS_OK, 200, "[Adblock]\nfoo\n!Redirect: http://example.com/redire cted\nbar"]; |
| 667 }); | 642 }); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 return this.runScheduledTasks(24); | 839 return this.runScheduledTasks(24); |
| 865 }).then(() => | 840 }).then(() => |
| 866 { | 841 { |
| 867 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow nloadStatus after download error"); | 842 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow nloadStatus after download error"); |
| 868 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); | 843 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); |
| 869 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD elay * MILLIS_IN_HOUR, "lastSuccess after download error"); | 844 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD elay * MILLIS_IN_HOUR, "lastSuccess after download error"); |
| 870 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); | 845 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); |
| 871 test.equal(subscription.errors, 2, "errors after download error"); | 846 test.equal(subscription.errors, 2, "errors after download error"); |
| 872 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 847 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 873 }; | 848 }; |
| LEFT | RIGHT |