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 ["Ignore generic filters", "example.com", ["##[-abp-properties='foo']", "exa
mple.com##[-abp-properties='foo']", "~example.com##[-abp-properties='foo']"], ["
example.com##[-abp-properties='foo']"]], |
| 37 ["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']"]], |
| 38 ["Ignore filters that include parent domain but exclude subdomain", "www.exa
mple.com", ["~www.example.com,example.com##[-abp-properties='foo']"], []], |
| 39 ["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']"], []], |
| 40 ["Ignore filters for other subdomain", "other.example.com", ["www.example.co
m##[-abp-properties='foo']", "other.example.com##[-abp-properties='foo']"], ["ot
her.example.com##[-abp-properties='foo']"]] |
| 41 ]; |
| 42 |
| 43 test("Domain restrictions", function() |
| 44 { |
| 45 selectorTests.forEach(runSelectorTest); |
| 46 }); |
| 47 |
| 48 function compareRules(text, domain, expected) |
| 49 { |
| 50 let result = CSSRules.getRulesForDomain(domain) |
| 51 .map((filter) => filter.text); |
| 52 expected = expected.map((filter) => filter.text); |
| 53 deepEqual(result.sort(), expected.sort(), text); |
| 54 } |
| 55 |
| 56 test("CSS property filters container", function() |
| 57 { |
| 58 let domainFilter = Filter.fromText("example.com##filter1"); |
| 59 let subdomainFilter = Filter.fromText("www.example.com##filter2"); |
| 60 let otherDomainFilter = Filter.fromText("other.example.com##filter3"); |
| 61 |
| 62 CSSRules.add(domainFilter); |
| 63 CSSRules.add(subdomainFilter); |
| 64 CSSRules.add(otherDomainFilter); |
| 65 compareRules("Return all matching filters", "www.example.com", |
| 66 [domainFilter, subdomainFilter]); |
| 67 |
| 68 CSSRules.remove(domainFilter); |
| 69 compareRules("Return all matching filters after removing one", |
| 70 "www.example.com", [subdomainFilter]); |
| 71 |
| 72 CSSRules.clear(); |
| 73 compareRules("Return no filters after clearing", "www.example.com", []); |
| 74 }); |
| 75 })(); |
OLD | NEW |