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

Powered by Google App Engine
This is Rietveld