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