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

Side by Side Diff: test/filterStorage.js

Issue 29886685: Issue 6856 - Remove FilterStorage.moveSubscription (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Address PS4 Comment Created Oct. 1, 2018, 2:31 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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 28 matching lines...) Expand all
39 callback(); 39 callback();
40 }; 40 };
41 41
42 function addListener(listener) 42 function addListener(listener)
43 { 43 {
44 let makeWrapper = name => (...args) => listener(name, ...args); 44 let makeWrapper = name => (...args) => listener(name, ...args);
45 45
46 filterNotifier.on("subscription.added", makeWrapper("subscription.added")); 46 filterNotifier.on("subscription.added", makeWrapper("subscription.added"));
47 filterNotifier.on("subscription.removed", 47 filterNotifier.on("subscription.removed",
48 makeWrapper("subscription.removed")); 48 makeWrapper("subscription.removed"));
49 filterNotifier.on("subscription.moved", makeWrapper("subscription.moved"));
50 49
51 filterNotifier.on("filter.added", makeWrapper("filter.added")); 50 filterNotifier.on("filter.added", makeWrapper("filter.added"));
52 filterNotifier.on("filter.removed", makeWrapper("filter.removed")); 51 filterNotifier.on("filter.removed", makeWrapper("filter.removed"));
53 filterNotifier.on("filter.moved", makeWrapper("filter.moved")); 52 filterNotifier.on("filter.moved", makeWrapper("filter.moved"));
54 53
55 filterNotifier.on("filter.hitCount", makeWrapper("filter.hitCount")); 54 filterNotifier.on("filter.hitCount", makeWrapper("filter.hitCount"));
56 filterNotifier.on("filter.lastHit", makeWrapper("filter.lastHit")); 55 filterNotifier.on("filter.lastHit", makeWrapper("filter.lastHit"));
57 } 56 }
58 57
59 function compareSubscriptionList(test, testMessage, list, 58 function compareSubscriptionList(test, testMessage, list,
60 knownSubscriptions = null) 59 knownSubscriptions = null)
61 { 60 {
62 let result = FilterStorage.subscriptions.map(subscription => subscription.url) ; 61 let result = [...FilterStorage.knownSubscriptions.keys()];
63 let expected = list.map(subscription => subscription.url); 62 let expected = list.map(subscription => subscription.url);
64 test.deepEqual(result, expected, testMessage); 63 test.deepEqual(result, expected, testMessage);
65 64
66 if (knownSubscriptions) 65 if (knownSubscriptions)
67 { 66 {
68 test.deepEqual([...Subscription.knownSubscriptions.values()], 67 test.deepEqual([...Subscription.knownSubscriptions.values()],
69 knownSubscriptions, testMessage); 68 knownSubscriptions, testMessage);
70 } 69 }
71 } 70 }
72 71
73 function compareFiltersList(test, testMessage, list) 72 function compareFiltersList(test, testMessage, list)
74 { 73 {
75 let result = FilterStorage.subscriptions.map( 74 let result = [...FilterStorage.subscriptions()].map(
76 subscription => subscription.filters.map( 75 subscription => subscription.filters.map(
77 filter => filter.text)); 76 filter => filter.text));
78 test.deepEqual(result, list, testMessage); 77 test.deepEqual(result, list, testMessage);
79 } 78 }
80 79
81 function compareFilterSubscriptions(test, testMessage, filter, list) 80 function compareFilterSubscriptions(test, testMessage, filter, list)
82 { 81 {
83 let result = [...filter.subscriptions()].map(subscription => subscription.url) ; 82 let result = [...filter.subscriptions()].map(subscription => subscription.url) ;
84 let expected = list.map(subscription => subscription.url); 83 let expected = list.map(subscription => subscription.url);
85 test.deepEqual(result, expected, testMessage); 84 test.deepEqual(result, expected, testMessage);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 function listener(action, subscription) 200 function listener(action, subscription)
202 { 201 {
203 if (action.indexOf("subscription.") == 0) 202 if (action.indexOf("subscription.") == 0)
204 changes.push(action + " " + subscription.url); 203 changes.push(action + " " + subscription.url);
205 } 204 }
206 addListener(listener); 205 addListener(listener);
207 206
208 compareSubscriptionList(test, "Initial state", [subscription1, subscription2, subscription3]); 207 compareSubscriptionList(test, "Initial state", [subscription1, subscription2, subscription3]);
209 test.deepEqual(changes, [], "Received changes"); 208 test.deepEqual(changes, [], "Received changes");
210 209
211 changes = [];
212 FilterStorage.moveSubscription(subscription1);
213 compareSubscriptionList(test, "Move without explicit position", [subscription2 , subscription3, subscription1]);
214 test.deepEqual(changes, ["subscription.moved http://test1/"], "Received change s");
215
216 changes = [];
217 FilterStorage.moveSubscription(subscription1);
218 compareSubscriptionList(test, "Move without explicit position (subscription al ready last)", [subscription2, subscription3, subscription1]);
219 test.deepEqual(changes, [], "Received changes");
220
221 changes = [];
222 FilterStorage.moveSubscription(subscription2, subscription1);
223 compareSubscriptionList(test, "Move with explicit position", [subscription3, s ubscription2, subscription1]);
224 test.deepEqual(changes, ["subscription.moved http://test2/"], "Received change s");
225
226 changes = [];
227 FilterStorage.moveSubscription(subscription3, subscription2);
228 compareSubscriptionList(test, "Move without explicit position (subscription al ready at position)", [subscription3, subscription2, subscription1]);
229 test.deepEqual(changes, [], "Received changes");
230
231 FilterStorage.removeSubscription(subscription2); 210 FilterStorage.removeSubscription(subscription2);
232 compareSubscriptionList(test, "Remove", [subscription3, subscription1]); 211 compareSubscriptionList(test, "Remove", [subscription1, subscription3]);
233
234 changes = [];
235 FilterStorage.moveSubscription(subscription3, subscription2);
236 compareSubscriptionList(test, "Move before removed subscription", [subscriptio n1, subscription3]);
237 test.deepEqual(changes, ["subscription.moved http://test3/"], "Received change s");
238
239 changes = [];
240 FilterStorage.moveSubscription(subscription2);
241 compareSubscriptionList(test, "Move of removed subscription", [subscription1, subscription3]);
242 test.deepEqual(changes, [], "Received changes");
243 212
244 test.done(); 213 test.done();
245 }; 214 };
246 215
247 exports.testAddingFilters = function(test) 216 exports.testAddingFilters = function(test)
248 { 217 {
249 let subscription1 = Subscription.fromURL("~blocking"); 218 let subscription1 = Subscription.fromURL("~blocking");
250 subscription1.defaults = ["blocking"]; 219 subscription1.defaults = ["blocking"];
251 220
252 let subscription2 = Subscription.fromURL("~exceptions"); 221 let subscription2 = Subscription.fromURL("~exceptions");
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]); 500 compareFilterSubscriptions(test, "filter3 subscriptions after updating http:// test3/ filters", filter3, [subscription2]);
532 501
533 FilterStorage.removeSubscription(subscription3); 502 FilterStorage.removeSubscription(subscription3);
534 503
535 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []); 504 compareFilterSubscriptions(test, "filter1 subscriptions after removing http:// test3/", filter1, []);
536 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]); 505 compareFilterSubscriptions(test, "filter2 subscriptions after removing http:// test3/", filter2, [subscription2]);
537 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]); 506 compareFilterSubscriptions(test, "filter3 subscriptions after removing http:// test3/", filter3, [subscription2]);
538 507
539 test.done(); 508 test.done();
540 }; 509 };
OLDNEW
« lib/filterStorage.js ('K') | « lib/synchronizer.js ('k') | test/filterStorage_readwrite.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld