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

Side by Side Diff: test/filterStorage.js

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

Powered by Google App Engine
This is Rietveld