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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 let {createSandbox} = require("common"); | 20 let {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 | 28 |
29 exports.setUp = function(callback) | 29 exports.setUp = function(callback) |
30 { | 30 { |
31 sandboxedRequire = createSandbox({ | 31 sandboxedRequire = createSandbox({ |
32 elemHide: ["filterByKey", "exceptions"], | 32 elemHide: ["filterByKey", "exceptions"], |
33 cssRules: ["filters"] | 33 cssRules: ["filters"] |
34 }); | 34 }); |
35 | 35 |
36 // We need to require the filterListener module so that filter changes will be | 36 // We need to require the filterListener module so that filter changes will be |
37 // noticed, even though we don't directly use the module here. | 37 // noticed, even though we don't directly use the module here. |
38 sandboxedRequire("filterListener"); | 38 sandboxedRequire("../lib/filterListener"); |
39 | 39 |
40 ( | 40 ( |
41 {FilterStorage} = sandboxedRequire("filterStorage"), | 41 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), |
42 {Subscription, SpecialSubscription} = sandboxedRequire("subscriptionClasses"
), | 42 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), |
43 {Filter} = sandboxedRequire("filterClasses"), | 43 {Filter} = sandboxedRequire("../lib/filterClasses"), |
44 {defaultMatcher} = sandboxedRequire("matcher") | 44 {defaultMatcher} = sandboxedRequire("../lib/matcher") |
45 ); | 45 ); |
46 | 46 |
47 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); | 47 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); |
48 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); | 48 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); |
49 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); | 49 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); |
50 | 50 |
51 Subscription.fromURL("~fl~").defaults = ["blocking"]; | 51 Subscription.fromURL("~fl~").defaults = ["blocking"]; |
52 Subscription.fromURL("~wl~").defaults = ["whitelist"]; | 52 Subscription.fromURL("~wl~").defaults = ["whitelist"]; |
53 Subscription.fromURL("~eh~").defaults = ["elemhide"]; | 53 Subscription.fromURL("~eh~").defaults = ["elemhide"]; |
54 | 54 |
(...skipping 14 matching lines...) Expand all Loading... |
69 { | 69 { |
70 let filter = list[i]; | 70 let filter = list[i]; |
71 test.equal(matcher.getKeywordForFilter(filter), keyword, | 71 test.equal(matcher.getKeywordForFilter(filter), keyword, |
72 "Keyword of filter " + filter.text); | 72 "Keyword of filter " + filter.text); |
73 filters.push(filter.text); | 73 filters.push(filter.text); |
74 } | 74 } |
75 } | 75 } |
76 result[type] = filters; | 76 result[type] = filters; |
77 } | 77 } |
78 | 78 |
79 let elemHide = sandboxedRequire("elemHide"); | 79 let elemHide = sandboxedRequire("../lib/elemHide"); |
80 result.elemhide = []; | 80 result.elemhide = []; |
81 for (let key in elemHide.filterByKey) | 81 for (let key in elemHide.filterByKey) |
82 result.elemhide.push(elemHide.filterByKey[key].text); | 82 result.elemhide.push(elemHide.filterByKey[key].text); |
83 | 83 |
84 result.elemhideexception = []; | 84 result.elemhideexception = []; |
85 for (let selector in elemHide.exceptions) | 85 for (let selector in elemHide.exceptions) |
86 { | 86 { |
87 let list = elemHide.exceptions[selector]; | 87 let list = elemHide.exceptions[selector]; |
88 for (let exception of list) | 88 for (let exception of list) |
89 result.elemhideexception.push(exception.text); | 89 result.elemhideexception.push(exception.text); |
90 } | 90 } |
91 | 91 |
92 let cssRules = sandboxedRequire("cssRules"); | 92 let cssRules = sandboxedRequire("../lib/cssRules"); |
93 result.cssrule = []; | 93 result.cssrule = []; |
94 for (let filterText in cssRules.filters) | 94 for (let filterText in cssRules.filters) |
95 result.cssrule.push(filterText); | 95 result.cssrule.push(filterText); |
96 | 96 |
97 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", | 97 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", |
98 "cssrule"]; | 98 "cssrule"]; |
99 for (let type of types) | 99 for (let type of types) |
100 { | 100 { |
101 if (!(type in expected)) | 101 if (!(type in expected)) |
102 expected[type] = []; | 102 expected[type] = []; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 }; |
LEFT | RIGHT |