OLD | NEW |
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; | |
29 | 28 |
30 exports.setUp = function(callback) | 29 exports.setUp = function(callback) |
31 { | 30 { |
32 sandboxedRequire = createSandbox({ | 31 sandboxedRequire = createSandbox({ |
33 extraExports: { | 32 extraExports: { |
34 elemHide: ["knownFilters"], | 33 elemHide: ["knownFilters"], |
35 elemHideEmulation: ["filters"], | 34 elemHideEmulation: ["filters"], |
| 35 elemHideExceptions: ["knownExceptions"], |
36 snippets: ["filters"] | 36 snippets: ["filters"] |
37 } | 37 } |
38 }); | 38 }); |
39 | 39 |
40 // We need to require the filterListener module so that filter changes will be | 40 // We need to require the filterListener module so that filter changes will be |
41 // noticed, even though we don't directly use the module here. | 41 // noticed, even though we don't directly use the module here. |
42 sandboxedRequire("../lib/filterListener"); | 42 sandboxedRequire("../lib/filterListener"); |
43 | 43 |
44 ( | 44 ( |
45 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), | 45 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), |
46 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), | 46 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), |
47 {Filter, ElemHideException} = sandboxedRequire("../lib/filterClasses"), | 47 {Filter} = sandboxedRequire("../lib/filterClasses"), |
48 {defaultMatcher} = sandboxedRequire("../lib/matcher") | 48 {defaultMatcher} = sandboxedRequire("../lib/matcher") |
49 ); | 49 ); |
50 | 50 |
51 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); | 51 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); |
52 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); | 52 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); |
53 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); | 53 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); |
54 | 54 |
55 Subscription.fromURL("~fl~").defaults = ["blocking"]; | 55 Subscription.fromURL("~fl~").defaults = ["blocking"]; |
56 Subscription.fromURL("~wl~").defaults = ["whitelist"]; | 56 Subscription.fromURL("~wl~").defaults = ["whitelist"]; |
57 Subscription.fromURL("~eh~").defaults = ["elemhide"]; | 57 Subscription.fromURL("~eh~").defaults = ["elemhide"]; |
(...skipping 16 matching lines...) Expand all Loading... |
74 test.equal(matcher.getKeywordForFilter(filter), keyword, | 74 test.equal(matcher.getKeywordForFilter(filter), keyword, |
75 "Keyword of filter " + filter.text); | 75 "Keyword of filter " + filter.text); |
76 filters.push(filter.text); | 76 filters.push(filter.text); |
77 } | 77 } |
78 } | 78 } |
79 result[type] = filters; | 79 result[type] = filters; |
80 } | 80 } |
81 | 81 |
82 let elemHide = sandboxedRequire("../lib/elemHide"); | 82 let elemHide = sandboxedRequire("../lib/elemHide"); |
83 result.elemhide = []; | 83 result.elemhide = []; |
| 84 for (let filter of elemHide.knownFilters) |
| 85 result.elemhide.push(filter.text); |
| 86 |
| 87 let elemHideExceptions = sandboxedRequire("../lib/elemHideExceptions"); |
84 result.elemhideexception = []; | 88 result.elemhideexception = []; |
85 for (let filter of elemHide.knownFilters) | 89 for (let exception of elemHideExceptions.knownExceptions) |
86 { | 90 result.elemhideexception.push(exception.text); |
87 if (filter instanceof ElemHideException) | |
88 result.elemhideexception.push(filter.text); | |
89 else | |
90 result.elemhide.push(filter.text); | |
91 } | |
92 | 91 |
93 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); | 92 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); |
94 result.elemhideemulation = []; | 93 result.elemhideemulation = []; |
95 for (let filterText of elemHideEmulation.filters) | 94 for (let filterText of elemHideEmulation.filters) |
96 result.elemhideemulation.push(filterText); | 95 result.elemhideemulation.push(filterText); |
97 | 96 |
98 let snippets = sandboxedRequire("../lib/snippets"); | 97 let snippets = sandboxedRequire("../lib/snippets"); |
99 result.snippets = []; | 98 result.snippets = []; |
100 for (let filterText of snippets.filters) | 99 for (let filterText of snippets.filters) |
101 result.snippets.push(filterText); | 100 result.snippets.push(filterText); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 checkKnownFilters(test, "add subscription of type circumvention with filter1",
{snippets: [filter1.text]}); | 350 checkKnownFilters(test, "add subscription of type circumvention with filter1",
{snippets: [filter1.text]}); |
352 | 351 |
353 let subscription3 = Subscription.fromURL("~foo"); | 352 let subscription3 = Subscription.fromURL("~foo"); |
354 subscription3.filters = [filter2]; | 353 subscription3.filters = [filter2]; |
355 | 354 |
356 FilterStorage.addSubscription(subscription3); | 355 FilterStorage.addSubscription(subscription3); |
357 checkKnownFilters(test, "add special subscription with filter2", {snippets: [f
ilter1.text, filter2.text]}); | 356 checkKnownFilters(test, "add special subscription with filter2", {snippets: [f
ilter1.text, filter2.text]}); |
358 | 357 |
359 test.done(); | 358 test.done(); |
360 }; | 359 }; |
OLD | NEW |