| OLD | NEW |
| 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 let ElemHideException = null; | 28 let ElemHideException = null; |
| 29 | 29 |
| 30 exports.setUp = function(callback) | 30 exports.setUp = function(callback) |
| 31 { | 31 { |
| 32 sandboxedRequire = createSandbox({ | 32 sandboxedRequire = createSandbox({ |
| 33 extraExports: { | 33 extraExports: { |
| 34 elemHide: ["knownFilters"], | 34 elemHide: ["knownFilters"], |
| 35 elemHideEmulation: ["filters"] | 35 elemHideEmulation: ["filters"], |
| 36 snippets: ["filters"] |
| 36 } | 37 } |
| 37 }); | 38 }); |
| 38 | 39 |
| 39 // We need to require the filterListener module so that filter changes will be | 40 // We need to require the filterListener module so that filter changes will be |
| 40 // noticed, even though we don't directly use the module here. | 41 // noticed, even though we don't directly use the module here. |
| 41 sandboxedRequire("../lib/filterListener"); | 42 sandboxedRequire("../lib/filterListener"); |
| 42 | 43 |
| 43 ( | 44 ( |
| 44 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), | 45 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), |
| 45 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), | 46 {Subscription, SpecialSubscription} = sandboxedRequire("../lib/subscriptionC
lasses"), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 result.elemhideexception.push(filter.text); | 88 result.elemhideexception.push(filter.text); |
| 88 else | 89 else |
| 89 result.elemhide.push(filter.text); | 90 result.elemhide.push(filter.text); |
| 90 } | 91 } |
| 91 | 92 |
| 92 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); | 93 let elemHideEmulation = sandboxedRequire("../lib/elemHideEmulation"); |
| 93 result.elemhideemulation = []; | 94 result.elemhideemulation = []; |
| 94 for (let filterText of elemHideEmulation.filters) | 95 for (let filterText of elemHideEmulation.filters) |
| 95 result.elemhideemulation.push(filterText); | 96 result.elemhideemulation.push(filterText); |
| 96 | 97 |
| 98 let snippets = sandboxedRequire("../lib/snippets"); |
| 99 result.snippets = []; |
| 100 for (let filterText of snippets.filters) |
| 101 result.snippets.push(filterText); |
| 102 |
| 97 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", | 103 let types = ["blacklist", "whitelist", "elemhide", "elemhideexception", |
| 98 "elemhideemulation"]; | 104 "elemhideemulation", "snippets"]; |
| 99 for (let type of types) | 105 for (let type of types) |
| 100 { | 106 { |
| 101 if (!(type in expected)) | 107 if (!(type in expected)) |
| 102 expected[type] = []; | 108 expected[type] = []; |
| 103 else | 109 else |
| 104 expected[type].sort(); | 110 expected[type].sort(); |
| 105 result[type].sort(); | 111 result[type].sort(); |
| 106 } | 112 } |
| 107 | 113 |
| 108 test.deepEqual(result, expected, text); | 114 test.deepEqual(result, expected, text); |
| (...skipping 209 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]}); | 324 checkKnownFilters(test, "disable exception rules", {blacklist: [filter1.text,
filter3.text], whitelist: [filter2.text]}); |
| 319 | 325 |
| 320 FilterStorage.removeSubscription(subscription4); | 326 FilterStorage.removeSubscription(subscription4); |
| 321 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); | 327 checkKnownFilters(test, "remove subscription from the list", {blacklist: [filt
er1.text]}); |
| 322 | 328 |
| 323 subscription3.disabled = false; | 329 subscription3.disabled = false; |
| 324 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); | 330 checkKnownFilters(test, "enable exception rules", {blacklist: [filter1.text],
whitelist: [filter2.text]}); |
| 325 | 331 |
| 326 test.done(); | 332 test.done(); |
| 327 }; | 333 }; |
| 334 |
| 335 exports.testSnippetFilters = function(test) |
| 336 { |
| 337 let filter1 = Filter.fromText("example.com#$#filter1"); |
| 338 let filter2 = Filter.fromText("example.com#$#filter2"); |
| 339 |
| 340 let subscription1 = Subscription.fromURL("http://test1/"); |
| 341 subscription1.filters = [filter1, filter2]; |
| 342 |
| 343 FilterStorage.addSubscription(subscription1); |
| 344 checkKnownFilters(test, "add subscription with filter1 and filter2", {}); |
| 345 |
| 346 let subscription2 = Subscription.fromURL("http://test2/"); |
| 347 subscription2.type = "circumvention"; |
| 348 subscription2.filters = [filter1]; |
| 349 |
| 350 FilterStorage.addSubscription(subscription2); |
| 351 checkKnownFilters(test, "add subscription of type circumvention with filter1",
{snippets: [filter1.text]}); |
| 352 |
| 353 let subscription3 = Subscription.fromURL("~foo"); |
| 354 subscription3.filters = [filter2]; |
| 355 |
| 356 FilterStorage.addSubscription(subscription3); |
| 357 checkKnownFilters(test, "add special subscription with filter2", {snippets: [f
ilter1.text, filter2.text]}); |
| 358 |
| 359 test.done(); |
| 360 }; |
| OLD | NEW |