LEFT | RIGHT |
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: ["filtersByDomain", "filterBySelector", "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 Loading... |
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 filters of elemHide.filtersByDomain.values()) | 83 result.elemhideexception = []; |
| 84 for (let filter of elemHide.knownFilters) |
83 { | 85 { |
84 for (let filter of filters.keys()) | 86 if (filter instanceof ElemHideException) |
| 87 result.elemhideexception.push(filter.text); |
| 88 else |
85 result.elemhide.push(filter.text); | 89 result.elemhide.push(filter.text); |
86 } | |
87 for (let filter of elemHide.filterBySelector.values()) | |
88 result.elemhide.push(filter.text); | |
89 | |
90 result.elemhideexception = []; | |
91 for (let [, list] of elemHide.exceptions) | |
92 { | |
93 for (let exception of list) | |
94 result.elemhideexception.push(exception.text); | |
95 } | 90 } |
96 | 91 |
97 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); | 92 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); |
98 result.elemhideemulation = []; | 93 result.elemhideemulation = []; |
99 for (let filterText of elemHideEmulation.filters) | 94 for (let filterText of elemHideEmulation.filters) |
100 result.elemhideemulation.push(filterText); | 95 result.elemhideemulation.push(filterText); |
101 | 96 |
102 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", | 97 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", |
103 "elemhideemulation"]; | 98 "elemhideemulation"]; |
104 for (let type of types) | 99 for (let type of types) |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 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]}); |
324 | 319 |
325 FilterStorage.removeSubscription(subscription4); | 320 FilterStorage.removeSubscription(subscription4); |
326 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); | 321 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); |
327 | 322 |
328 subscription3.disabled = false; | 323 subscription3.disabled = false; |
329 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); | 324 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); |
330 | 325 |
331 test.done(); | 326 test.done(); |
332 }; | 327 }; |
LEFT | RIGHT |