Index: chrome/content/tests/cssRules.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/chrome/content/tests/cssRules.js |
@@ -0,0 +1,84 @@ |
+(function() |
+{ |
+ module("CSS property filter", { |
+ setup: function() |
+ { |
+ prepareFilterComponents.call(this); |
+ preparePrefs.call(this); |
+ }, |
+ teardown: function() |
+ { |
+ restoreFilterComponents.call(this); |
+ restorePrefs.call(this); |
+ } |
+ }); |
+ |
+ function runSelectorTest([text, domain, filters, expected]) |
+ { |
+ for (let filter of filters) |
+ { |
+ filter = Filter.fromText(filter); |
+ if (filter instanceof CSSPropertyFilter) |
+ CSSRules.add(filter); |
+ else |
+ ElemHide.add(filter); |
+ } |
+ |
+ let result = CSSRules.getRulesForDomain(domain) |
+ .map((filter) => filter.text); |
+ deepEqual(result.sort(), expected.sort(), text); |
+ |
+ CSSRules.clear(); |
+ ElemHide.clear(); |
+ } |
+ |
+ let selectorTests = [ |
+ ["Return single filter for multiple domains", "www.example.com", ["www.example.com,example.com##[-abp-properties='foo']"], ["www.example.com,example.com##[-abp-properties='foo']"]], |
+ // ["Return unique selectors from multiple filters", "www.example.com", ["www.example.com##[-abp-properties='foo']", "other.example.org,www.example.com##[-abp-properties='foo']"], ["[-abp-properties='foo']"]], |
Thomas Greiner
2015/12/03 12:55:21
Removed these ones because they can no longer appl
|
+ ["Ignore selectors with exceptions", "example.com", ["example.com##[-abp-properties='foo']", "example.com##[-abp-properties='bar']", "example.com#@#[-abp-properties='foo']"], ["example.com##[-abp-properties='bar']"]], |
+ ["Ignore filters that include parent domain but exclude subdomain", "www.example.com", ["~www.example.com,example.com##[-abp-properties='foo']"], []], |
+ ["Ignore filters with parent domain if exception matches subdomain", "www.example.com", ["www.example.com#@#[-abp-properties='foo']", "example.com##[-abp-properties='foo']"], []] |
+ ]; |
+ |
+ test("Domain restrictions", function() |
+ { |
+ for (let selectorTest of selectorTests) |
+ runSelectorTest(selectorTest); |
+ }); |
+ |
+ let testObjectCount = 0; |
+ function constructFilter(domain) |
+ { |
+ let selector = "filter_" + (++testObjectCount); |
+ return Filter.fromText(domain + "##" + selector); |
+ } |
+ |
+ function compareRules(text, domain, expected) |
+ { |
+ let result = CSSRules.getRulesForDomain(domain) |
+ .map((filter) => filter.text); |
+ expected = expected.map((filter) => filter.text); |
+ deepEqual(result.sort(), expected.sort(), text); |
+ } |
+ |
+ test("CSS property filters container", function() |
+ { |
+ let genericFilter = constructFilter(""); |
+ let domainFilter = constructFilter("example.com"); |
+ let subdomainFilter = constructFilter("www.example.com"); |
+ let otherDomainFilter = constructFilter("other.example.com"); |
+ |
+ CSSRules.add(genericFilter); |
+ CSSRules.add(domainFilter); |
+ CSSRules.add(subdomainFilter); |
+ CSSRules.add(otherDomainFilter); |
+ compareRules("Return all matching filters", "www.example.com", |
+ [genericFilter, domainFilter, subdomainFilter]); |
+ |
+ CSSRules.clear(); |
+ CSSRules.add(subdomainFilter); |
+ CSSRules.add(otherDomainFilter); |
+ compareRules("Don't match other subdomain", "www.example.com", |
+ [subdomainFilter]); |
+ }); |
+})(); |