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); |
Wladimir Palant
2015/11/10 10:49:02
Why add to ElemHide here if you are only testing C
Thomas Greiner
2015/12/03 12:55:19
Because exception rules are still handled by `Elem
|
+ } |
+ |
+ let selectors = CSSRules.getRulesForDomain(domain); |
Wladimir Palant
2015/11/10 10:49:02
Note that getRulesForDomain() should return filter
Thomas Greiner
2015/12/03 12:55:19
Done.
|
+ equal(selectors.sort().join("\n"), expected.sort().join("\n"), text); |
+ |
+ CSSRules.clear(); |
+ ElemHide.clear(); |
Wladimir Palant
2015/11/10 10:49:02
You should add a CSSRules.clear() call to prepareF
Thomas Greiner
2015/12/03 12:55:19
I already did.
|
+ } |
+ |
+ let selectorTests = [ |
+ ["Return unique selectors from single filter", "www.example.com", ["www.example.com,example.com##[-abp-properties='foo']"], ["[-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/08/25 16:11:47
I commented this one out since our current impleme
|
+ ["Ignore selectors with exceptions", "example.com", ["example.com##[-abp-properties='foo']", "example.com##[-abp-properties='bar']", "example.com#@#[-abp-properties='foo']"], ["[-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']"], []] |
Wladimir Palant
2015/11/10 10:49:02
I'd expect a test here verifying that generic rule
Thomas Greiner
2015/12/03 12:55:20
Done. Added a test for ignoring generic filters.
|
+ ]; |
+ |
+ test("Domain restrictions", function() |
+ { |
+ for (let selectorTest of selectorTests) |
+ runSelectorTest(selectorTest); |
Wladimir Palant
2015/11/10 10:49:02
selectorTests.forEach(runSelectorTest)?
Thomas Greiner
2015/12/03 12:55:20
Done.
|
+ }); |
+ |
+ let testObjectCount = 0; |
+ function constructTestObject(domain) |
+ { |
+ let selector = "filter_" + (++testObjectCount); |
+ return { |
+ filter: Filter.fromText(domain + "##" + selector), |
+ selector: selector |
+ }; |
+ } |
+ |
+ function compareRules(text, domain, expected) |
+ { |
+ let result = CSSRules.getRulesForDomain(domain); |
+ deepEqual(result.sort(), expected.sort(), text); |
+ } |
+ |
+ test("CSS property filters container", function() |
+ { |
+ let generic = constructTestObject(""); |
+ let domain = constructTestObject("example.com"); |
+ let subdomain = constructTestObject("www.example.com"); |
+ let otherDomain = constructTestObject("other.example.com"); |
+ |
+ CSSRules.add(generic.filter); |
+ CSSRules.add(domain.filter); |
+ CSSRules.add(subdomain.filter); |
+ CSSRules.add(otherDomain.filter); |
+ compareRules("Return all matching filters", "www.example.com", |
+ [generic.selector, domain.selector, subdomain.selector]); |
+ |
+ CSSRules.clear(); |
+ CSSRules.add(subdomain.filter); |
+ CSSRules.add(otherDomain.filter); |
+ compareRules("Don't match other subdomain", "www.example.com", |
+ [subdomain.selector]); |
Wladimir Palant
2015/11/10 10:49:02
This check makes little sense IMHO, it's already c
Thomas Greiner
2015/12/03 12:55:20
Done. Moved this to `selectorTests`.
Generally, t
|
+ }); |
+})(); |