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

Side by Side Diff: test/filterStorage.js

Issue 29853561: Issue 6854 - Remove deprecated FilterNotifier methods (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Aug. 11, 2018, 2:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« test/filterNotifier.js ('K') | « test/filterNotifier.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 addListener(listener)
43 {
44 let makeWrapper = name => (...args) => listener(name, ...args);
45
46 FilterNotifier.on("subscription.added", makeWrapper("subscription.added"));
Manish Jethani 2018/08/11 14:47:06 Since there is no catch-all event (unlike FilterNo
47 FilterNotifier.on("subscription.removed",
48 makeWrapper("subscription.removed"));
49 FilterNotifier.on("subscription.moved", makeWrapper("subscription.moved"));
50
51 FilterNotifier.on("filter.added", makeWrapper("filter.added"));
52 FilterNotifier.on("filter.removed", makeWrapper("filter.removed"));
53 FilterNotifier.on("filter.moved", makeWrapper("filter.moved"));
54
55 FilterNotifier.on("filter.hitCount", makeWrapper("filter.hitCount"));
56 FilterNotifier.on("filter.lastHit", makeWrapper("filter.lastHit"));
57 }
58
42 function compareSubscriptionList(test, testMessage, list) 59 function compareSubscriptionList(test, testMessage, list)
43 { 60 {
44 let result = FilterStorage.subscriptions.map(subscription => subscription.url) ; 61 let result = FilterStorage.subscriptions.map(subscription => subscription.url) ;
45 let expected = list.map(subscription => subscription.url); 62 let expected = list.map(subscription => subscription.url);
46 test.deepEqual(result, expected, testMessage); 63 test.deepEqual(result, expected, testMessage);
47 } 64 }
48 65
49 function compareFiltersList(test, testMessage, list) 66 function compareFiltersList(test, testMessage, list)
50 { 67 {
51 let result = FilterStorage.subscriptions.map( 68 let result = FilterStorage.subscriptions.map(
(...skipping 13 matching lines...) Expand all
65 { 82 {
66 let subscription1 = Subscription.fromURL("http://test1/"); 83 let subscription1 = Subscription.fromURL("http://test1/");
67 let subscription2 = Subscription.fromURL("http://test2/"); 84 let subscription2 = Subscription.fromURL("http://test2/");
68 85
69 let changes = []; 86 let changes = [];
70 function listener(action, subscription) 87 function listener(action, subscription)
71 { 88 {
72 if (action.indexOf("subscription.") == 0) 89 if (action.indexOf("subscription.") == 0)
73 changes.push(action + " " + subscription.url); 90 changes.push(action + " " + subscription.url);
74 } 91 }
75 FilterNotifier.addListener(listener); 92 addListener(listener);
76 93
77 compareSubscriptionList(test, "Initial state", []); 94 compareSubscriptionList(test, "Initial state", []);
78 test.deepEqual(changes, [], "Received changes"); 95 test.deepEqual(changes, [], "Received changes");
79 96
80 changes = []; 97 changes = [];
81 FilterStorage.addSubscription(subscription1); 98 FilterStorage.addSubscription(subscription1);
82 compareSubscriptionList(test, "Adding first subscription", [subscription1]); 99 compareSubscriptionList(test, "Adding first subscription", [subscription1]);
83 test.deepEqual(changes, ["subscription.added http://test1/"], "Received change s"); 100 test.deepEqual(changes, ["subscription.added http://test1/"], "Received change s");
84 101
85 changes = []; 102 changes = [];
(...skipping 23 matching lines...) Expand all
109 let subscription2 = Subscription.fromURL("http://test2/"); 126 let subscription2 = Subscription.fromURL("http://test2/");
110 FilterStorage.addSubscription(subscription1); 127 FilterStorage.addSubscription(subscription1);
111 FilterStorage.addSubscription(subscription2); 128 FilterStorage.addSubscription(subscription2);
112 129
113 let changes = []; 130 let changes = [];
114 function listener(action, subscription) 131 function listener(action, subscription)
115 { 132 {
116 if (action.indexOf("subscription.") == 0) 133 if (action.indexOf("subscription.") == 0)
117 changes.push(action + " " + subscription.url); 134 changes.push(action + " " + subscription.url);
118 } 135 }
119 FilterNotifier.addListener(listener); 136 addListener(listener);
120 137
121 compareSubscriptionList(test, "Initial state", [subscription1, subscription2]) ; 138 compareSubscriptionList(test, "Initial state", [subscription1, subscription2]) ;
122 test.deepEqual(changes, [], "Received changes"); 139 test.deepEqual(changes, [], "Received changes");
123 140
124 changes = []; 141 changes = [];
125 FilterStorage.removeSubscription(subscription1); 142 FilterStorage.removeSubscription(subscription1);
126 compareSubscriptionList(test, "Removing first subscription", [subscription2]); 143 compareSubscriptionList(test, "Removing first subscription", [subscription2]);
127 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges"); 144 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan ges");
128 145
129 changes = []; 146 changes = [];
(...skipping 26 matching lines...) Expand all
156 FilterStorage.addSubscription(subscription1); 173 FilterStorage.addSubscription(subscription1);
157 FilterStorage.addSubscription(subscription2); 174 FilterStorage.addSubscription(subscription2);
158 FilterStorage.addSubscription(subscription3); 175 FilterStorage.addSubscription(subscription3);
159 176
160 let changes = []; 177 let changes = [];
161 function listener(action, subscription) 178 function listener(action, subscription)
162 { 179 {
163 if (action.indexOf("subscription.") == 0) 180 if (action.indexOf("subscription.") == 0)
164 changes.push(action + " " + subscription.url); 181 changes.push(action + " " + subscription.url);
165 } 182 }
166 FilterNotifier.addListener(listener); 183 addListener(listener);
167 184
168 compareSubscriptionList(test, "Initial state", [subscription1, subscription2, subscription3]); 185 compareSubscriptionList(test, "Initial state", [subscription1, subscription2, subscription3]);
169 test.deepEqual(changes, [], "Received changes"); 186 test.deepEqual(changes, [], "Received changes");
170 187
171 changes = []; 188 changes = [];
172 FilterStorage.moveSubscription(subscription1); 189 FilterStorage.moveSubscription(subscription1);
173 compareSubscriptionList(test, "Move without explicit position", [subscription2 , subscription3, subscription1]); 190 compareSubscriptionList(test, "Move without explicit position", [subscription2 , subscription3, subscription1]);
174 test.deepEqual(changes, ["subscription.moved http://test1/"], "Received change s"); 191 test.deepEqual(changes, ["subscription.moved http://test1/"], "Received change s");
175 192
176 changes = []; 193 changes = [];
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 FilterStorage.addSubscription(subscription1); 234 FilterStorage.addSubscription(subscription1);
218 FilterStorage.addSubscription(subscription2); 235 FilterStorage.addSubscription(subscription2);
219 FilterStorage.addSubscription(subscription3); 236 FilterStorage.addSubscription(subscription3);
220 237
221 let changes = []; 238 let changes = [];
222 function listener(action, filter) 239 function listener(action, filter)
223 { 240 {
224 if (action.indexOf("filter.") == 0) 241 if (action.indexOf("filter.") == 0)
225 changes.push(action + " " + filter.text); 242 changes.push(action + " " + filter.text);
226 } 243 }
227 FilterNotifier.addListener(listener); 244 addListener(listener);
228 245
229 compareFiltersList(test, "Initial state", [[], [], []]); 246 compareFiltersList(test, "Initial state", [[], [], []]);
230 test.deepEqual(changes, [], "Received changes"); 247 test.deepEqual(changes, [], "Received changes");
231 248
232 changes = []; 249 changes = [];
233 FilterStorage.addFilter(Filter.fromText("foo")); 250 FilterStorage.addFilter(Filter.fromText("foo"));
234 compareFiltersList(test, "Adding blocking filter", [["foo"], [], []]); 251 compareFiltersList(test, "Adding blocking filter", [["foo"], [], []]);
235 test.deepEqual(changes, ["filter.added foo"], "Received changes"); 252 test.deepEqual(changes, ["filter.added foo"], "Received changes");
236 253
237 changes = []; 254 changes = [];
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 FilterStorage.addSubscription(subscription1); 310 FilterStorage.addSubscription(subscription1);
294 FilterStorage.addSubscription(subscription2); 311 FilterStorage.addSubscription(subscription2);
295 FilterStorage.addSubscription(subscription3); 312 FilterStorage.addSubscription(subscription3);
296 313
297 let changes = []; 314 let changes = [];
298 function listener(action, filter) 315 function listener(action, filter)
299 { 316 {
300 if (action.indexOf("filter.") == 0) 317 if (action.indexOf("filter.") == 0)
301 changes.push(action + " " + filter.text); 318 changes.push(action + " " + filter.text);
302 } 319 }
303 FilterNotifier.addListener(listener); 320 addListener(listener);
304 321
305 compareFiltersList(test, "Initial state", [["foo", "foo", "bar"], ["foo", "bar ", "foo"], ["foo", "bar"]]); 322 compareFiltersList(test, "Initial state", [["foo", "foo", "bar"], ["foo", "bar ", "foo"], ["foo", "bar"]]);
306 test.deepEqual(changes, [], "Received changes"); 323 test.deepEqual(changes, [], "Received changes");
307 324
308 changes = []; 325 changes = [];
309 FilterStorage.removeFilter(Filter.fromText("foo"), subscription2, 0); 326 FilterStorage.removeFilter(Filter.fromText("foo"), subscription2, 0);
310 compareFiltersList(test, "Remove with explicit subscription and position", [[" foo", "foo", "bar"], ["bar", "foo"], ["foo", "bar"]]); 327 compareFiltersList(test, "Remove with explicit subscription and position", [[" foo", "foo", "bar"], ["bar", "foo"], ["foo", "bar"]]);
311 test.deepEqual(changes, ["filter.removed foo"], "Received changes"); 328 test.deepEqual(changes, ["filter.removed foo"], "Received changes");
312 329
313 changes = []; 330 changes = [];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 365
349 FilterStorage.addSubscription(subscription1); 366 FilterStorage.addSubscription(subscription1);
350 FilterStorage.addSubscription(subscription2); 367 FilterStorage.addSubscription(subscription2);
351 368
352 let changes = []; 369 let changes = [];
353 function listener(action, filter) 370 function listener(action, filter)
354 { 371 {
355 if (action.indexOf("filter.") == 0) 372 if (action.indexOf("filter.") == 0)
356 changes.push(action + " " + filter.text); 373 changes.push(action + " " + filter.text);
357 } 374 }
358 FilterNotifier.addListener(listener); 375 addListener(listener);
359 376
360 compareFiltersList(test, "Initial state", [["foo", "bar", "bas", "foo"], ["foo ", "bar"]]); 377 compareFiltersList(test, "Initial state", [["foo", "bar", "bas", "foo"], ["foo ", "bar"]]);
361 test.deepEqual(changes, [], "Received changes"); 378 test.deepEqual(changes, [], "Received changes");
362 379
363 changes = []; 380 changes = [];
364 FilterStorage.moveFilter(Filter.fromText("foo"), subscription1, 0, 1); 381 FilterStorage.moveFilter(Filter.fromText("foo"), subscription1, 0, 1);
365 compareFiltersList(test, "Regular move", [["bar", "foo", "bas", "foo"], ["foo" , "bar"]]); 382 compareFiltersList(test, "Regular move", [["bar", "foo", "bas", "foo"], ["foo" , "bar"]]);
366 test.deepEqual(changes, ["filter.moved foo"], "Received changes"); 383 test.deepEqual(changes, ["filter.moved foo"], "Received changes");
367 384
368 changes = []; 385 changes = [];
(...skipping 20 matching lines...) Expand all
389 }; 406 };
390 407
391 exports.testHitCounts = function(test) 408 exports.testHitCounts = function(test)
392 { 409 {
393 let changes = []; 410 let changes = [];
394 function listener(action, filter) 411 function listener(action, filter)
395 { 412 {
396 if (action.indexOf("filter.") == 0) 413 if (action.indexOf("filter.") == 0)
397 changes.push(action + " " + filter.text); 414 changes.push(action + " " + filter.text);
398 } 415 }
399 FilterNotifier.addListener(listener); 416 addListener(listener);
400 417
401 let filter1 = Filter.fromText("filter1"); 418 let filter1 = Filter.fromText("filter1");
402 let filter2 = Filter.fromText("filter2"); 419 let filter2 = Filter.fromText("filter2");
403 420
404 FilterStorage.addFilter(filter1); 421 FilterStorage.addFilter(filter1);
405 422
406 test.equal(filter1.hitCount, 0, "filter1 initial hit count"); 423 test.equal(filter1.hitCount, 0, "filter1 initial hit count");
407 test.equal(filter2.hitCount, 0, "filter2 initial hit count"); 424 test.equal(filter2.hitCount, 0, "filter2 initial hit count");
408 test.equal(filter1.lastHit, 0, "filter1 initial last hit"); 425 test.equal(filter1.lastHit, 0, "filter1 initial last hit");
409 test.equal(filter2.lastHit, 0, "filter2 initial last hit"); 426 test.equal(filter2.lastHit, 0, "filter2 initial last hit");
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]); 508 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]);
492 509
493 FilterStorage.removeSubscription(subscription3); 510 FilterStorage.removeSubscription(subscription3);
494 511
495 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []); 512 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []);
496 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]); 513 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]);
497 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]); 514 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]);
498 515
499 test.done(); 516 test.done();
500 }; 517 };
OLDNEW
« test/filterNotifier.js ('K') | « test/filterNotifier.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld