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

Delta Between Two Patch Sets: test/filterStorage.js

Issue 29853574: Issue 6855 - Release all references to Subscription object once removed (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Add tests Created Aug. 12, 2018, 6:34 a.m.
Right Patch Set: Improve tests Created Aug. 16, 2018, 5:33 a.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 | « lib/filterStorage.js ('k') | no next file » | 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
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 function compareFiltersList(test, testMessage, list) 56 function compareFiltersList(test, testMessage, list)
57 { 57 {
58 let result = FilterStorage.subscriptions.map( 58 let result = FilterStorage.subscriptions.map(
59 subscription => subscription.filters.map( 59 subscription => subscription.filters.map(
60 filter => filter.text)); 60 filter => filter.text));
61 test.deepEqual(result, list, testMessage); 61 test.deepEqual(result, list, testMessage);
62 } 62 }
63 63
64 function compareFilterSubscriptions(test, testMessage, filter, list) 64 function compareFilterSubscriptions(test, testMessage, filter, list)
65 { 65 {
66 let result = filter.subscriptions.map(subscription => subscription.url); 66 let result = [...filter.subscriptions].map(subscription => subscription.url);
67 let expected = list.map(subscription => subscription.url); 67 let expected = list.map(subscription => subscription.url);
68 test.deepEqual(result, expected, testMessage); 68 test.deepEqual(result, expected, testMessage);
69 } 69 }
70 70
71 exports.testAddingSubscriptions = function(test) 71 exports.testAddingSubscriptions = function(test)
72 { 72 {
73 let subscription1 = Subscription.fromURL("http://test1/"); 73 let subscription1 = Subscription.fromURL("http://test1/");
74 let subscription2 = Subscription.fromURL("http://test2/"); 74 let subscription2 = Subscription.fromURL("http://test2/");
75 75
76 let changes = []; 76 let changes = [];
(...skipping 30 matching lines...) Expand all
107 compareSubscriptionList(test, "Re-adding previously removed subscription", [su bscription2, subscription1]); 107 compareSubscriptionList(test, "Re-adding previously removed subscription", [su bscription2, subscription1]);
108 test.deepEqual(changes, ["subscription.added http://test1/"], "Received change s"); 108 test.deepEqual(changes, ["subscription.added http://test1/"], "Received change s");
109 109
110 test.done(); 110 test.done();
111 }; 111 };
112 112
113 exports.testRemovingSubscriptions = function(test) 113 exports.testRemovingSubscriptions = function(test)
114 { 114 {
115 let subscription1 = Subscription.fromURL("http://test1/"); 115 let subscription1 = Subscription.fromURL("http://test1/");
116 let subscription2 = Subscription.fromURL("http://test2/"); 116 let subscription2 = Subscription.fromURL("http://test2/");
117
118 test.equal(Subscription.fromURL(subscription1.url), subscription1,
119 "Subscription known before addition");
120
117 FilterStorage.addSubscription(subscription1); 121 FilterStorage.addSubscription(subscription1);
118 FilterStorage.addSubscription(subscription2); 122 FilterStorage.addSubscription(subscription2);
119 123
120 let changes = []; 124 let changes = [];
121 function listener(action, subscription) 125 function listener(action, subscription)
122 { 126 {
123 if (action.indexOf("subscription.") == 0) 127 if (action.indexOf("subscription.") == 0)
124 changes.push(action + " " + subscription.url); 128 changes.push(action + " " + subscription.url);
125 } 129 }
126 FilterNotifier.addListener(listener); 130 FilterNotifier.addListener(listener);
127 131
128 compareSubscriptionList(test, "Initial state", [subscription1, subscription2], 132 compareSubscriptionList(test, "Initial state", [subscription1, subscription2],
129 [subscription1, subscription2]); 133 [subscription1, subscription2]);
130 test.deepEqual(changes, [], "Received changes"); 134 test.deepEqual(changes, [], "Received changes");
135
136 test.equal(Subscription.fromURL(subscription1.url), subscription1,
137 "Subscription known after addition");
131 138
132 changes = []; 139 changes = [];
133 FilterStorage.removeSubscription(subscription1); 140 FilterStorage.removeSubscription(subscription1);
134 compareSubscriptionList(test, "Removing first subscription", [subscription2], 141 compareSubscriptionList(test, "Removing first subscription", [subscription2],
135 [subscription2]); 142 [subscription2]);
136 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges"); 143 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges");
137 144
145 // Once a subscription has been removed, it is forgotten; a new object is
146 // created for the previously known subscription URL.
147 test.notEqual(Subscription.fromURL(subscription1.url), subscription1,
148 "Subscription forgotten upon removal");
149 Subscription.knownSubscriptions.delete(subscription1.url);
150
138 changes = []; 151 changes = [];
139 FilterStorage.removeSubscription(subscription1); 152 FilterStorage.removeSubscription(subscription1);
140 compareSubscriptionList(test, "Removing already removed subscription", [subscr iption2], 153 compareSubscriptionList(test, "Removing already removed subscription", [subscr iption2],
141 [subscription2]); 154 [subscription2]);
142 test.deepEqual(changes, [], "Received changes"); 155 test.deepEqual(changes, [], "Received changes");
143 156
144 changes = []; 157 changes = [];
145 FilterStorage.removeSubscription(subscription2); 158 FilterStorage.removeSubscription(subscription2);
146 compareSubscriptionList(test, "Removing remaining subscription", [], []); 159 compareSubscriptionList(test, "Removing remaining subscription", [], []);
147 test.deepEqual(changes, ["subscription.removed http://test2/"], "Received chan ges"); 160 test.deepEqual(changes, ["subscription.removed http://test2/"], "Received chan ges");
148 161
149 // Compare references to make sure that a new object is created for the same 162 FilterStorage.addSubscription(subscription1);
150 // subscription URL. 163 compareSubscriptionList(test, "Add", [subscription1], []);
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.
156 FilterStorage.addSubscription(subscription1);
157 compareSubscriptionList(test, "Add", [subscription1]);
158 164
159 changes = []; 165 changes = [];
160 FilterStorage.removeSubscription(subscription1); 166 FilterStorage.removeSubscription(subscription1);
161 compareSubscriptionList(test, "Re-removing previously added subscription", []) ; 167 compareSubscriptionList(test, "Re-removing previously added subscription", [], []);
162 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges"); 168 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges");
163 169
164 test.done(); 170 test.done();
165 }; 171 };
166 172
167 exports.testMovingSubscriptions = function(test) 173 exports.testMovingSubscriptions = function(test)
168 { 174 {
169 let subscription1 = Subscription.fromURL("http://test1/"); 175 let subscription1 = Subscription.fromURL("http://test1/");
170 let subscription2 = Subscription.fromURL("http://test2/"); 176 let subscription2 = Subscription.fromURL("http://test2/");
171 let subscription3 = Subscription.fromURL("http://test3/"); 177 let subscription3 = Subscription.fromURL("http://test3/");
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]); 514 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]);
509 515
510 FilterStorage.removeSubscription(subscription3); 516 FilterStorage.removeSubscription(subscription3);
511 517
512 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []); 518 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []);
513 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]); 519 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]);
514 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]); 520 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]);
515 521
516 test.done(); 522 test.done();
517 }; 523 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld