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: Update tests Created Nov. 17, 2018, 11:40 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 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 } 77 }
81 78
82 exports.testSubscriptionClassDefinitions = function(test) 79 exports.testSubscriptionClassDefinitions = function(test)
83 { 80 {
84 test.equal(typeof Subscription, "function", "typeof Subscription"); 81 test.equal(typeof Subscription, "function", "typeof Subscription");
85 test.equal(typeof SpecialSubscription, "function", "typeof SpecialSubscription "); 82 test.equal(typeof SpecialSubscription, "function", "typeof SpecialSubscription ");
86 test.equal(typeof RegularSubscription, "function", "typeof RegularSubscription "); 83 test.equal(typeof RegularSubscription, "function", "typeof RegularSubscription ");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 133
137 test.done(); 134 test.done();
138 }; 135 };
139 136
140 exports.testFilterManagement = function(test) 137 exports.testFilterManagement = function(test)
141 { 138 {
142 let subscription = Subscription.fromURL("https://example.com/"); 139 let subscription = Subscription.fromURL("https://example.com/");
143 140
144 compareSubscriptionFilters(test, subscription, []); 141 compareSubscriptionFilters(test, subscription, []);
145 142
146 subscription.addFilter(f$("foo")); 143 subscription.addFilter(f$("##.foo"));
147 compareSubscriptionFilters(test, subscription, ["foo"]); 144 compareSubscriptionFilters(test, subscription, ["##.foo"]);
148 test.equal(subscription.searchFilter(f$("foo")), 0); 145 test.equal(subscription.searchFilter(f$("##.foo")), 0);
149 146
150 subscription.addFilter(f$("bar")); 147 subscription.addFilter(f$("##.bar"));
151 compareSubscriptionFilters(test, subscription, ["foo", "bar"]); 148 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar"]);
152 test.equal(subscription.searchFilter(f$("bar")), 1); 149 test.equal(subscription.searchFilter(f$("##.bar")), 1);
153 150
154 // Repeat filter. 151 // Repeat filter.
155 subscription.addFilter(f$("bar")); 152 subscription.addFilter(f$("##.bar"));
156 compareSubscriptionFilters(test, subscription, ["foo", "bar", "bar"]); 153 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar",
154 "##.bar"]);
157 155
158 // The first occurrence is found. 156 // The first occurrence is found.
159 test.equal(subscription.searchFilter(f$("bar")), 1); 157 test.equal(subscription.searchFilter(f$("##.bar")), 1);
160 158
161 subscription.deleteFilterAt(0); 159 subscription.deleteFilterAt(0);
162 compareSubscriptionFilters(test, subscription, ["bar", "bar"]); 160 compareSubscriptionFilters(test, subscription, ["##.bar", "##.bar"]);
163 test.equal(subscription.searchFilter(f$("bar")), 0); 161 test.equal(subscription.searchFilter(f$("##.bar")), 0);
164 test.ok(!subscription.hasFilter(f$("foo"))); 162
165 163 subscription.insertFilterAt(f$("##.foo"), 0);
166 subscription.insertFilterAt(f$("foo"), 0); 164 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar",
167 compareSubscriptionFilters(test, subscription, ["foo", "bar", "bar"]); 165 "##.bar"]);
168 test.equal(subscription.searchFilter(f$("bar")), 1); 166 test.equal(subscription.searchFilter(f$("##.bar")), 1);
169 167
170 subscription.deleteFilterAt(1); 168 subscription.deleteFilterAt(1);
171 compareSubscriptionFilters(test, subscription, ["foo", "bar"]); 169 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar"]);
172 test.equal(subscription.searchFilter(f$("bar")), 1); 170 test.equal(subscription.searchFilter(f$("##.bar")), 1);
173 171
174 subscription.deleteFilterAt(1); 172 subscription.deleteFilterAt(1);
175 compareSubscriptionFilters(test, subscription, ["foo"]); 173 compareSubscriptionFilters(test, subscription, ["##.foo"]);
176 test.equal(subscription.searchFilter(f$("bar")), -1); 174 test.equal(subscription.searchFilter(f$("##.bar")), -1);
177 test.ok(!subscription.hasFilter(f$("bar"))); 175
178 176 subscription.addFilter(f$("##.bar"));
179 subscription.addFilter(f$("bar")); 177 compareSubscriptionFilters(test, subscription, ["##.foo", "##.bar"]);
180 compareSubscriptionFilters(test, subscription, ["foo", "bar"]); 178 test.equal(subscription.searchFilter(f$("##.bar")), 1);
181 test.equal(subscription.searchFilter(f$("bar")), 1);
182 179
183 subscription.clearFilters(); 180 subscription.clearFilters();
184 compareSubscriptionFilters(test, subscription, []); 181 compareSubscriptionFilters(test, subscription, []);
185 test.ok(!subscription.hasFilter(f$("foo"))); 182 test.equal(subscription.searchFilter(f$("##.foo")), -1);
186 test.ok(!subscription.hasFilter(f$("bar"))); 183 test.equal(subscription.searchFilter(f$("##.bar")), -1);
187 test.equal(subscription.searchFilter(f$("foo")), -1); 184
188 test.equal(subscription.searchFilter(f$("bar")), -1); 185 subscription.addFilter(f$("##.bar"));
189 186 compareSubscriptionFilters(test, subscription, ["##.bar"]);
190 subscription.addFilter(f$("bar")); 187
191 compareSubscriptionFilters(test, subscription, ["bar"]); 188 subscription.addFilter(f$("##.foo"));
192 189 compareSubscriptionFilters(test, subscription, ["##.bar", "##.foo"]);
193 subscription.addFilter(f$("foo")); 190 test.equal(subscription.searchFilter(f$("##.bar")), 0);
194 compareSubscriptionFilters(test, subscription, ["bar", "foo"]); 191 test.equal(subscription.searchFilter(f$("##.foo")), 1);
195 test.equal(subscription.searchFilter(f$("bar")), 0);
196 test.equal(subscription.searchFilter(f$("foo")), 1);
197 192
198 // Insert outside of bounds. 193 // Insert outside of bounds.
199 subscription.insertFilterAt(f$("lambda"), 1000); 194 subscription.insertFilterAt(f$("##.lambda"), 1000);
200 compareSubscriptionFilters(test, subscription, ["bar", "foo", "lambda"]); 195 compareSubscriptionFilters(test, subscription, ["##.bar", "##.foo",
201 test.equal(subscription.searchFilter(f$("lambda")), 2); 196 "##.lambda"]);
197 test.equal(subscription.searchFilter(f$("##.lambda")), 2);
202 198
203 // Delete outside of bounds. 199 // Delete outside of bounds.
204 subscription.deleteFilterAt(1000); 200 subscription.deleteFilterAt(1000);
205 compareSubscriptionFilters(test, subscription, ["bar", "foo", "lambda"]); 201 compareSubscriptionFilters(test, subscription, ["##.bar", "##.foo",
206 test.equal(subscription.searchFilter(f$("lambda")), 2); 202 "##.lambda"]);
203 test.equal(subscription.searchFilter(f$("##.lambda")), 2);
207 204
208 // Insert outside of bounds (negative). 205 // Insert outside of bounds (negative).
209 subscription.insertFilterAt(f$("lambda"), -1000); 206 subscription.insertFilterAt(f$("##.lambda"), -1000);
210 compareSubscriptionFilters(test, subscription, ["lambda", "bar", "foo", 207 compareSubscriptionFilters(test, subscription, ["##.lambda", "##.bar",
211 "lambda"]); 208 "##.foo", "##.lambda"]);
212 test.equal(subscription.searchFilter(f$("lambda")), 0); 209 test.equal(subscription.searchFilter(f$("##.lambda")), 0);
213 210
214 // Delete outside of bounds (negative). 211 // Delete outside of bounds (negative).
215 subscription.deleteFilterAt(-1000); 212 subscription.deleteFilterAt(-1000);
216 compareSubscriptionFilters(test, subscription, ["lambda", "bar", "foo", 213 compareSubscriptionFilters(test, subscription, ["##.lambda", "##.bar",
217 "lambda"]); 214 "##.foo", "##.lambda"]);
218 test.equal(subscription.searchFilter(f$("lambda")), 0); 215 test.equal(subscription.searchFilter(f$("##.lambda")), 0);
219 216
220 test.done(); 217 test.done();
221 }; 218 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld