| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | |
| 4 * | |
| 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 | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 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/>. | |
| 16 */ | |
| 17 | |
| 18 "use strict"; | |
| 19 | |
| 20 let common = require("common"); | |
| 21 | |
| 22 let {CSSPropertyFilter} = require("filterClasses"); | |
| 23 let {CSSRules} = require("cssRules"); | |
| 24 let {ElemHide} = require("elemHide"); | |
| 25 let {Filter} = require("filterClasses"); | |
| 26 | |
| 27 exports.setUp = function(callback) | |
| 28 { | |
| 29 common.prepareFilterComponents.call(this, true); | |
|
Wladimir Palant
2016/09/26 09:40:58
Saving and restoring data is a hack that was neces
kzar
2016/09/29 15:53:09
Cool idea, it works great as you suggested except
| |
| 30 | |
| 31 callback(); | |
| 32 }; | |
| 33 | |
| 34 exports.tearDown = function(callback) | |
| 35 { | |
| 36 common.restoreFilterComponents.call(this); | |
| 37 | |
| 38 callback(); | |
| 39 } | |
| 40 | |
| 41 exports.testDomainRestrictions = function(test) | |
| 42 { | |
| 43 function testSelectorMatches(description, filters, domain, expectedMatches) | |
| 44 { | |
| 45 for (let filter of filters) | |
| 46 { | |
| 47 filter = Filter.fromText(filter); | |
| 48 if (filter instanceof CSSPropertyFilter) | |
| 49 CSSRules.add(filter); | |
| 50 else | |
| 51 ElemHide.add(filter); | |
| 52 } | |
| 53 | |
| 54 let matches = CSSRules.getRulesForDomain(domain).map(filter => filter.text); | |
| 55 test.deepEqual(matches.sort(), expectedMatches.sort(), description); | |
| 56 | |
| 57 CSSRules.clear(); | |
| 58 ElemHide.clear(); | |
| 59 } | |
| 60 | |
| 61 testSelectorMatches( | |
| 62 "Ignore generic filters", | |
| 63 ["##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", | |
| 64 "~example.com##[-abp-properties='foo']"], | |
| 65 "example.com", | |
| 66 ["example.com##[-abp-properties='foo']"] | |
| 67 ); | |
| 68 testSelectorMatches( | |
| 69 "Ignore selectors with exceptions", | |
| 70 ["example.com##[-abp-properties='foo']", | |
| 71 "example.com##[-abp-properties='bar']", | |
| 72 "example.com#@#[-abp-properties='foo']"], | |
| 73 "example.com", | |
| 74 ["example.com##[-abp-properties='bar']"] | |
| 75 ); | |
| 76 testSelectorMatches( | |
| 77 "Ignore filters that include parent domain but exclude subdomain", | |
| 78 ["~www.example.com,example.com##[-abp-properties='foo']"], | |
| 79 "www.example.com", | |
| 80 [] | |
| 81 ); | |
| 82 testSelectorMatches( | |
| 83 "Ignore filters with parent domain if exception matches subdomain", | |
| 84 ["www.example.com#@#[-abp-properties='foo']", | |
| 85 "example.com##[-abp-properties='foo']"], | |
| 86 "www.example.com", | |
| 87 [] | |
| 88 ); | |
| 89 testSelectorMatches( | |
| 90 "Ignore filters for other subdomain", | |
| 91 ["www.example.com##[-abp-properties='foo']", | |
| 92 "other.example.com##[-abp-properties='foo']"], | |
| 93 "other.example.com", | |
| 94 ["other.example.com##[-abp-properties='foo']"] | |
| 95 ); | |
| 96 | |
| 97 test.done(); | |
| 98 }; | |
| 99 | |
| 100 exports.testCSSPropertyFiltersContainer = function(test) | |
| 101 { | |
| 102 function compareRules(description, domain, expectedMatches) | |
| 103 { | |
| 104 let result = CSSRules.getRulesForDomain(domain) | |
| 105 .map((filter) => filter.text); | |
| 106 expectedMatches = expectedMatches.map(filter => filter.text); | |
| 107 test.deepEqual(result.sort(), expectedMatches.sort(), description); | |
| 108 } | |
| 109 | |
| 110 let domainFilter = Filter.fromText("example.com##filter1"); | |
| 111 let subdomainFilter = Filter.fromText("www.example.com##filter2"); | |
| 112 let otherDomainFilter = Filter.fromText("other.example.com##filter3"); | |
| 113 | |
| 114 CSSRules.add(domainFilter); | |
| 115 CSSRules.add(subdomainFilter); | |
| 116 CSSRules.add(otherDomainFilter); | |
| 117 compareRules( | |
| 118 "Return all matching filters", | |
| 119 "www.example.com", | |
| 120 [domainFilter, subdomainFilter] | |
| 121 ); | |
| 122 | |
| 123 CSSRules.remove(domainFilter); | |
| 124 compareRules( | |
| 125 "Return all matching filters after removing one", | |
| 126 "www.example.com", | |
| 127 [subdomainFilter] | |
| 128 ); | |
| 129 | |
| 130 CSSRules.clear(); | |
| 131 compareRules( | |
| 132 "Return no filters after clearing", | |
| 133 "www.example.com", | |
| 134 [] | |
| 135 ); | |
| 136 | |
| 137 test.done(); | |
| 138 }; | |
| OLD | NEW |