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

Side by Side Diff: test/filterStorage.js

Issue 29853574: Issue 6855 - Release all references to Subscription object once removed (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Remove Subscription object before emitting "subscription.removed" event Created Aug. 12, 2018, 7:12 a.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 | « lib/filterStorage.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 21 matching lines...) Expand all
32 ( 32 (
33 {Filter} = sandboxedRequire("../lib/filterClasses"), 33 {Filter} = sandboxedRequire("../lib/filterClasses"),
34 {FilterNotifier} = sandboxedRequire("../lib/filterNotifier"), 34 {FilterNotifier} = sandboxedRequire("../lib/filterNotifier"),
35 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), 35 {FilterStorage} = sandboxedRequire("../lib/filterStorage"),
36 {Subscription} = sandboxedRequire("../lib/subscriptionClasses") 36 {Subscription} = sandboxedRequire("../lib/subscriptionClasses")
37 ); 37 );
38 38
39 callback(); 39 callback();
40 }; 40 };
41 41
42 function compareSubscriptionList(test, testMessage, list) 42 function compareSubscriptionList(test, testMessage, list,
43 knownSubscriptions = null)
43 { 44 {
44 let result = FilterStorage.subscriptions.map(subscription => subscription.url) ; 45 let result = FilterStorage.subscriptions.map(subscription => subscription.url) ;
45 let expected = list.map(subscription => subscription.url); 46 let expected = list.map(subscription => subscription.url);
46 test.deepEqual(result, expected, testMessage); 47 test.deepEqual(result, expected, testMessage);
48
49 if (knownSubscriptions)
50 {
51 test.deepEqual([...Subscription.knownSubscriptions.values()],
52 knownSubscriptions, testMessage);
53 }
47 } 54 }
48 55
49 function compareFiltersList(test, testMessage, list) 56 function compareFiltersList(test, testMessage, list)
50 { 57 {
51 let result = FilterStorage.subscriptions.map( 58 let result = FilterStorage.subscriptions.map(
52 subscription => subscription.filters.map( 59 subscription => subscription.filters.map(
53 filter => filter.text)); 60 filter => filter.text));
54 test.deepEqual(result, list, testMessage); 61 test.deepEqual(result, list, testMessage);
55 } 62 }
56 63
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 FilterStorage.addSubscription(subscription2); 118 FilterStorage.addSubscription(subscription2);
112 119
113 let changes = []; 120 let changes = [];
114 function listener(action, subscription) 121 function listener(action, subscription)
115 { 122 {
116 if (action.indexOf("subscription.") == 0) 123 if (action.indexOf("subscription.") == 0)
117 changes.push(action + " " + subscription.url); 124 changes.push(action + " " + subscription.url);
118 } 125 }
119 FilterNotifier.addListener(listener); 126 FilterNotifier.addListener(listener);
120 127
121 compareSubscriptionList(test, "Initial state", [subscription1, subscription2]) ; 128 compareSubscriptionList(test, "Initial state", [subscription1, subscription2],
129 [subscription1, subscription2]);
122 test.deepEqual(changes, [], "Received changes"); 130 test.deepEqual(changes, [], "Received changes");
123 131
124 changes = []; 132 changes = [];
125 FilterStorage.removeSubscription(subscription1); 133 FilterStorage.removeSubscription(subscription1);
126 compareSubscriptionList(test, "Removing first subscription", [subscription2]); 134 compareSubscriptionList(test, "Removing first subscription", [subscription2],
135 [subscription2]);
127 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges"); 136 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges");
128 137
129 changes = []; 138 changes = [];
130 FilterStorage.removeSubscription(subscription1); 139 FilterStorage.removeSubscription(subscription1);
131 compareSubscriptionList(test, "Removing already removed subscription", [subscr iption2]); 140 compareSubscriptionList(test, "Removing already removed subscription", [subscr iption2],
141 [subscription2]);
132 test.deepEqual(changes, [], "Received changes"); 142 test.deepEqual(changes, [], "Received changes");
133 143
134 changes = []; 144 changes = [];
135 FilterStorage.removeSubscription(subscription2); 145 FilterStorage.removeSubscription(subscription2);
136 compareSubscriptionList(test, "Removing remaining subscription", []); 146 compareSubscriptionList(test, "Removing remaining subscription", [], []);
137 test.deepEqual(changes, ["subscription.removed http://test2/"], "Received chan ges"); 147 test.deepEqual(changes, ["subscription.removed http://test2/"], "Received chan ges");
138 148
149 // Compare references to make sure that a new object is created for the same
150 // subscription URL.
151 test.notEqual(Subscription.fromURL(subscription2.url), subscription2,
152 "Subscription forgotten");
153
154 // Adding a removed Subscription object back still works but is not
155 // recommended.
139 FilterStorage.addSubscription(subscription1); 156 FilterStorage.addSubscription(subscription1);
140 compareSubscriptionList(test, "Add", [subscription1]); 157 compareSubscriptionList(test, "Add", [subscription1]);
141 158
142 changes = []; 159 changes = [];
143 FilterStorage.removeSubscription(subscription1); 160 FilterStorage.removeSubscription(subscription1);
144 compareSubscriptionList(test, "Re-removing previously added subscription", []) ; 161 compareSubscriptionList(test, "Re-removing previously added subscription", []) ;
145 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges"); 162 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges");
146 163
147 test.done(); 164 test.done();
148 }; 165 };
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 compareFilterSubscriptions(test, "filter1 subscriptions after adding http://te st1/", filter1, [subscription1]); 476 compareFilterSubscriptions(test, "filter1 subscriptions after adding http://te st1/", filter1, [subscription1]);
460 compareFilterSubscriptions(test, "filter2 subscriptions after adding http://te st1/", filter2, [subscription1]); 477 compareFilterSubscriptions(test, "filter2 subscriptions after adding http://te st1/", filter2, [subscription1]);
461 compareFilterSubscriptions(test, "filter3 subscriptions after adding http://te st1/", filter3, []); 478 compareFilterSubscriptions(test, "filter3 subscriptions after adding http://te st1/", filter3, []);
462 479
463 FilterStorage.addSubscription(subscription2); 480 FilterStorage.addSubscription(subscription2);
464 481
465 compareFilterSubscriptions(test, "filter1 subscriptions after adding http://te st2/", filter1, [subscription1]); 482 compareFilterSubscriptions(test, "filter1 subscriptions after adding http://te st2/", filter1, [subscription1]);
466 compareFilterSubscriptions(test, "filter2 subscriptions after adding http://te st2/", filter2, [subscription1, subscription2]); 483 compareFilterSubscriptions(test, "filter2 subscriptions after adding http://te st2/", filter2, [subscription1, subscription2]);
467 compareFilterSubscriptions(test, "filter3 subscriptions after adding http://te st2/", filter3, [subscription2]); 484 compareFilterSubscriptions(test, "filter3 subscriptions after adding http://te st2/", filter3, [subscription2]);
468 485
486 // Test duplicate subscription entries, which can occur when a subscription
487 // is loaded from disk and contains the same filter more than once.
488 filter1.subscriptions.push(subscription1);
489 compareFilterSubscriptions(test, "filter1 subscriptions after duplicating http ://test1/",
490 filter1, [subscription1, subscription1]);
491
469 FilterStorage.removeSubscription(subscription1); 492 FilterStorage.removeSubscription(subscription1);
470 493
471 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test1/", filter1, []); 494 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test1/", filter1, []);
472 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test1/", filter2, [subscription2]); 495 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test1/", filter2, [subscription2]);
473 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test1/", filter3, [subscription2]); 496 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test1/", filter3, [subscription2]);
474 497
475 FilterStorage.updateSubscriptionFilters(subscription3, [filter3]); 498 FilterStorage.updateSubscriptionFilters(subscription3, [filter3]);
476 499
477 compareFilterSubscriptions(test, "filter1 subscriptions after updating http:// test3/ filters", filter1, []); 500 compareFilterSubscriptions(test, "filter1 subscriptions after updating http:// test3/ filters", filter1, []);
478 compareFilterSubscriptions(test, "filter2 subscriptions after updating http:// test3/ filters", filter2, [subscription2]); 501 compareFilterSubscriptions(test, "filter2 subscriptions after updating http:// test3/ filters", filter2, [subscription2]);
(...skipping 12 matching lines...) Expand all
491 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]); 514 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]);
492 515
493 FilterStorage.removeSubscription(subscription3); 516 FilterStorage.removeSubscription(subscription3);
494 517
495 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []); 518 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []);
496 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]); 519 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]);
497 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]); 520 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]);
498 521
499 test.done(); 522 test.done();
500 }; 523 };
OLDNEW
« no previous file with comments | « lib/filterStorage.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld