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

Side by Side Diff: test/synchronizer.js

Issue 29886685: Issue 6856 - Remove FilterStorage.moveSubscription (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Address PS5 Comments Created Oct. 1, 2018, 3:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/filterStorage_readwrite.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 319
320 this.registerHandler("/subscription", metadata => 320 this.registerHandler("/subscription", metadata =>
321 { 321 {
322 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/redirected\ nbar"]; 322 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/redirected\ nbar"];
323 }); 323 });
324 324
325 let requests; 325 let requests;
326 326
327 this.runScheduledTasks(30).then(() => 327 this.runScheduledTasks(30).then(() =>
328 { 328 {
329 test.equal(FilterStorage.subscriptions[0], subscription, "Invalid redirect i gnored"); 329 test.equal([...FilterStorage.subscriptions()][0], subscription, "Invalid red irect ignored");
330 test.equal(subscription.downloadStatus, "synchronize_connection_error", "Con nection error recorded"); 330 test.equal(subscription.downloadStatus, "synchronize_connection_error", "Con nection error recorded");
331 test.equal(subscription.errors, 2, "Number of download errors"); 331 test.equal(subscription.errors, 2, "Number of download errors");
332 332
333 requests = []; 333 requests = [];
334 334
335 this.registerHandler("/redirected", metadata => 335 this.registerHandler("/redirected", metadata =>
336 { 336 {
337 requests.push(this.getTimeOffset()); 337 requests.push(this.getTimeOffset());
338 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 8 hours\nbar"]; 338 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 8 hours\nbar"];
339 }); 339 });
340 340
341 resetSubscription(subscription); 341 resetSubscription(subscription);
342 return this.runScheduledTasks(15); 342 return this.runScheduledTasks(15);
343 }).then(() => 343 }).then(() =>
344 { 344 {
345 test.equal(FilterStorage.subscriptions[0].url, "http://example.com/redirecte d", "Redirect followed"); 345 test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/re directed", "Redirect followed");
346 test.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resulting re quests"); 346 test.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resulting re quests");
347 347
348 this.registerHandler("/redirected", metadata => 348 this.registerHandler("/redirected", metadata =>
349 { 349 {
350 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/subscript ion\nbar"]; 350 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/subscript ion\nbar"];
351 }); 351 });
352 352
353 subscription = Subscription.fromURL("http://example.com/subscription"); 353 subscription = Subscription.fromURL("http://example.com/subscription");
354 resetSubscription(subscription); 354 resetSubscription(subscription);
355 FilterStorage.removeSubscription(FilterStorage.subscriptions[0]); 355 FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]);
356 FilterStorage.addSubscription(subscription); 356 FilterStorage.addSubscription(subscription);
357 357
358 return this.runScheduledTasks(2); 358 return this.runScheduledTasks(2);
359 }).then(() => 359 }).then(() =>
360 { 360 {
361 test.equal(FilterStorage.subscriptions[0], subscription, "Redirect not follo wed on redirect loop"); 361 test.equal([...FilterStorage.subscriptions()][0], subscription, "Redirect no t followed on redirect loop");
362 test.equal(subscription.downloadStatus, "synchronize_connection_error", "Dow nload status after redirect loop"); 362 test.equal(subscription.downloadStatus, "synchronize_connection_error", "Dow nload status after redirect loop");
363 }).catch(unexpectedError.bind(test)).then(() => test.done()); 363 }).catch(unexpectedError.bind(test)).then(() => test.done());
364 }; 364 };
365 365
366 exports.testFallback = function(test) 366 exports.testFallback = function(test)
367 { 367 {
368 Prefs.subscriptions_fallbackerrors = 3; 368 Prefs.subscriptions_fallbackerrors = 3;
369 Prefs.subscriptions_fallbackurl = "http://example.com/fallback?%SUBSCRIPTION%& %CHANNELSTATUS%&%RESPONSESTATUS%"; 369 Prefs.subscriptions_fallbackurl = "http://example.com/fallback?%SUBSCRIPTION%& %CHANNELSTATUS%&%RESPONSESTATUS%";
370 370
371 let subscription = Subscription.fromURL("http://example.com/subscription"); 371 let subscription = Subscription.fromURL("http://example.com/subscription");
(...skipping 28 matching lines...) Expand all
400 return this.runScheduledTasks(100); 400 return this.runScheduledTasks(100);
401 }).then(() => 401 }).then(() =>
402 { 402 {
403 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD elay], "Stop trying if the fallback responds with Gone"); 403 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD elay], "Stop trying if the fallback responds with Gone");
404 test.equal(fallbackParams, "http://example.com/subscription&0&404", "Fallbac k arguments"); 404 test.equal(fallbackParams, "http://example.com/subscription&0&404", "Fallbac k arguments");
405 405
406 // Fallback redirecting to a missing file 406 // Fallback redirecting to a missing file
407 407
408 subscription = Subscription.fromURL("http://example.com/subscription"); 408 subscription = Subscription.fromURL("http://example.com/subscription");
409 resetSubscription(subscription); 409 resetSubscription(subscription);
410 FilterStorage.removeSubscription(FilterStorage.subscriptions[0]); 410 FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]);
411 FilterStorage.addSubscription(subscription); 411 FilterStorage.addSubscription(subscription);
412 requests = []; 412 requests = [];
413 413
414 this.registerHandler("/fallback", metadata => 414 this.registerHandler("/fallback", metadata =>
415 { 415 {
416 return [Cr.NS_OK, 200, "301 http://example.com/redirected"]; 416 return [Cr.NS_OK, 200, "301 http://example.com/redirected"];
417 }); 417 });
418 return this.runScheduledTasks(100); 418 return this.runScheduledTasks(100);
419 }).then(() => 419 }).then(() =>
420 { 420 {
421 test.equal(FilterStorage.subscriptions[0].url, "http://example.com/subscript ion", "Ignore invalid redirect from fallback"); 421 test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/su bscription", "Ignore invalid redirect from fallback");
422 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD elay, 72 + initialDelay, 96 + initialDelay], "Requests not affected by invalid r edirect"); 422 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD elay, 72 + initialDelay, 96 + initialDelay], "Requests not affected by invalid r edirect");
423 423
424 // Fallback redirecting to an existing file 424 // Fallback redirecting to an existing file
425 425
426 resetSubscription(subscription); 426 resetSubscription(subscription);
427 requests = []; 427 requests = [];
428 redirectedRequests = []; 428 redirectedRequests = [];
429 this.registerHandler("/redirected", metadata => 429 this.registerHandler("/redirected", metadata =>
430 { 430 {
431 redirectedRequests.push(this.getTimeOffset()); 431 redirectedRequests.push(this.getTimeOffset());
432 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"]; 432 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"];
433 }); 433 });
434 434
435 return this.runScheduledTasks(100); 435 return this.runScheduledTasks(100);
436 }).then(() => 436 }).then(() =>
437 { 437 {
438 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/re directed", "Valid redirect from fallback is followed");
439 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");
440 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");
441 441
442 // Redirect loop 442 // Redirect loop
443 443
444 this.registerHandler("/subscription", metadata => 444 this.registerHandler("/subscription", metadata =>
445 { 445 {
446 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"];
447 }); 447 });
448 this.registerHandler("/subscription2", metadata => 448 this.registerHandler("/subscription2", metadata =>
449 { 449 {
450 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"];
451 }); 451 });
452 452
453 subscription = Subscription.fromURL("http://example.com/subscription"); 453 subscription = Subscription.fromURL("http://example.com/subscription");
454 resetSubscription(subscription); 454 resetSubscription(subscription);
455 FilterStorage.removeSubscription(FilterStorage.subscriptions[0]); 455 FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]);
456 FilterStorage.addSubscription(subscription); 456 FilterStorage.addSubscription(subscription);
457 457
458 return this.runScheduledTasks(100); 458 return this.runScheduledTasks(100);
459 }).then(() => 459 }).then(() =>
460 { 460 {
461 test.equal(FilterStorage.subscriptions[0].url, "http://example.com/redirecte d", "Fallback can still redirect even after a redirect loop"); 461 test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/re directed", "Fallback can still redirect even after a redirect loop");
462 }).catch(unexpectedError.bind(test)).then(() => test.done()); 462 }).catch(unexpectedError.bind(test)).then(() => test.done());
463 }; 463 };
464 464
465 exports.testStateFields = function(test) 465 exports.testStateFields = function(test)
466 { 466 {
467 let subscription = Subscription.fromURL("http://example.com/subscription"); 467 let subscription = Subscription.fromURL("http://example.com/subscription");
468 FilterStorage.addSubscription(subscription); 468 FilterStorage.addSubscription(subscription);
469 469
470 this.registerHandler("/subscription", metadata => 470 this.registerHandler("/subscription", metadata =>
471 { 471 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 return this.runScheduledTasks(24); 503 return this.runScheduledTasks(24);
504 }).then(() => 504 }).then(() =>
505 { 505 {
506 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");
507 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");
508 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");
509 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");
510 test.equal(subscription.errors, 2, "errors after download error"); 510 test.equal(subscription.errors, 2, "errors after download error");
511 }).catch(unexpectedError.bind(test)).then(() => test.done()); 511 }).catch(unexpectedError.bind(test)).then(() => test.done());
512 }; 512 };
OLDNEW
« no previous file with comments | « test/filterStorage_readwrite.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld