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

Delta Between Two Patch Sets: test/filterStorage.js

Issue 29934588: Issue 7094 - Encapsulate management of subscription filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Nov. 2, 2018, 10:34 p.m.
Right Patch Set: Remove hasFilter and related code Created Nov. 18, 2018, 10:21 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
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
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 if (knownSubscriptions) 65 if (knownSubscriptions)
66 { 66 {
67 test.deepEqual([...Subscription.knownSubscriptions.values()], 67 test.deepEqual([...Subscription.knownSubscriptions.values()],
68 knownSubscriptions, testMessage); 68 knownSubscriptions, testMessage);
69 } 69 }
70 } 70 }
71 71
72 function compareFiltersList(test, testMessage, list) 72 function compareFiltersList(test, testMessage, list)
73 { 73 {
74 let result = [...filterStorage.subscriptions()].map( 74 let result = [...filterStorage.subscriptions()].map(
75 subscription => subscription.filters); 75 subscription => [...subscription.filterText()]);
76 test.deepEqual(result, list, testMessage); 76 test.deepEqual(result, list, testMessage);
77 } 77 }
78 78
79 function compareFilterSubscriptions(test, testMessage, filter, list) 79 function compareFilterSubscriptions(test, testMessage, filter, list)
80 { 80 {
81 let result = [...filter.subscriptions()].map(subscription => subscription.url) ; 81 let result = [...filter.subscriptions()].map(subscription => subscription.url) ;
82 let expected = list.map(subscription => subscription.url); 82 let expected = list.map(subscription => subscription.url);
83 test.deepEqual(result, expected, testMessage); 83 test.deepEqual(result, expected, testMessage);
84 } 84 }
85 85
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 filterStorage.addFilter(Filter.fromText("!foobar"), subscription2, 0); 283 filterStorage.addFilter(Filter.fromText("!foobar"), subscription2, 0);
284 compareFiltersList(test, "Adding filter to an explicit subscription with posit ion", [["foo", "foo"], ["!foobar", "@@bar", "foo##bar", "foo#@#bar"], ["!foobar" , "foo"]]); 284 compareFiltersList(test, "Adding filter to an explicit subscription with posit ion", [["foo", "foo"], ["!foobar", "@@bar", "foo##bar", "foo#@#bar"], ["!foobar" , "foo"]]);
285 test.deepEqual(changes, ["filter.added !foobar"], "Received changes"); 285 test.deepEqual(changes, ["filter.added !foobar"], "Received changes");
286 286
287 test.done(); 287 test.done();
288 }; 288 };
289 289
290 exports.testRemovingFilters = function(test) 290 exports.testRemovingFilters = function(test)
291 { 291 {
292 let subscription1 = Subscription.fromURL("~foo"); 292 let subscription1 = Subscription.fromURL("~foo");
293 subscription1.filters = ["foo", "foo", "bar"]; 293 subscription1.addFilter(Filter.fromText("foo"));
294 subscription1.addFilter(Filter.fromText("foo"));
295 subscription1.addFilter(Filter.fromText("bar"));
294 296
295 let subscription2 = Subscription.fromURL("~bar"); 297 let subscription2 = Subscription.fromURL("~bar");
296 subscription2.filters = ["foo", "bar", "foo"]; 298 subscription2.addFilter(Filter.fromText("foo"));
299 subscription2.addFilter(Filter.fromText("bar"));
300 subscription2.addFilter(Filter.fromText("foo"));
297 301
298 let subscription3 = Subscription.fromURL("http://test/"); 302 let subscription3 = Subscription.fromURL("http://test/");
299 subscription3.filters = ["foo", "bar"]; 303 subscription3.addFilter(Filter.fromText("foo"));
304 subscription3.addFilter(Filter.fromText("bar"));
300 305
301 filterStorage.addSubscription(subscription1); 306 filterStorage.addSubscription(subscription1);
302 filterStorage.addSubscription(subscription2); 307 filterStorage.addSubscription(subscription2);
303 filterStorage.addSubscription(subscription3); 308 filterStorage.addSubscription(subscription3);
304 309
305 let changes = []; 310 let changes = [];
306 function listener(action, filter) 311 function listener(action, filter)
307 { 312 {
308 if (action.indexOf("filter.") == 0) 313 if (action.indexOf("filter.") == 0)
309 changes.push(action + " " + filter.text); 314 changes.push(action + " " + filter.text);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 filterStorage.removeFilter(Filter.fromText("bar")); 347 filterStorage.removeFilter(Filter.fromText("bar"));
343 compareFiltersList(test, "Remove of unknown filter", [[], ["foo"], ["foo", "ba r"]]); 348 compareFiltersList(test, "Remove of unknown filter", [[], ["foo"], ["foo", "ba r"]]);
344 test.deepEqual(changes, [], "Received changes"); 349 test.deepEqual(changes, [], "Received changes");
345 350
346 test.done(); 351 test.done();
347 }; 352 };
348 353
349 exports.testMovingFilters = function(test) 354 exports.testMovingFilters = function(test)
350 { 355 {
351 let subscription1 = Subscription.fromURL("~foo"); 356 let subscription1 = Subscription.fromURL("~foo");
352 subscription1.filters = ["foo", "bar", "bas", "foo"]; 357 subscription1.addFilter(Filter.fromText("foo"));
358 subscription1.addFilter(Filter.fromText("bar"));
359 subscription1.addFilter(Filter.fromText("bas"));
360 subscription1.addFilter(Filter.fromText("foo"));
353 361
354 let subscription2 = Subscription.fromURL("http://test/"); 362 let subscription2 = Subscription.fromURL("http://test/");
355 subscription2.filters = ["foo", "bar"]; 363 subscription2.addFilter(Filter.fromText("foo"));
364 subscription2.addFilter(Filter.fromText("bar"));
356 365
357 filterStorage.addSubscription(subscription1); 366 filterStorage.addSubscription(subscription1);
358 filterStorage.addSubscription(subscription2); 367 filterStorage.addSubscription(subscription2);
359 368
360 let changes = []; 369 let changes = [];
361 function listener(action, filter) 370 function listener(action, filter)
362 { 371 {
363 if (action.indexOf("filter.") == 0) 372 if (action.indexOf("filter.") == 0)
364 changes.push(action + " " + filter.text); 373 changes.push(action + " " + filter.text);
365 } 374 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 test.done(); 452 test.done();
444 }; 453 };
445 454
446 exports.testFilterSubscriptionRelationship = function(test) 455 exports.testFilterSubscriptionRelationship = function(test)
447 { 456 {
448 let filter1 = Filter.fromText("filter1"); 457 let filter1 = Filter.fromText("filter1");
449 let filter2 = Filter.fromText("filter2"); 458 let filter2 = Filter.fromText("filter2");
450 let filter3 = Filter.fromText("filter3"); 459 let filter3 = Filter.fromText("filter3");
451 460
452 let subscription1 = Subscription.fromURL("http://test1/"); 461 let subscription1 = Subscription.fromURL("http://test1/");
453 subscription1.filters = [filter1.text, filter2.text]; 462 subscription1.addFilter(filter1);
463 subscription1.addFilter(filter2);
454 464
455 let subscription2 = Subscription.fromURL("http://test2/"); 465 let subscription2 = Subscription.fromURL("http://test2/");
456 subscription2.filters = [filter2.text, filter3.text]; 466 subscription2.addFilter(filter2);
467 subscription2.addFilter(filter3);
457 468
458 let subscription3 = Subscription.fromURL("http://test3/"); 469 let subscription3 = Subscription.fromURL("http://test3/");
459 subscription3.filters = [filter1.text, filter2.text, filter3.text]; 470 subscription3.addFilter(filter1);
471 subscription3.addFilter(filter2);
472 subscription3.addFilter(filter3);
460 473
461 compareFilterSubscriptions(test, "Initial filter1 subscriptions", filter1, []) ; 474 compareFilterSubscriptions(test, "Initial filter1 subscriptions", filter1, []) ;
462 compareFilterSubscriptions(test, "Initial filter2 subscriptions", filter2, []) ; 475 compareFilterSubscriptions(test, "Initial filter2 subscriptions", filter2, []) ;
463 compareFilterSubscriptions(test, "Initial filter3 subscriptions", filter3, []) ; 476 compareFilterSubscriptions(test, "Initial filter3 subscriptions", filter3, []) ;
464 477
465 filterStorage.addSubscription(subscription1); 478 filterStorage.addSubscription(subscription1);
466 479
467 compareFilterSubscriptions(test, "filter1 subscriptions after adding http://te st1/", filter1, [subscription1]); 480 compareFilterSubscriptions(test, "filter1 subscriptions after adding http://te st1/", filter1, [subscription1]);
468 compareFilterSubscriptions(test, "filter2 subscriptions after adding http://te st1/", filter2, [subscription1]); 481 compareFilterSubscriptions(test, "filter2 subscriptions after adding http://te st1/", filter2, [subscription1]);
469 compareFilterSubscriptions(test, "filter3 subscriptions after adding http://te st1/", filter3, []); 482 compareFilterSubscriptions(test, "filter3 subscriptions after adding http://te st1/", filter3, []);
(...skipping 29 matching lines...) Expand all
499 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]); 512 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]);
500 513
501 filterStorage.removeSubscription(subscription3); 514 filterStorage.removeSubscription(subscription3);
502 515
503 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []); 516 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []);
504 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]); 517 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]);
505 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]); 518 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]);
506 519
507 test.done(); 520 test.done();
508 }; 521 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld