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; | |
29 | 28 |
30 exports.setUp = function(callback) | 29 exports.setUp = function(callback) |
31 { | 30 { |
32 sandboxedRequire = createSandbox(); | 31 sandboxedRequire = createSandbox({ |
| 32 extraExports: { |
| 33 elemHideExceptions: ["knownExceptions"], |
| 34 snippets: ["filters"] |
| 35 } |
| 36 }); |
33 | 37 |
34 // We need to require the filterListener module so that filter changes will be | 38 // We need to require the filterListener module so that filter changes will be |
35 // noticed, even though we don't directly use the module here. | 39 // noticed, even though we don't directly use the module here. |
36 sandboxedRequire("../lib/filterListener"); | 40 sandboxedRequire("../lib/filterListener"); |
37 | 41 |
38 ( | 42 ( |
39 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), | 43 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), |
40 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), | 44 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), |
41 {Filter, ElemHideException} = sandboxedRequire("../lib/filterClasses"), | 45 {Filter} = sandboxedRequire("../lib/filterClasses"), |
42 {defaultMatcher} = sandboxedRequire("../lib/matcher") | 46 {defaultMatcher} = sandboxedRequire("../lib/matcher") |
43 ); | 47 ); |
44 | 48 |
45 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); | 49 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); |
46 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); | 50 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); |
47 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); | 51 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); |
48 | 52 |
49 Subscription.fromURL("~fl~").defaults = ["blocking"]; | 53 Subscription.fromURL("~fl~").defaults = ["blocking"]; |
50 Subscription.fromURL("~wl~").defaults = ["whitelist"]; | 54 Subscription.fromURL("~wl~").defaults = ["whitelist"]; |
51 Subscription.fromURL("~eh~").defaults = ["elemhide"]; | 55 Subscription.fromURL("~eh~").defaults = ["elemhide"]; |
(...skipping 16 matching lines...) Expand all Loading... |
68 test.equal(matcher.getKeywordForFilter(filter), keyword, | 72 test.equal(matcher.getKeywordForFilter(filter), keyword, |
69 "Keyword of filter " + filter.text); | 73 "Keyword of filter " + filter.text); |
70 filters.push(filter.text); | 74 filters.push(filter.text); |
71 } | 75 } |
72 } | 76 } |
73 result[type] = filters; | 77 result[type] = filters; |
74 } | 78 } |
75 | 79 |
76 let elemHide = sandboxedRequire("../lib/elemHide"); | 80 let elemHide = sandboxedRequire("../lib/elemHide"); |
77 result.elemhide = []; | 81 result.elemhide = []; |
| 82 for (let filter of elemHide.ElemHide._knownFilters) |
| 83 result.elemhide.push(filter.text); |
| 84 |
| 85 let elemHideExceptions = sandboxedRequire("../lib/elemHideExceptions"); |
78 result.elemhideexception = []; | 86 result.elemhideexception = []; |
79 for (let filter of elemHide.ElemHide._knownFilters) | 87 for (let exception of elemHideExceptions.knownExceptions) |
80 { | 88 result.elemhideexception.push(exception.text); |
81 if (filter instanceof ElemHideException) | |
82 result.elemhideexception.push(filter.text); | |
83 else | |
84 result.elemhide.push(filter.text); | |
85 } | |
86 | 89 |
87 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); | 90 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); |
88 result.elemhideemulation = []; | 91 result.elemhideemulation = []; |
89 for (let filter of elemHideEmulation.ElemHideEmulation._knownFilters) | 92 for (let filter of elemHideEmulation.ElemHideEmulation._knownFilters) |
90 result.elemhideemulation.push(filter.text); | 93 result.elemhideemulation.push(filter.text); |
91 | 94 |
| 95 let snippets = sandboxedRequire("../lib/snippets"); |
| 96 result.snippets = []; |
| 97 for (let filterText of snippets.filters) |
| 98 result.snippets.push(filterText); |
| 99 |
92 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", | 100 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", |
93 "elemhideemulation"]; | 101 "elemhideemulation", "snippets"]; |
94 for (let type of types) | 102 for (let type of types) |
95 { | 103 { |
96 if (!(type in expected)) | 104 if (!(type in expected)) |
97 expected[type] = []; | 105 expected[type] = []; |
98 else | 106 else |
99 expected[type].sort(); | 107 expected[type].sort(); |
100 result[type].sort(); | 108 result[type].sort(); |
101 } | 109 } |
102 | 110 |
103 test.deepEqual(result, expected, text); | 111 test.deepEqual(result, expected, text); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 287 |
280 subscription2.disabled = false; | 288 subscription2.disabled = false; |
281 checkKnownFilters(test, "enable blocking filters", {blacklist: [filter1.text]}
); | 289 checkKnownFilters(test, "enable blocking filters", {blacklist: [filter1.text]}
); |
282 | 290 |
283 let subscription3 = Subscription.fromURL("~wl~"); | 291 let subscription3 = Subscription.fromURL("~wl~"); |
284 subscription3.disabled = true; | 292 subscription3.disabled = true; |
285 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text]}
); | 293 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text]}
); |
286 | 294 |
287 FilterStorage.addFilter(filter2); | 295 FilterStorage.addFilter(filter2); |
288 checkKnownFilters(test, "add @@filter2", {blacklist: [filter1.text], whitelist
: [filter2.text]}); | 296 checkKnownFilters(test, "add @@filter2", {blacklist: [filter1.text], whitelist
: [filter2.text]}); |
289 test.equal(filter2.subscriptions.length, 1, "@@filter2.subscription.length"); | 297 test.equal(filter2.subscriptions.size, 1, "@@filter2.subscription.length"); |
290 test.ok(filter2.subscriptions[0] instanceof SpecialSubscription, "@@filter2 ad
ded to a new filter group"); | 298 test.ok([...filter2.subscriptions][0] instanceof SpecialSubscription, "@@filte
r2 added to a new filter group"); |
291 test.ok(filter2.subscriptions[0] != subscription3, "@@filter2 filter group is
not the disabled exceptions group"); | 299 test.ok([...filter2.subscriptions][0] != subscription3, "@@filter2 filter grou
p is not the disabled exceptions group"); |
292 | 300 |
293 subscription3.disabled = false; | 301 subscription3.disabled = false; |
294 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); | 302 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); |
295 | 303 |
296 FilterStorage.removeFilter(filter2); | 304 FilterStorage.removeFilter(filter2); |
297 FilterStorage.addFilter(filter2); | 305 FilterStorage.addFilter(filter2); |
298 checkKnownFilters(test, "re-add @@filter2", {blacklist: [filter1.text], whitel
ist: [filter2.text]}); | 306 checkKnownFilters(test, "re-add @@filter2", {blacklist: [filter1.text], whitel
ist: [filter2.text]}); |
299 test.equal(filter2.subscriptions.length, 1, "@@filter2.subscription.length"); | 307 test.equal(filter2.subscriptions.size, 1, "@@filter2.subscription.length"); |
300 test.ok(filter2.subscriptions[0] == subscription3, "@@filter2 added to the def
ault exceptions group"); | 308 test.ok([...filter2.subscriptions][0] == subscription3, "@@filter2 added to th
e default exceptions group"); |
301 | 309 |
302 let subscription4 = Subscription.fromURL("http://test/"); | 310 let subscription4 = Subscription.fromURL("http://test/"); |
303 FilterStorage.updateSubscriptionFilters(subscription4, [filter3, filter4, filt
er5]); | 311 FilterStorage.updateSubscriptionFilters(subscription4, [filter3, filter4, filt
er5]); |
304 checkKnownFilters(test, "update subscription not in the list yet", {blacklist:
[filter1.text], whitelist: [filter2.text]}); | 312 checkKnownFilters(test, "update subscription not in the list yet", {blacklist:
[filter1.text], whitelist: [filter2.text]}); |
305 | 313 |
306 FilterStorage.addSubscription(subscription4); | 314 FilterStorage.addSubscription(subscription4); |
307 checkKnownFilters(test, "add subscription to the list", {blacklist: [filter1.t
ext, filter3.text], whitelist: [filter2.text, filter4.text]}); | 315 checkKnownFilters(test, "add subscription to the list", {blacklist: [filter1.t
ext, filter3.text], whitelist: [filter2.text, filter4.text]}); |
308 | 316 |
309 FilterStorage.updateSubscriptionFilters(subscription4, [filter3, filter2, filt
er5]); | 317 FilterStorage.updateSubscriptionFilters(subscription4, [filter3, filter2, filt
er5]); |
310 checkKnownFilters(test, "update subscription while in the list", {blacklist: [
filter1.text, filter3.text], whitelist: [filter2.text]}); | 318 checkKnownFilters(test, "update subscription while in the list", {blacklist: [
filter1.text, filter3.text], whitelist: [filter2.text]}); |
311 | 319 |
312 subscription3.disabled = true; | 320 subscription3.disabled = true; |
313 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text,
filter3.text], whitelist: [filter2.text]}); | 321 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text,
filter3.text], whitelist: [filter2.text]}); |
314 | 322 |
315 FilterStorage.removeSubscription(subscription4); | 323 FilterStorage.removeSubscription(subscription4); |
316 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); | 324 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); |
317 | 325 |
318 subscription3.disabled = false; | 326 subscription3.disabled = false; |
319 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); | 327 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); |
320 | 328 |
321 test.done(); | 329 test.done(); |
322 }; | 330 }; |
| 331 |
| 332 exports.testSnippetFilters = function(test) |
| 333 { |
| 334 let filter1 = Filter.fromText("example.com#$#filter1"); |
| 335 let filter2 = Filter.fromText("example.com#$#filter2"); |
| 336 |
| 337 let subscription1 = Subscription.fromURL("http://test1/"); |
| 338 subscription1.filters = [filter1, filter2]; |
| 339 |
| 340 FilterStorage.addSubscription(subscription1); |
| 341 checkKnownFilters(test, "add subscription with filter1 and filter2", {}); |
| 342 |
| 343 let subscription2 = Subscription.fromURL("http://test2/"); |
| 344 subscription2.type = "circumvention"; |
| 345 subscription2.filters = [filter1]; |
| 346 |
| 347 FilterStorage.addSubscription(subscription2); |
| 348 checkKnownFilters(test, "add subscription of type circumvention with filter1",
{snippets: [filter1.text]}); |
| 349 |
| 350 let subscription3 = Subscription.fromURL("~foo"); |
| 351 subscription3.filters = [filter2]; |
| 352 |
| 353 FilterStorage.addSubscription(subscription3); |
| 354 checkKnownFilters(test, "add special subscription with filter2", {snippets: [f
ilter1.text, filter2.text]}); |
| 355 |
| 356 test.done(); |
| 357 }; |
LEFT | RIGHT |