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(["filterByKey", "exceptions", "filters"]); | 31 sandboxedRequire = createSandbox({ |
| 32 elemHide: ["filterByKey", "exceptions"], |
| 33 cssRules: ["filters"] |
| 34 }); |
32 | 35 |
33 // 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 |
34 // noticed, even though we don't directly use the module here. | 37 // noticed, even though we don't directly use the module here. |
35 sandboxedRequire("filterListener"); | 38 sandboxedRequire("../lib/filterListener"); |
36 | 39 |
37 FilterStorage = sandboxedRequire("filterStorage").FilterStorage; | 40 ( |
38 ({Subscription, SpecialSubscription} = sandboxedRequire("subscriptionClasses")
); | 41 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), |
39 Filter = sandboxedRequire("filterClasses").Filter; | 42 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), |
40 defaultMatcher = sandboxedRequire("matcher").defaultMatcher; | 43 {Filter} = sandboxedRequire("../lib/filterClasses"), |
| 44 {defaultMatcher} = sandboxedRequire("../lib/matcher") |
| 45 ); |
41 | 46 |
42 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); | 47 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); |
43 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); | 48 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); |
44 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); | 49 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); |
45 | 50 |
46 Subscription.fromURL("~fl~").defaults = ["blocking"]; | 51 Subscription.fromURL("~fl~").defaults = ["blocking"]; |
47 Subscription.fromURL("~wl~").defaults = ["whitelist"]; | 52 Subscription.fromURL("~wl~").defaults = ["whitelist"]; |
48 Subscription.fromURL("~eh~").defaults = ["elemhide"]; | 53 Subscription.fromURL("~eh~").defaults = ["elemhide"]; |
49 | 54 |
50 callback(); | 55 callback(); |
(...skipping 13 matching lines...) Expand all Loading... |
64 { | 69 { |
65 let filter = list[i]; | 70 let filter = list[i]; |
66 test.equal(matcher.getKeywordForFilter(filter), keyword, | 71 test.equal(matcher.getKeywordForFilter(filter), keyword, |
67 "Keyword of filter " + filter.text); | 72 "Keyword of filter " + filter.text); |
68 filters.push(filter.text); | 73 filters.push(filter.text); |
69 } | 74 } |
70 } | 75 } |
71 result[type] = filters; | 76 result[type] = filters; |
72 } | 77 } |
73 | 78 |
74 let elemHide = sandboxedRequire("elemHide"); | 79 let elemHide = sandboxedRequire("../lib/elemHide"); |
75 result.elemhide = []; | 80 result.elemhide = []; |
76 for (let key in elemHide.filterByKey) | 81 for (let key in elemHide.filterByKey) |
77 result.elemhide.push(elemHide.filterByKey[key].text); | 82 result.elemhide.push(elemHide.filterByKey[key].text); |
78 | 83 |
79 result.elemhideexception = []; | 84 result.elemhideexception = []; |
80 for (let selector in elemHide.exceptions) | 85 for (let selector in elemHide.exceptions) |
81 { | 86 { |
82 let list = elemHide.exceptions[selector]; | 87 let list = elemHide.exceptions[selector]; |
83 for (let exception of list) | 88 for (let exception of list) |
84 result.elemhideexception.push(exception.text); | 89 result.elemhideexception.push(exception.text); |
85 } | 90 } |
86 | 91 |
87 let cssRules = sandboxedRequire("cssRules"); | 92 let cssRules = sandboxedRequire("../lib/cssRules"); |
88 result.cssrule = []; | 93 result.cssrule = []; |
89 for (let filterText in cssRules.filters) | 94 for (let filterText in cssRules.filters) |
90 result.cssrule.push(filterText); | 95 result.cssrule.push(filterText); |
91 | 96 |
92 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", | 97 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", |
93 "cssrule"]; | 98 "cssrule"]; |
94 for (let type of types) | 99 for (let type of types) |
95 { | 100 { |
96 if (!(type in expected)) | 101 if (!(type in expected)) |
97 expected[type] = []; | 102 expected[type] = []; |
98 else | 103 else |
99 expected[type] = expected[type].sort(); | 104 expected[type].sort(); |
100 result[type] = result[type].sort(); | 105 result[type].sort(); |
101 } | 106 } |
102 | 107 |
103 test.deepEqual(result, expected, text); | 108 test.deepEqual(result, expected, text); |
104 } | 109 } |
105 | 110 |
106 exports.testAddingAndRemovingFilters = function(test) | 111 exports.testAddingAndRemovingFilters = function(test) |
107 { | 112 { |
108 let filter1 = Filter.fromText("filter1"); | 113 let filter1 = Filter.fromText("filter1"); |
109 let filter2 = Filter.fromText("@@filter2"); | 114 let filter2 = Filter.fromText("@@filter2"); |
110 let filter3 = Filter.fromText("#filter3"); | 115 let filter3 = Filter.fromText("#filter3"); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 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]}); |
314 | 319 |
315 FilterStorage.removeSubscription(subscription4); | 320 FilterStorage.removeSubscription(subscription4); |
316 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); | 321 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); |
317 | 322 |
318 subscription3.disabled = false; | 323 subscription3.disabled = false; |
319 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); | 324 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); |
320 | 325 |
321 test.done(); | 326 test.done(); |
322 }; | 327 }; |
LEFT | RIGHT |