Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/synchronizer.js

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created March 7, 2019, 1:14 p.m.
Right Patch Set: Rebased Created April 10, 2019, 6:33 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 | « test/subscriptionClasses.js ('k') | test/url.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-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
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 const assert = require("assert"); 20 const assert = require("assert");
21 let { 21 let {
22 createSandbox, setupTimerAndXMLHttp, setupRandomResult, Cr, 22 createSandbox, setupTimerAndFetch, setupRandomResult,
23 MILLIS_IN_SECOND, MILLIS_IN_HOUR 23 MILLIS_IN_SECOND, MILLIS_IN_HOUR
24 } = require("./_common"); 24 } = require("./_common");
25 25
26 let filterStorage = null; 26 let filterStorage = null;
27 let Prefs = null; 27 let Prefs = null;
28 let Subscription = null; 28 let Subscription = null;
29 29
30 describe("Synchronizer", () => 30 describe("Synchronizer", () =>
31 { 31 {
32 let runner = {}; 32 let runner = {};
33 33
34 beforeEach(() => 34 beforeEach(() =>
35 { 35 {
36 runner = {}; 36 runner = {};
37 let globals = Object.assign({}, setupTimerAndXMLHttp.call(runner), 37 let globals = Object.assign({}, setupTimerAndFetch.call(runner),
38 setupRandomResult.call(runner)); 38 setupRandomResult.call(runner));
39 39
40 let sandboxedRequire = createSandbox({globals}); 40 let sandboxedRequire = createSandbox({globals});
41 ( 41 (
42 {filterStorage} = sandboxedRequire("../lib/filterStorage"), 42 {filterStorage} = sandboxedRequire("../lib/filterStorage"),
43 {Prefs} = sandboxedRequire("./stub-modules/prefs"), 43 {Prefs} = sandboxedRequire("./stub-modules/prefs"),
44 {Subscription} = sandboxedRequire("../lib/subscriptionClasses"), 44 {Subscription} = sandboxedRequire("../lib/subscriptionClasses"),
45 sandboxedRequire("../lib/synchronizer") 45 sandboxedRequire("../lib/synchronizer")
46 ); 46 );
47 }); 47 });
48 48
(...skipping 16 matching lines...) Expand all
65 { 65 {
66 it("One Subscription", () => 66 it("One Subscription", () =>
67 { 67 {
68 let subscription = Subscription.fromURL("http://example.com/subscription") ; 68 let subscription = Subscription.fromURL("http://example.com/subscription") ;
69 filterStorage.addSubscription(subscription); 69 filterStorage.addSubscription(subscription);
70 70
71 let requests = []; 71 let requests = [];
72 runner.registerHandler("/subscription", metadata => 72 runner.registerHandler("/subscription", metadata =>
73 { 73 {
74 requests.push([runner.getTimeOffset(), metadata.method, metadata.path]); 74 requests.push([runner.getTimeOffset(), metadata.method, metadata.path]);
75 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; 75 return [200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"];
76 }); 76 });
77 77
78 return runner.runScheduledTasks(50).then(() => 78 return runner.runScheduledTasks(50).then(() =>
79 { 79 {
80 assert.deepEqual(requests, [ 80 assert.deepEqual(requests, [
81 [0 + initialDelay, "GET", "/subscription"], 81 [0 + initialDelay, "GET", "/subscription"],
82 [24 + initialDelay, "GET", "/subscription"], 82 [24 + initialDelay, "GET", "/subscription"],
83 [48 + initialDelay, "GET", "/subscription"] 83 [48 + initialDelay, "GET", "/subscription"]
84 ], "Requests after 50 hours"); 84 ], "Requests after 50 hours");
85 }); 85 });
86 }); 86 });
87 87
88 it("Two Subscriptions", () => 88 it("Two Subscriptions", () =>
89 { 89 {
90 let subscription1 = Subscription.fromURL("http://example.com/subscription1 "); 90 let subscription1 = Subscription.fromURL("http://example.com/subscription1 ");
91 filterStorage.addSubscription(subscription1); 91 filterStorage.addSubscription(subscription1);
92 92
93 let subscription2 = Subscription.fromURL("http://example.com/subscription2 "); 93 let subscription2 = Subscription.fromURL("http://example.com/subscription2 ");
94 subscription2.expires = 94 subscription2.expires =
95 subscription2.softExpiration = 95 subscription2.softExpiration =
96 (runner.currentTime + 2 * MILLIS_IN_HOUR) / MILLIS_IN_SECOND; 96 (runner.currentTime + 2 * MILLIS_IN_HOUR) / MILLIS_IN_SECOND;
97 filterStorage.addSubscription(subscription2); 97 filterStorage.addSubscription(subscription2);
98 98
99 let requests = []; 99 let requests = [];
100 let handler = metadata => 100 let handler = metadata =>
101 { 101 {
102 requests.push([runner.getTimeOffset(), metadata.method, metadata.path]); 102 requests.push([runner.getTimeOffset(), metadata.method, metadata.path]);
103 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; 103 return [200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"];
104 }; 104 };
105 105
106 runner.registerHandler("/subscription1", handler); 106 runner.registerHandler("/subscription1", handler);
107 runner.registerHandler("/subscription2", handler); 107 runner.registerHandler("/subscription2", handler);
108 108
109 return runner.runScheduledTasks(55).then(() => 109 return runner.runScheduledTasks(55).then(() =>
110 { 110 {
111 assert.deepEqual(requests, [ 111 assert.deepEqual(requests, [
112 [0 + initialDelay, "GET", "/subscription1"], 112 [0 + initialDelay, "GET", "/subscription1"],
113 [2 + initialDelay, "GET", "/subscription2"], 113 [2 + initialDelay, "GET", "/subscription2"],
(...skipping 17 matching lines...) Expand all
131 {header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVers ion: null} 131 {header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVers ion: null}
132 ]) 132 ])
133 { 133 {
134 it(currentTest.header, () => 134 it(currentTest.header, () =>
135 { 135 {
136 let subscription = Subscription.fromURL("http://example.com/subscription "); 136 let subscription = Subscription.fromURL("http://example.com/subscription ");
137 filterStorage.addSubscription(subscription); 137 filterStorage.addSubscription(subscription);
138 138
139 runner.registerHandler("/subscription", metadata => 139 runner.registerHandler("/subscription", metadata =>
140 { 140 {
141 return [Cr.NS_OK, 200, currentTest.header + "\n!Expires: 8 hours\nfoo\ n!bar\n\n@@bas\n#bam"]; 141 return [200, currentTest.header + "\n!Expires: 8 hours\nfoo\n!bar\n\n@ @bas\n#bam"];
142 }); 142 });
143 143
144 return runner.runScheduledTasks(2).then(() => 144 return runner.runScheduledTasks(2).then(() =>
145 { 145 {
146 assert.equal(subscription.downloadStatus, currentTest.downloadStatus, "Download status"); 146 assert.equal(subscription.downloadStatus, currentTest.downloadStatus, "Download status");
147 assert.equal(subscription.requiredVersion, currentTest.requiredVersion , "Required version"); 147 assert.equal(subscription.requiredVersion, currentTest.requiredVersion , "Required version");
148 148
149 if (currentTest.downloadStatus == "synchronize_ok") 149 if (currentTest.downloadStatus == "synchronize_ok")
150 { 150 {
151 assert.deepEqual([...subscription.filterText()], ["foo", "!bar", "@@ bas", "#bam"], "Resulting subscription filters"); 151 assert.deepEqual([...subscription.filterText()], ["foo", "!bar", "@@ bas", "#bam"], "Resulting subscription filters");
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 it(testId, () => 255 it(testId, () =>
256 { 256 {
257 let subscription = Subscription.fromURL("http://example.com/subscription "); 257 let subscription = Subscription.fromURL("http://example.com/subscription ");
258 filterStorage.addSubscription(subscription); 258 filterStorage.addSubscription(subscription);
259 259
260 let requests = []; 260 let requests = [];
261 runner.registerHandler("/subscription", metadata => 261 runner.registerHandler("/subscription", metadata =>
262 { 262 {
263 requests.push(runner.getTimeOffset()); 263 requests.push(runner.getTimeOffset());
264 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: " + currentTest.expiratio n + "\nbar"]; 264 return [200, "[Adblock]\n!Expires: " + currentTest.expiration + "\nbar "];
265 }); 265 });
266 266
267 runner.randomResult = currentTest.randomResult; 267 runner.randomResult = currentTest.randomResult;
268 268
269 let maxHours = Math.round(Math.max.apply(null, currentTest.requests)) + 1; 269 let maxHours = Math.round(Math.max.apply(null, currentTest.requests)) + 1;
270 return runner.runScheduledTasks(maxHours, currentTest.skipAfter, current Test.skip).then(() => 270 return runner.runScheduledTasks(maxHours, currentTest.skipAfter, current Test.skip).then(() =>
271 { 271 {
272 assert.deepEqual(requests, currentTest.requests, "Requests"); 272 assert.deepEqual(requests, currentTest.requests, "Requests");
273 }); 273 });
274 }); 274 });
(...skipping 22 matching lines...) Expand all
297 }] 297 }]
298 ]) 298 ])
299 { 299 {
300 it(comment, () => 300 it(comment, () =>
301 { 301 {
302 let subscription = Subscription.fromURL("http://example.com/subscription "); 302 let subscription = Subscription.fromURL("http://example.com/subscription ");
303 filterStorage.addSubscription(subscription); 303 filterStorage.addSubscription(subscription);
304 304
305 runner.registerHandler("/subscription", metadata => 305 runner.registerHandler("/subscription", metadata =>
306 { 306 {
307 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"]; 307 return [200, "[Adblock]\n" + comment + "\nfoo\nbar"];
308 }); 308 });
309 309
310 return runner.runScheduledTasks(2).then(() => 310 return runner.runScheduledTasks(2).then(() =>
311 { 311 {
312 check(subscription); 312 check(subscription);
313 assert.deepEqual([...subscription.filterText()], ["foo", "bar"], "Spec ial comment not added to filters"); 313 assert.deepEqual([...subscription.filterText()], ["foo", "bar"], "Spec ial comment not added to filters");
314 }); 314 });
315 }); 315 });
316 } 316 }
317 }); 317 });
318 318
319 it("Redirects", () => 319 it("Redirects", () =>
320 { 320 {
321 let subscription = Subscription.fromURL("http://example.com/subscription"); 321 let subscription = Subscription.fromURL("http://example.com/subscription");
322 filterStorage.addSubscription(subscription); 322 filterStorage.addSubscription(subscription);
323 323
324 runner.registerHandler("/subscription", metadata => 324 runner.registerHandler("/subscription", metadata =>
325 { 325 {
326 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/redirecte d\nbar"]; 326 return [200, "[Adblock]\n!Redirect: http://example.com/redirected\nbar"];
327 }); 327 });
328 328
329 let requests; 329 let requests;
330 330
331 return runner.runScheduledTasks(30).then(() => 331 return runner.runScheduledTasks(30).then(() =>
332 { 332 {
333 assert.equal([...filterStorage.subscriptions()][0], subscription, "Invalid redirect ignored"); 333 assert.equal([...filterStorage.subscriptions()][0], subscription, "Invalid redirect ignored");
334 assert.equal(subscription.downloadStatus, "synchronize_connection_error", "Connection error recorded"); 334 assert.equal(subscription.downloadStatus, "synchronize_connection_error", "Connection error recorded");
335 assert.equal(subscription.errors, 2, "Number of download errors"); 335 assert.equal(subscription.errors, 2, "Number of download errors");
336 336
337 requests = []; 337 requests = [];
338 338
339 runner.registerHandler("/redirected", metadata => 339 runner.registerHandler("/redirected", metadata =>
340 { 340 {
341 requests.push(runner.getTimeOffset()); 341 requests.push(runner.getTimeOffset());
342 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 8 hours\nbar"]; 342 return [200, "[Adblock]\n! Expires: 8 hours\nbar"];
343 }); 343 });
344 344
345 resetSubscription(subscription); 345 resetSubscription(subscription);
346 return runner.runScheduledTasks(15); 346 return runner.runScheduledTasks(15);
347 }).then(() => 347 }).then(() =>
348 { 348 {
349 assert.equal([...filterStorage.subscriptions()][0].url, "http://example.co m/redirected", "Redirect followed"); 349 assert.equal([...filterStorage.subscriptions()][0].url, "http://example.co m/redirected", "Redirect followed");
350 assert.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resultin g requests"); 350 assert.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resultin g requests");
351 351
352 runner.registerHandler("/redirected", metadata => 352 runner.registerHandler("/redirected", metadata =>
353 { 353 {
354 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/subscri ption\nbar"]; 354 return [200, "[Adblock]\n!Redirect: http://example.com/subscription\nbar "];
355 }); 355 });
356 356
357 subscription = Subscription.fromURL("http://example.com/subscription"); 357 subscription = Subscription.fromURL("http://example.com/subscription");
358 resetSubscription(subscription); 358 resetSubscription(subscription);
359 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]); 359 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]);
360 filterStorage.addSubscription(subscription); 360 filterStorage.addSubscription(subscription);
361 361
362 return runner.runScheduledTasks(2); 362 return runner.runScheduledTasks(2);
363 }).then(() => 363 }).then(() =>
364 { 364 {
365 assert.equal([...filterStorage.subscriptions()][0], subscription, "Redirec t not followed on redirect loop"); 365 assert.equal([...filterStorage.subscriptions()][0], subscription, "Redirec t not followed on redirect loop");
366 assert.equal(subscription.downloadStatus, "synchronize_connection_error", "Download status after redirect loop"); 366 assert.equal(subscription.downloadStatus, "synchronize_connection_error", "Download status after redirect loop");
367 }); 367 });
368 }); 368 });
369 369
370 it("Fallback", () => 370 it("Fallback", () =>
371 { 371 {
372 Prefs.subscriptions_fallbackerrors = 3; 372 Prefs.subscriptions_fallbackerrors = 3;
373 Prefs.subscriptions_fallbackurl = "http://example.com/fallback?%SUBSCRIPTION %&%CHANNELSTATUS%&%RESPONSESTATUS%"; 373 Prefs.subscriptions_fallbackurl = "http://example.com/fallback?%SUBSCRIPTION %&%RESPONSESTATUS%";
374 374
375 let subscription = Subscription.fromURL("http://example.com/subscription"); 375 let subscription = Subscription.fromURL("http://example.com/subscription");
376 filterStorage.addSubscription(subscription); 376 filterStorage.addSubscription(subscription);
377 377
378 // No valid response from fallback 378 // No valid response from fallback
379 379
380 let requests = []; 380 let requests = [];
381 let fallbackParams; 381 let fallbackParams;
382 let redirectedRequests; 382 let redirectedRequests;
383 runner.registerHandler("/subscription", metadata => 383 runner.registerHandler("/subscription", metadata =>
384 { 384 {
385 requests.push(runner.getTimeOffset()); 385 requests.push(runner.getTimeOffset());
386 return [Cr.NS_OK, 404, ""]; 386 return [404, ""];
387 }); 387 });
388 388
389 return runner.runScheduledTasks(100).then(() => 389 return runner.runScheduledTasks(100).then(() =>
390 { 390 {
391 assert.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + init ialDelay, 72 + initialDelay, 96 + initialDelay], "Continue trying if the fallbac k doesn't respond"); 391 assert.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + init ialDelay, 72 + initialDelay, 96 + initialDelay], "Continue trying if the fallbac k doesn't respond");
392 392
393 // Fallback giving "Gone" response 393 // Fallback giving "Gone" response
394 394
395 resetSubscription(subscription); 395 resetSubscription(subscription);
396 requests = []; 396 requests = [];
397 fallbackParams = null; 397 fallbackParams = null;
398 runner.registerHandler("/fallback", metadata => 398 runner.registerHandler("/fallback", metadata =>
399 { 399 {
400 fallbackParams = decodeURIComponent(metadata.queryString); 400 fallbackParams = decodeURIComponent(metadata.queryString);
401 return [Cr.NS_OK, 200, "410 Gone"]; 401 return [200, "410 Gone"];
402 }); 402 });
403 403
404 return runner.runScheduledTasks(100); 404 return runner.runScheduledTasks(100);
405 }).then(() => 405 }).then(() =>
406 { 406 {
407 assert.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + init ialDelay], "Stop trying if the fallback responds with Gone"); 407 assert.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + init ialDelay], "Stop trying if the fallback responds with Gone");
408 assert.equal(fallbackParams, "http://example.com/subscription&0&404", "Fal lback arguments"); 408 assert.equal(fallbackParams, "http://example.com/subscription&404", "Fallb ack arguments");
409 409
410 // Fallback redirecting to a missing file 410 // Fallback redirecting to a missing file
411 411
412 subscription = Subscription.fromURL("http://example.com/subscription"); 412 subscription = Subscription.fromURL("http://example.com/subscription");
413 resetSubscription(subscription); 413 resetSubscription(subscription);
414 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]); 414 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]);
415 filterStorage.addSubscription(subscription); 415 filterStorage.addSubscription(subscription);
416 requests = []; 416 requests = [];
417 417
418 runner.registerHandler("/fallback", metadata => 418 runner.registerHandler("/fallback", metadata =>
419 { 419 {
420 return [Cr.NS_OK, 200, "301 http://example.com/redirected"]; 420 return [200, "301 http://example.com/redirected"];
421 }); 421 });
422 return runner.runScheduledTasks(100); 422 return runner.runScheduledTasks(100);
423 }).then(() => 423 }).then(() =>
424 { 424 {
425 assert.equal([...filterStorage.subscriptions()][0].url, "http://example.co m/subscription", "Ignore invalid redirect from fallback"); 425 assert.equal([...filterStorage.subscriptions()][0].url, "http://example.co m/subscription", "Ignore invalid redirect from fallback");
426 assert.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + init ialDelay, 72 + initialDelay, 96 + initialDelay], "Requests not affected by inval id redirect"); 426 assert.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + init ialDelay, 72 + initialDelay, 96 + initialDelay], "Requests not affected by inval id redirect");
427 427
428 // Fallback redirecting to an existing file 428 // Fallback redirecting to an existing file
429 429
430 resetSubscription(subscription); 430 resetSubscription(subscription);
431 requests = []; 431 requests = [];
432 redirectedRequests = []; 432 redirectedRequests = [];
433 runner.registerHandler("/redirected", metadata => 433 runner.registerHandler("/redirected", metadata =>
434 { 434 {
435 redirectedRequests.push(runner.getTimeOffset()); 435 redirectedRequests.push(runner.getTimeOffset());
436 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"]; 436 return [200, "[Adblock]\n!Expires: 1day\nfoo\nbar"];
437 }); 437 });
438 438
439 return runner.runScheduledTasks(100); 439 return runner.runScheduledTasks(100);
440 }).then(() => 440 }).then(() =>
441 { 441 {
442 assert.equal([...filterStorage.subscriptions()][0].url, "http://example.co m/redirected", "Valid redirect from fallback is followed"); 442 assert.equal([...filterStorage.subscriptions()][0].url, "http://example.co m/redirected", "Valid redirect from fallback is followed");
443 assert.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + init ialDelay], "Stop polling original URL after a valid redirect from fallback"); 443 assert.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + init ialDelay], "Stop polling original URL after a valid redirect from fallback");
444 assert.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay , 96 + initialDelay], "Request new URL after a valid redirect from fallback"); 444 assert.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay , 96 + initialDelay], "Request new URL after a valid redirect from fallback");
445 445
446 // Redirect loop 446 // Redirect loop
447 447
448 runner.registerHandler("/subscription", metadata => 448 runner.registerHandler("/subscription", metadata =>
449 { 449 {
450 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscr iption2"]; 450 return [200, "[Adblock]\n! Redirect: http://example.com/subscription2"];
451 }); 451 });
452 runner.registerHandler("/subscription2", metadata => 452 runner.registerHandler("/subscription2", metadata =>
453 { 453 {
454 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscr iption"]; 454 return [200, "[Adblock]\n! Redirect: http://example.com/subscription"];
455 }); 455 });
456 456
457 subscription = Subscription.fromURL("http://example.com/subscription"); 457 subscription = Subscription.fromURL("http://example.com/subscription");
458 resetSubscription(subscription); 458 resetSubscription(subscription);
459 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]); 459 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]);
460 filterStorage.addSubscription(subscription); 460 filterStorage.addSubscription(subscription);
461 461
462 return runner.runScheduledTasks(100); 462 return runner.runScheduledTasks(100);
463 }).then(() => 463 }).then(() =>
464 { 464 {
465 assert.equal([...filterStorage.subscriptions()][0].url, "http://example.co m/redirected", "Fallback can still redirect even after a redirect loop"); 465 assert.equal([...filterStorage.subscriptions()][0].url, "http://example.co m/redirected", "Fallback can still redirect even after a redirect loop");
466 }); 466 });
467 }); 467 });
468 468
469 it("State Fields", () => 469 it("State Fields", () =>
470 { 470 {
471 let subscription = Subscription.fromURL("http://example.com/subscription"); 471 let subscription = Subscription.fromURL("http://example.com/subscription");
472 filterStorage.addSubscription(subscription); 472 filterStorage.addSubscription(subscription);
473 473
474 runner.registerHandler("/subscription", metadata => 474 runner.registerHandler("/subscription", metadata =>
475 { 475 {
476 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 2 hours\nfoo\nbar"]; 476 return [200, "[Adblock]\n! Expires: 2 hours\nfoo\nbar"];
477 }); 477 });
478 478
479 let startTime = runner.currentTime; 479 let startTime = runner.currentTime;
480 return runner.runScheduledTasks(2).then(() => 480 return runner.runScheduledTasks(2).then(() =>
481 { 481 {
482 assert.equal(subscription.downloadStatus, "synchronize_ok", "downloadStatu s after successful download"); 482 assert.equal(subscription.downloadStatus, "synchronize_ok", "downloadStatu s after successful download");
483 assert.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + ini tialDelay * MILLIS_IN_HOUR, "lastDownload after successful download"); 483 assert.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + ini tialDelay * MILLIS_IN_HOUR, "lastDownload after successful download");
484 assert.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + init ialDelay * MILLIS_IN_HOUR, "lastSuccess after successful download"); 484 assert.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + init ialDelay * MILLIS_IN_HOUR, "lastSuccess after successful download");
485 assert.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (1 + i nitialDelay) * MILLIS_IN_HOUR, "lastCheck after successful download"); 485 assert.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (1 + i nitialDelay) * MILLIS_IN_HOUR, "lastCheck after successful download");
486 assert.equal(subscription.errors, 0, "errors after successful download"); 486 assert.equal(subscription.errors, 0, "errors after successful download");
487 487
488 runner.registerHandler("/subscription", metadata => 488 runner.registerHandler("/subscription", metadata =>
489 { 489 {
490 return [Cr.NS_ERROR_FAILURE, 0, ""]; 490 return [0, ""];
491 }); 491 });
492 492
493 return runner.runScheduledTasks(2); 493 return runner.runScheduledTasks(2);
494 }).then(() => 494 }).then(() =>
495 { 495 {
496 assert.equal(subscription.downloadStatus, "synchronize_connection_error", "downloadStatus after connection error"); 496 assert.equal(subscription.downloadStatus, "synchronize_connection_error", "downloadStatus after connection error");
497 assert.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (2 + initialDelay) * MILLIS_IN_HOUR, "lastDownload after connection error"); 497 assert.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (2 + initialDelay) * MILLIS_IN_HOUR, "lastDownload after connection error");
498 assert.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + init ialDelay * MILLIS_IN_HOUR, "lastSuccess after connection error"); 498 assert.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + init ialDelay * MILLIS_IN_HOUR, "lastSuccess after connection error");
499 assert.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (3 + i nitialDelay) * MILLIS_IN_HOUR, "lastCheck after connection error"); 499 assert.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (3 + i nitialDelay) * MILLIS_IN_HOUR, "lastCheck after connection error");
500 assert.equal(subscription.errors, 1, "errors after connection error"); 500 assert.equal(subscription.errors, 1, "errors after connection error");
501 501
502 runner.registerHandler("/subscription", metadata => 502 runner.registerHandler("/subscription", metadata =>
503 { 503 {
504 return [Cr.NS_OK, 404, ""]; 504 return [404, ""];
505 }); 505 });
506 506
507 return runner.runScheduledTasks(24); 507 return runner.runScheduledTasks(24);
508 }).then(() => 508 }).then(() =>
509 { 509 {
510 assert.equal(subscription.downloadStatus, "synchronize_connection_error", "downloadStatus after download error"); 510 assert.equal(subscription.downloadStatus, "synchronize_connection_error", "downloadStatus after download error");
511 assert.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + initialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); 511 assert.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + initialDelay) * MILLIS_IN_HOUR, "lastDownload after download error");
512 assert.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + init ialDelay * MILLIS_IN_HOUR, "lastSuccess after download error"); 512 assert.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + init ialDelay * MILLIS_IN_HOUR, "lastSuccess after download error");
513 assert.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + initialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); 513 assert.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + initialDelay) * MILLIS_IN_HOUR, "lastCheck after download error");
514 assert.equal(subscription.errors, 2, "errors after download error"); 514 assert.equal(subscription.errors, 2, "errors after download error");
515 }); 515 });
516 }); 516 });
517 517
518 it("Special Comment Ordering", () => 518 it("Special Comment Ordering", () =>
519 { 519 {
520 let subscription = Subscription.fromURL("http://example.com/subscription"); 520 let subscription = Subscription.fromURL("http://example.com/subscription");
521 filterStorage.addSubscription(subscription); 521 filterStorage.addSubscription(subscription);
522 522
523 runner.registerHandler("/subscription", metadata => 523 runner.registerHandler("/subscription", metadata =>
524 { 524 {
525 return [Cr.NS_OK, 200, "[Adblock]\n! Special Comment: x\n!foo\n! Title: fo obar\nfoo\nbar"]; 525 return [0, ""];
526 }); 526 });
527 527
528 return runner.runScheduledTasks(1).then(() => 528 return runner.runScheduledTasks(1).then(() =>
529 { 529 {
530 assert.equal(subscription.title, "http://example.com/subscription", "make sure title was not found"); 530 assert.equal(subscription.title, "http://example.com/subscription", "make sure title was not found");
531 }); 531 });
532 }); 532 });
533 533
534 it("Unkown Special Comments", () => 534 it("Unkown Special Comments", () =>
535 { 535 {
536 let subscription = Subscription.fromURL("http://example.com/subscription"); 536 let subscription = Subscription.fromURL("http://example.com/subscription");
537 filterStorage.addSubscription(subscription); 537 filterStorage.addSubscription(subscription);
538 538
539 runner.registerHandler("/subscription", metadata => 539 runner.registerHandler("/subscription", metadata =>
540 { 540 {
541 // To test allowing unknown special comments like `! :`, `!!@#$%^&*() : `, and `! Some Unknown Comment : ` 541 // To test allowing unknown special comments like `! :`, `!!@#$%^&*() : `, and `! Some Unknown Comment : `
542 return [Cr.NS_OK, 200, "[Adblock]\n! :\n! !@#$%^&*() :\n! Some Unknown Com ment :\n! Title: foobar\nfoo\nbar"]; 542 return [200, "[Adblock]\n! :\n! !@#$%^&*() :\n! Some Unknown Comment :\n! Title: foobar\nfoo\nbar"];
543 }); 543 });
544 544
545 return runner.runScheduledTasks(1).then(() => 545 return runner.runScheduledTasks(1).then(() =>
546 { 546 {
547 assert.equal(subscription.title, "foobar", "make sure title was found"); 547 assert.equal(subscription.title, "foobar", "make sure title was found");
548 }); 548 });
549 }); 549 });
550 }); 550 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld