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 |
(...skipping 14 matching lines...) Expand all Loading... |
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 extraExports: { | 32 extraExports: { |
33 elemHide: ["knownFilterText"], | 33 elemHide: ["knownFilterText"], |
34 elemHideEmulation: ["filters"], | 34 elemHideEmulation: ["filters"], |
35 elemHideExceptions: ["knownExceptions"], | 35 elemHideExceptions: ["knownExceptions"] |
36 snippets: ["filters"] | |
37 } | 36 } |
38 }); | 37 }); |
39 | 38 |
40 // We need to require the filterListener module so that filter changes will be | 39 // 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. | 40 // noticed, even though we don't directly use the module here. |
42 sandboxedRequire("../lib/filterListener"); | 41 sandboxedRequire("../lib/filterListener"); |
43 | 42 |
44 ( | 43 ( |
45 {filterStorage} = sandboxedRequire("../lib/filterStorage"), | 44 {filterStorage} = sandboxedRequire("../lib/filterStorage"), |
46 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), | 45 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 let elemHideExceptions = sandboxedRequire("../lib/elemHideExceptions"); | 89 let elemHideExceptions = sandboxedRequire("../lib/elemHideExceptions"); |
91 result.elemhideexception = []; | 90 result.elemhideexception = []; |
92 for (let exception of elemHideExceptions.knownExceptions) | 91 for (let exception of elemHideExceptions.knownExceptions) |
93 result.elemhideexception.push(exception.text); | 92 result.elemhideexception.push(exception.text); |
94 | 93 |
95 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); | 94 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); |
96 result.elemhideemulation = []; | 95 result.elemhideemulation = []; |
97 for (let filter of elemHideEmulation.filters) | 96 for (let filter of elemHideEmulation.filters) |
98 result.elemhideemulation.push(filter.text); | 97 result.elemhideemulation.push(filter.text); |
99 | 98 |
100 let snippets = sandboxedRequire("../lib/snippets"); | 99 let {snippets} = sandboxedRequire("../lib/snippets"); |
101 result.snippets = []; | 100 result.snippets = []; |
102 for (let filter of snippets.filters) | 101 for (let filter of snippets._filters) |
103 result.snippets.push(filter.text); | 102 result.snippets.push(filter.text); |
104 | 103 |
105 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", | 104 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", |
106 "elemhideemulation", "snippets"]; | 105 "elemhideemulation", "snippets"]; |
107 for (let type of types) | 106 for (let type of types) |
108 { | 107 { |
109 if (!(type in expected)) | 108 if (!(type in expected)) |
110 expected[type] = []; | 109 expected[type] = []; |
111 else | 110 else |
112 expected[type].sort(); | 111 expected[type].sort(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 216 |
218 filterStorage.addSubscription(subscription); | 217 filterStorage.addSubscription(subscription); |
219 checkKnownFilters(test, "add subscription with filter1, @@filter2, ##filter3,
!filter4, #@#filter5, example.com#?#:-abp-properties(filter6), example.com#@#[-a
bp-properties='filter7']", {blacklist: [filter1.text], elemhide: [filter3.text],
elemhideexception: [filter5.text, filter7.text], elemhideemulation: [filter6.te
xt]}); | 218 checkKnownFilters(test, "add subscription with filter1, @@filter2, ##filter3,
!filter4, #@#filter5, example.com#?#:-abp-properties(filter6), example.com#@#[-a
bp-properties='filter7']", {blacklist: [filter1.text], elemhide: [filter3.text],
elemhideexception: [filter5.text, filter7.text], elemhideemulation: [filter6.te
xt]}); |
220 | 219 |
221 filter2.disabled = false; | 220 filter2.disabled = false; |
222 checkKnownFilters(test, "enable @@filter2", {blacklist: [filter1.text], whitel
ist: [filter2.text], elemhide: [filter3.text], elemhideexception: [filter5.text,
filter7.text], elemhideemulation: [filter6.text]}); | 221 checkKnownFilters(test, "enable @@filter2", {blacklist: [filter1.text], whitel
ist: [filter2.text], elemhide: [filter3.text], elemhideexception: [filter5.text,
filter7.text], elemhideemulation: [filter6.text]}); |
223 | 222 |
224 filterStorage.addFilter(filter1); | 223 filterStorage.addFilter(filter1); |
225 checkKnownFilters(test, "add filter1", {blacklist: [filter1.text], whitelist:
[filter2.text], elemhide: [filter3.text], elemhideexception: [filter5.text, filt
er7.text], elemhideemulation: [filter6.text]}); | 224 checkKnownFilters(test, "add filter1", {blacklist: [filter1.text], whitelist:
[filter2.text], elemhide: [filter3.text], elemhideexception: [filter5.text, filt
er7.text], elemhideemulation: [filter6.text]}); |
226 | 225 |
227 filterStorage.updateSubscriptionFilters(subscription, [filter4]); | 226 filterStorage.updateSubscriptionFilters(subscription, [filter4.text]); |
228 checkKnownFilters(test, "change subscription filters to filter4", {blacklist:
[filter1.text]}); | 227 checkKnownFilters(test, "change subscription filters to filter4", {blacklist:
[filter1.text]}); |
229 | 228 |
230 filterStorage.removeFilter(filter1); | 229 filterStorage.removeFilter(filter1); |
231 checkKnownFilters(test, "remove filter1", {}); | 230 checkKnownFilters(test, "remove filter1", {}); |
232 | 231 |
233 filterStorage.updateSubscriptionFilters(subscription, [filter1, filter2]); | 232 filterStorage.updateSubscriptionFilters(subscription, [filter1.text, filter2.t
ext]); |
234 checkKnownFilters(test, "change subscription filters to filter1, filter2", {bl
acklist: [filter1.text], whitelist: [filter2.text]}); | 233 checkKnownFilters(test, "change subscription filters to filter1, filter2", {bl
acklist: [filter1.text], whitelist: [filter2.text]}); |
235 | 234 |
236 filter1.disabled = true; | 235 filter1.disabled = true; |
237 checkKnownFilters(test, "disable filter1", {whitelist: [filter2.text]}); | 236 checkKnownFilters(test, "disable filter1", {whitelist: [filter2.text]}); |
238 filter2.disabled = true; | 237 filter2.disabled = true; |
239 checkKnownFilters(test, "disable filter2", {}); | 238 checkKnownFilters(test, "disable filter2", {}); |
240 filter1.disabled = false; | 239 filter1.disabled = false; |
241 filter2.disabled = false; | 240 filter2.disabled = false; |
242 checkKnownFilters(test, "enable filter1, filter2", {blacklist: [filter1.text],
whitelist: [filter2.text]}); | 241 checkKnownFilters(test, "enable filter1, filter2", {blacklist: [filter1.text],
whitelist: [filter2.text]}); |
243 | 242 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 298 |
300 subscription2.disabled = false; | 299 subscription2.disabled = false; |
301 checkKnownFilters(test, "enable blocking filters", {blacklist: [filter1.text]}
); | 300 checkKnownFilters(test, "enable blocking filters", {blacklist: [filter1.text]}
); |
302 | 301 |
303 let subscription3 = Subscription.fromURL("~wl~"); | 302 let subscription3 = Subscription.fromURL("~wl~"); |
304 subscription3.disabled = true; | 303 subscription3.disabled = true; |
305 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text]}
); | 304 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text]}
); |
306 | 305 |
307 filterStorage.addFilter(filter2); | 306 filterStorage.addFilter(filter2); |
308 checkKnownFilters(test, "add @@filter2", {blacklist: [filter1.text], whitelist
: [filter2.text]}); | 307 checkKnownFilters(test, "add @@filter2", {blacklist: [filter1.text], whitelist
: [filter2.text]}); |
309 test.equal(filter2.subscriptionCount, 1, "@@filter2.subscriptionCount"); | 308 test.equal([...filterStorage.subscriptions(filter2.text)].length, 1, "@@filter
2 subscription count"); |
310 test.ok([...filter2.subscriptions()][0] instanceof SpecialSubscription, "@@fil
ter2 added to a new filter group"); | 309 test.ok([...filterStorage.subscriptions(filter2.text)][0] instanceof SpecialSu
bscription, "@@filter2 added to a new filter group"); |
311 test.ok([...filter2.subscriptions()][0] != subscription3, "@@filter2 filter gr
oup is not the disabled exceptions group"); | 310 test.ok([...filterStorage.subscriptions(filter2.text)][0] != subscription3, "@
@filter2 filter group is not the disabled exceptions group"); |
312 | 311 |
313 subscription3.disabled = false; | 312 subscription3.disabled = false; |
314 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); | 313 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); |
315 | 314 |
316 filterStorage.removeFilter(filter2); | 315 filterStorage.removeFilter(filter2); |
317 filterStorage.addFilter(filter2); | 316 filterStorage.addFilter(filter2); |
318 checkKnownFilters(test, "re-add @@filter2", {blacklist: [filter1.text], whitel
ist: [filter2.text]}); | 317 checkKnownFilters(test, "re-add @@filter2", {blacklist: [filter1.text], whitel
ist: [filter2.text]}); |
319 test.equal(filter2.subscriptionCount, 1, "@@filter2.subscriptionCount"); | 318 test.equal([...filterStorage.subscriptions(filter2.text)].length, 1, "@@filter
2 subscription count"); |
320 test.ok([...filter2.subscriptions()][0] == subscription3, "@@filter2 added to
the default exceptions group"); | 319 test.ok([...filterStorage.subscriptions(filter2.text)][0] == subscription3, "@
@filter2 added to the default exceptions group"); |
321 | 320 |
322 let subscription4 = Subscription.fromURL("http://test/"); | 321 let subscription4 = Subscription.fromURL("http://test/"); |
323 filterStorage.updateSubscriptionFilters(subscription4, [filter3, filter4, filt
er5]); | 322 filterStorage.updateSubscriptionFilters(subscription4, [filter3.text, filter4.
text, filter5.text]); |
324 checkKnownFilters(test, "update subscription not in the list yet", {blacklist:
[filter1.text], whitelist: [filter2.text]}); | 323 checkKnownFilters(test, "update subscription not in the list yet", {blacklist:
[filter1.text], whitelist: [filter2.text]}); |
325 | 324 |
326 filterStorage.addSubscription(subscription4); | 325 filterStorage.addSubscription(subscription4); |
327 checkKnownFilters(test, "add subscription to the list", {blacklist: [filter1.t
ext, filter3.text], whitelist: [filter2.text, filter4.text]}); | 326 checkKnownFilters(test, "add subscription to the list", {blacklist: [filter1.t
ext, filter3.text], whitelist: [filter2.text, filter4.text]}); |
328 | 327 |
329 filterStorage.updateSubscriptionFilters(subscription4, [filter3, filter2, filt
er5]); | 328 filterStorage.updateSubscriptionFilters(subscription4, [filter3.text, filter2.
text, filter5.text]); |
330 checkKnownFilters(test, "update subscription while in the list", {blacklist: [
filter1.text, filter3.text], whitelist: [filter2.text]}); | 329 checkKnownFilters(test, "update subscription while in the list", {blacklist: [
filter1.text, filter3.text], whitelist: [filter2.text]}); |
331 | 330 |
332 subscription3.disabled = true; | 331 subscription3.disabled = true; |
333 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text,
filter3.text], whitelist: [filter2.text]}); | 332 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text,
filter3.text], whitelist: [filter2.text]}); |
334 | 333 |
335 filterStorage.removeSubscription(subscription4); | 334 filterStorage.removeSubscription(subscription4); |
336 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); | 335 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); |
337 | 336 |
338 subscription3.disabled = false; | 337 subscription3.disabled = false; |
339 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); | 338 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); |
(...skipping 28 matching lines...) Expand all Loading... |
368 checkKnownFilters(test, "add special subscription with filter2", {snippets: [f
ilter1.text, filter2.text]}); | 367 checkKnownFilters(test, "add special subscription with filter2", {snippets: [f
ilter1.text, filter2.text]}); |
369 | 368 |
370 let subscription4 = Subscription.fromURL("https://easylist-downloads.adblockpl
us.org/abp-filters-anti-cv.txt"); | 369 let subscription4 = Subscription.fromURL("https://easylist-downloads.adblockpl
us.org/abp-filters-anti-cv.txt"); |
371 subscription4.addFilter(filter3); | 370 subscription4.addFilter(filter3); |
372 | 371 |
373 filterStorage.addSubscription(subscription4); | 372 filterStorage.addSubscription(subscription4); |
374 checkKnownFilters(test, "add ABP anti-circumvention subscription with filter3"
, {snippets: [filter1.text, filter2.text, filter3.text]}); | 373 checkKnownFilters(test, "add ABP anti-circumvention subscription with filter3"
, {snippets: [filter1.text, filter2.text, filter3.text]}); |
375 | 374 |
376 test.done(); | 375 test.done(); |
377 }; | 376 }; |
LEFT | RIGHT |