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

Delta Between Two Patch Sets: test/subscriptionClasses.js

Issue 29934588: Issue 7094 - Encapsulate management of subscription filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Lazy initialize and clean up filter text lookup Created Nov. 18, 2018, 2:20 a.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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 function compareSubscriptionFilters(test, subscription, expected) 65 function compareSubscriptionFilters(test, subscription, expected)
66 { 66 {
67 test.deepEqual([...subscription.filterText()], expected); 67 test.deepEqual([...subscription.filterText()], expected);
68 test.deepEqual([...subscription.filters()], expected.map(f$)); 68 test.deepEqual([...subscription.filters()], expected.map(f$));
69 69
70 test.equal(subscription.filterCount, expected.length); 70 test.equal(subscription.filterCount, expected.length);
71 71
72 for (let i = 0; i < subscription.filterCount; i++) 72 for (let i = 0; i < subscription.filterCount; i++)
73 {
74 test.equal(subscription.filterAt(i).text, expected[i]); 73 test.equal(subscription.filterAt(i).text, expected[i]);
75 test.ok(subscription.hasFilter(f$(expected[i])));
76 }
77 74
78 test.ok(!subscription.filterAt(subscription.filterCount)); 75 test.ok(!subscription.filterAt(subscription.filterCount));
79 test.ok(!subscription.filterAt(-1)); 76 test.ok(!subscription.filterAt(-1));
80
81 subscription.clearCaches();
Manish Jethani 2018/11/18 02:25:51 Test again after clearing caches.
82
83 for (let i = 0; i < subscription.filterCount; i++)
84 test.ok(subscription.hasFilter(f$(expected[i])));
85 } 77 }
86 78
87 exports.testSubscriptionClassDefinitions = function(test) 79 exports.testSubscriptionClassDefinitions = function(test)
88 { 80 {
89 test.equal(typeof Subscription, "function", "typeof Subscription"); 81 test.equal(typeof Subscription, "function", "typeof Subscription");
90 test.equal(typeof SpecialSubscription, "function", "typeof SpecialSubscription "); 82 test.equal(typeof SpecialSubscription, "function", "typeof SpecialSubscription ");
91 test.equal(typeof RegularSubscription, "function", "typeof RegularSubscription "); 83 test.equal(typeof RegularSubscription, "function", "typeof RegularSubscription ");
92 test.equal(typeof ExternalSubscription, "function", "typeof ExternalSubscripti on"); 84 test.equal(typeof ExternalSubscription, "function", "typeof ExternalSubscripti on");
93 test.equal(typeof DownloadableSubscription, "function", "typeof DownloadableSu bscription"); 85 test.equal(typeof DownloadableSubscription, "function", "typeof DownloadableSu bscription");
94 86
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 subscription.addFilter(f$("##.bar")); 152 subscription.addFilter(f$("##.bar"));
161 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar", 153 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar",
162 "##.bar"]); 154 "##.bar"]);
163 155
164 // The first occurrence is found. 156 // The first occurrence is found.
165 test.equal(subscription.searchFilter(f$("##.bar")), 1); 157 test.equal(subscription.searchFilter(f$("##.bar")), 1);
166 158
167 subscription.deleteFilterAt(0); 159 subscription.deleteFilterAt(0);
168 compareSubscriptionFilters(test, subscription, ["##.bar", "##.bar"]); 160 compareSubscriptionFilters(test, subscription, ["##.bar", "##.bar"]);
169 test.equal(subscription.searchFilter(f$("##.bar")), 0); 161 test.equal(subscription.searchFilter(f$("##.bar")), 0);
170 test.ok(!subscription.hasFilter(f$("##.foo")));
171 162
172 subscription.insertFilterAt(f$("##.foo"), 0); 163 subscription.insertFilterAt(f$("##.foo"), 0);
173 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar", 164 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar",
174 "##.bar"]); 165 "##.bar"]);
175 test.equal(subscription.searchFilter(f$("##.bar")), 1); 166 test.equal(subscription.searchFilter(f$("##.bar")), 1);
176 167
177 subscription.deleteFilterAt(1); 168 subscription.deleteFilterAt(1);
178 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar"]); 169 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar"]);
179 test.equal(subscription.searchFilter(f$("##.bar")), 1); 170 test.equal(subscription.searchFilter(f$("##.bar")), 1);
180 171
181 subscription.deleteFilterAt(1); 172 subscription.deleteFilterAt(1);
182 compareSubscriptionFilters(test, subscription, ["##.foo"]); 173 compareSubscriptionFilters(test, subscription, ["##.foo"]);
183 test.equal(subscription.searchFilter(f$("##.bar")), -1); 174 test.equal(subscription.searchFilter(f$("##.bar")), -1);
184 test.ok(!subscription.hasFilter(f$("##.bar")));
185 175
186 subscription.addFilter(f$("##.bar")); 176 subscription.addFilter(f$("##.bar"));
187 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar"]); 177 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar"]);
188 test.equal(subscription.searchFilter(f$("##.bar")), 1); 178 test.equal(subscription.searchFilter(f$("##.bar")), 1);
189 179
190 subscription.clearFilters(); 180 subscription.clearFilters();
191 compareSubscriptionFilters(test, subscription, []); 181 compareSubscriptionFilters(test, subscription, []);
192 test.ok(!subscription.hasFilter(f$("##.foo")));
193 test.ok(!subscription.hasFilter(f$("##.bar")));
194 test.equal(subscription.searchFilter(f$("##.foo")), -1); 182 test.equal(subscription.searchFilter(f$("##.foo")), -1);
195 test.equal(subscription.searchFilter(f$("##.bar")), -1); 183 test.equal(subscription.searchFilter(f$("##.bar")), -1);
196 184
197 subscription.addFilter(f$("##.bar")); 185 subscription.addFilter(f$("##.bar"));
198 compareSubscriptionFilters(test, subscription, ["##.bar"]); 186 compareSubscriptionFilters(test, subscription, ["##.bar"]);
199 187
200 subscription.addFilter(f$("##.foo")); 188 subscription.addFilter(f$("##.foo"));
201 compareSubscriptionFilters(test, subscription, ["##.bar", "##.foo"]); 189 compareSubscriptionFilters(test, subscription, ["##.bar", "##.foo"]);
202 test.equal(subscription.searchFilter(f$("##.bar")), 0); 190 test.equal(subscription.searchFilter(f$("##.bar")), 0);
203 test.equal(subscription.searchFilter(f$("##.foo")), 1); 191 test.equal(subscription.searchFilter(f$("##.foo")), 1);
(...skipping 17 matching lines...) Expand all
221 test.equal(subscription.searchFilter(f$("##.lambda")), 0); 209 test.equal(subscription.searchFilter(f$("##.lambda")), 0);
222 210
223 // Delete outside of bounds (negative). 211 // Delete outside of bounds (negative).
224 subscription.deleteFilterAt(-1000); 212 subscription.deleteFilterAt(-1000);
225 compareSubscriptionFilters(test, subscription, ["##.lambda", "##.bar", 213 compareSubscriptionFilters(test, subscription, ["##.lambda", "##.bar",
226 "##.foo", "##.lambda"]); 214 "##.foo", "##.lambda"]);
227 test.equal(subscription.searchFilter(f$("##.lambda")), 0); 215 test.equal(subscription.searchFilter(f$("##.lambda")), 0);
228 216
229 test.done(); 217 test.done();
230 }; 218 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld