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

Side by Side Diff: test/filterListener.js

Issue 29757591: Issue 6562 - Remove filter keys from the element hiding code (Closed)
Patch Set: Avoid adding duplicate hiding filters Created April 26, 2018, noon
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/elemHide.js ('K') | « lib/elemHide.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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const {createSandbox} = require("./_common"); 20 const {createSandbox} = require("./_common");
21 let sandboxedRequire = null; 21 let sandboxedRequire = null;
22 22
23 let FilterStorage = null; 23 let FilterStorage = null;
24 let Subscription = null; 24 let Subscription = null;
25 let Filter = null; 25 let Filter = null;
26 let defaultMatcher = null; 26 let defaultMatcher = null;
27 let SpecialSubscription = null; 27 let SpecialSubscription = null;
28 let ElemHideException = null;
28 29
29 exports.setUp = function(callback) 30 exports.setUp = function(callback)
30 { 31 {
31 sandboxedRequire = createSandbox({ 32 sandboxedRequire = createSandbox({
32 extraExports: { 33 extraExports: {
33 elemHide: ["filterByKey", "exceptions"], 34 elemHide: ["knownFilters"],
34 elemHideEmulation: ["filters"] 35 elemHideEmulation: ["filters"]
35 } 36 }
36 }); 37 });
37 38
38 // We need to require the filterListener module so that filter changes will be 39 // We need to require the filterListener module so that filter changes will be
39 // noticed, even though we don't directly use the module here. 40 // noticed, even though we don't directly use the module here.
40 sandboxedRequire("../lib/filterListener"); 41 sandboxedRequire("../lib/filterListener");
41 42
42 ( 43 (
43 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), 44 {FilterStorage} = sandboxedRequire("../lib/filterStorage"),
44 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC lasses"), 45 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC lasses"),
45 {Filter} = sandboxedRequire("../lib/filterClasses"), 46 {Filter, ElemHideException} = sandboxedRequire("../lib/filterClasses"),
46 {defaultMatcher} = sandboxedRequire("../lib/matcher") 47 {defaultMatcher} = sandboxedRequire("../lib/matcher")
47 ); 48 );
48 49
49 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); 50 FilterStorage.addSubscription(Subscription.fromURL("~fl~"));
50 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); 51 FilterStorage.addSubscription(Subscription.fromURL("~wl~"));
51 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); 52 FilterStorage.addSubscription(Subscription.fromURL("~eh~"));
52 53
53 Subscription.fromURL("~fl~").defaults = ["blocking"]; 54 Subscription.fromURL("~fl~").defaults = ["blocking"];
54 Subscription.fromURL("~wl~").defaults = ["whitelist"]; 55 Subscription.fromURL("~wl~").defaults = ["whitelist"];
55 Subscription.fromURL("~eh~").defaults = ["elemhide"]; 56 Subscription.fromURL("~eh~").defaults = ["elemhide"];
(...skipping 16 matching lines...) Expand all
72 test.equal(matcher.getKeywordForFilter(filter), keyword, 73 test.equal(matcher.getKeywordForFilter(filter), keyword,
73 "Keyword of filter " + filter.text); 74 "Keyword of filter " + filter.text);
74 filters.push(filter.text); 75 filters.push(filter.text);
75 } 76 }
76 } 77 }
77 result[type] = filters; 78 result[type] = filters;
78 } 79 }
79 80
80 let elemHide = sandboxedRequire("../lib/elemHide"); 81 let elemHide = sandboxedRequire("../lib/elemHide");
81 result.elemhide = []; 82 result.elemhide = [];
82 for (let key in elemHide.filterByKey)
83 result.elemhide.push(elemHide.filterByKey[key].text);
84
85 result.elemhideexception = []; 83 result.elemhideexception = [];
86 for (let [, list] of elemHide.exceptions) 84 for (let filter of elemHide.knownFilters.values())
Manish Jethani 2018/04/27 12:39:36 Call .values is redundant here, but if you prefer
kzar 2018/04/30 10:11:46 Done.
87 { 85 {
88 for (let exception of list) 86 if (filter instanceof ElemHideException)
89 result.elemhideexception.push(exception.text); 87 result.elemhideexception.push(filter.text);
88 else
89 result.elemhide.push(filter.text);
90 } 90 }
91 91
92 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); 92 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation");
93 result.elemhideemulation = []; 93 result.elemhideemulation = [];
94 for (let filterText of elemHideEmulation.filters) 94 for (let filterText of elemHideEmulation.filters)
95 result.elemhideemulation.push(filterText); 95 result.elemhideemulation.push(filterText);
96 96
97 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", 97 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception",
98 "elemhideemulation"]; 98 "elemhideemulation"];
99 for (let type of types) 99 for (let type of types)
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text, filter3.text], whitelist: [filter2.text]}); 318 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text, filter3.text], whitelist: [filter2.text]});
319 319
320 FilterStorage.removeSubscription(subscription4); 320 FilterStorage.removeSubscription(subscription4);
321 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt er1.text]}); 321 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt er1.text]});
322 322
323 subscription3.disabled = false; 323 subscription3.disabled = false;
324 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text], whitelist: [filter2.text]}); 324 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text], whitelist: [filter2.text]});
325 325
326 test.done(); 326 test.done();
327 }; 327 };
OLDNEW
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld