OLD | NEW |
(Empty) | |
| 1 (function() |
| 2 { |
| 3 module("CSS property filter", { |
| 4 setup: function() |
| 5 { |
| 6 prepareFilterComponents.call(this); |
| 7 preparePrefs.call(this); |
| 8 }, |
| 9 teardown: function() |
| 10 { |
| 11 restoreFilterComponents.call(this); |
| 12 restorePrefs.call(this); |
| 13 } |
| 14 }); |
| 15 |
| 16 function runSelectorTest([text, domain, filters, expected]) |
| 17 { |
| 18 for (let filter of filters) |
| 19 { |
| 20 filter = Filter.fromText(filter); |
| 21 if (filter instanceof CSSPropertyFilter) |
| 22 CSSRules.add(filter); |
| 23 else |
| 24 ElemHide.add(filter); |
| 25 } |
| 26 |
| 27 let result = CSSRules.getRulesForDomain(domain) |
| 28 .map((filter) => filter.text); |
| 29 deepEqual(result.sort(), expected.sort(), text); |
| 30 |
| 31 CSSRules.clear(); |
| 32 ElemHide.clear(); |
| 33 } |
| 34 |
| 35 let selectorTests = [ |
| 36 ["Return single filter for multiple domains", "www.example.com", ["www.examp
le.com,example.com##[-abp-properties='foo']"], ["www.example.com,example.com##[-
abp-properties='foo']"]], |
| 37 // ["Return unique selectors from multiple filters", "www.example.com", ["ww
w.example.com##[-abp-properties='foo']", "other.example.org,www.example.com##[-a
bp-properties='foo']"], ["[-abp-properties='foo']"]], |
| 38 ["Ignore selectors with exceptions", "example.com", ["example.com##[-abp-pro
perties='foo']", "example.com##[-abp-properties='bar']", "example.com#@#[-abp-pr
operties='foo']"], ["example.com##[-abp-properties='bar']"]], |
| 39 ["Ignore filters that include parent domain but exclude subdomain", "www.exa
mple.com", ["~www.example.com,example.com##[-abp-properties='foo']"], []], |
| 40 ["Ignore filters with parent domain if exception matches subdomain", "www.ex
ample.com", ["www.example.com#@#[-abp-properties='foo']", "example.com##[-abp-pr
operties='foo']"], []] |
| 41 ]; |
| 42 |
| 43 test("Domain restrictions", function() |
| 44 { |
| 45 for (let selectorTest of selectorTests) |
| 46 runSelectorTest(selectorTest); |
| 47 }); |
| 48 |
| 49 let testObjectCount = 0; |
| 50 function constructFilter(domain) |
| 51 { |
| 52 let selector = "filter_" + (++testObjectCount); |
| 53 return Filter.fromText(domain + "##" + selector); |
| 54 } |
| 55 |
| 56 function compareRules(text, domain, expected) |
| 57 { |
| 58 let result = CSSRules.getRulesForDomain(domain) |
| 59 .map((filter) => filter.text); |
| 60 expected = expected.map((filter) => filter.text); |
| 61 deepEqual(result.sort(), expected.sort(), text); |
| 62 } |
| 63 |
| 64 test("CSS property filters container", function() |
| 65 { |
| 66 let genericFilter = constructFilter(""); |
| 67 let domainFilter = constructFilter("example.com"); |
| 68 let subdomainFilter = constructFilter("www.example.com"); |
| 69 let otherDomainFilter = constructFilter("other.example.com"); |
| 70 |
| 71 CSSRules.add(genericFilter); |
| 72 CSSRules.add(domainFilter); |
| 73 CSSRules.add(subdomainFilter); |
| 74 CSSRules.add(otherDomainFilter); |
| 75 compareRules("Return all matching filters", "www.example.com", |
| 76 [genericFilter, domainFilter, subdomainFilter]); |
| 77 |
| 78 CSSRules.clear(); |
| 79 CSSRules.add(subdomainFilter); |
| 80 CSSRules.add(otherDomainFilter); |
| 81 compareRules("Don't match other subdomain", "www.example.com", |
| 82 [subdomainFilter]); |
| 83 }); |
| 84 })(); |
OLD | NEW |