| LEFT | RIGHT |
| 1 (function() | 1 (function() |
| 2 { | 2 { |
| 3 module("CSS property filter", { | 3 module("CSS property filter", { |
| 4 setup: function() | 4 setup: function() |
| 5 { | 5 { |
| 6 prepareFilterComponents.call(this); | 6 prepareFilterComponents.call(this); |
| 7 preparePrefs.call(this); | 7 preparePrefs.call(this); |
| 8 }, | 8 }, |
| 9 teardown: function() | 9 teardown: function() |
| 10 { | 10 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 let result = CSSRules.getRulesForDomain(domain) | 27 let result = CSSRules.getRulesForDomain(domain) |
| 28 .map((filter) => filter.text); | 28 .map((filter) => filter.text); |
| 29 deepEqual(result.sort(), expected.sort(), text); | 29 deepEqual(result.sort(), expected.sort(), text); |
| 30 | 30 |
| 31 CSSRules.clear(); | 31 CSSRules.clear(); |
| 32 ElemHide.clear(); | 32 ElemHide.clear(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 let selectorTests = [ | 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']"]], | 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 // ["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']"]], | 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']"]], |
| 39 ["Ignore filters that include parent domain but exclude subdomain", "www.exa
mple.com", ["~www.example.com,example.com##[-abp-properties='foo']"], []], | 38 ["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']"], []] | 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 ]; | 41 ]; |
| 42 | 42 |
| 43 test("Domain restrictions", function() | 43 test("Domain restrictions", function() |
| 44 { | 44 { |
| 45 for (let selectorTest of selectorTests) | 45 selectorTests.forEach(runSelectorTest); |
| 46 runSelectorTest(selectorTest); | |
| 47 }); | 46 }); |
| 48 | |
| 49 let testObjectCount = 0; | |
| 50 function constructFilter(domain) | |
| 51 { | |
| 52 let selector = "filter_" + (++testObjectCount); | |
| 53 return Filter.fromText(domain + "##" + selector); | |
| 54 } | |
| 55 | 47 |
| 56 function compareRules(text, domain, expected) | 48 function compareRules(text, domain, expected) |
| 57 { | 49 { |
| 58 let result = CSSRules.getRulesForDomain(domain) | 50 let result = CSSRules.getRulesForDomain(domain) |
| 59 .map((filter) => filter.text); | 51 .map((filter) => filter.text); |
| 60 expected = expected.map((filter) => filter.text); | 52 expected = expected.map((filter) => filter.text); |
| 61 deepEqual(result.sort(), expected.sort(), text); | 53 deepEqual(result.sort(), expected.sort(), text); |
| 62 } | 54 } |
| 63 | 55 |
| 64 test("CSS property filters container", function() | 56 test("CSS property filters container", function() |
| 65 { | 57 { |
| 66 let genericFilter = constructFilter(""); | 58 let domainFilter = Filter.fromText("example.com##filter1"); |
| 67 let domainFilter = constructFilter("example.com"); | 59 let subdomainFilter = Filter.fromText("www.example.com##filter2"); |
| 68 let subdomainFilter = constructFilter("www.example.com"); | 60 let otherDomainFilter = Filter.fromText("other.example.com##filter3"); |
| 69 let otherDomainFilter = constructFilter("other.example.com"); | |
| 70 | 61 |
| 71 CSSRules.add(genericFilter); | |
| 72 CSSRules.add(domainFilter); | 62 CSSRules.add(domainFilter); |
| 73 CSSRules.add(subdomainFilter); | 63 CSSRules.add(subdomainFilter); |
| 74 CSSRules.add(otherDomainFilter); | 64 CSSRules.add(otherDomainFilter); |
| 75 compareRules("Return all matching filters", "www.example.com", | 65 compareRules("Return all matching filters", "www.example.com", |
| 76 [genericFilter, domainFilter, subdomainFilter]); | 66 [domainFilter, subdomainFilter]); |
| 67 |
| 68 CSSRules.remove(domainFilter); |
| 69 compareRules("Return all matching filters after removing one", |
| 70 "www.example.com", [subdomainFilter]); |
| 77 | 71 |
| 78 CSSRules.clear(); | 72 CSSRules.clear(); |
| 79 CSSRules.add(subdomainFilter); | 73 compareRules("Return no filters after clearing", "www.example.com", []); |
| 80 CSSRules.add(otherDomainFilter); | |
| 81 compareRules("Don't match other subdomain", "www.example.com", | |
| 82 [subdomainFilter]); | |
| 83 }); | 74 }); |
| 84 })(); | 75 })(); |
| LEFT | RIGHT |