Left: | ||
Right: |
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); | |
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
| |
25 } | |
26 | |
27 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.
| |
28 equal(selectors.sort().join("\n"), expected.sort().join("\n"), text); | |
29 | |
30 CSSRules.clear(); | |
31 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.
| |
32 } | |
33 | |
34 let selectorTests = [ | |
35 ["Return unique selectors from single filter", "www.example.com", ["www.exam ple.com,example.com##[-abp-properties='foo']"], ["[-abp-properties='foo']"]], | |
36 // ["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']"]], | |
Thomas Greiner
2015/08/25 16:11:47
I commented this one out since our current impleme
| |
37 ["Ignore selectors with exceptions", "example.com", ["example.com##[-abp-pro perties='foo']", "example.com##[-abp-properties='bar']", "example.com#@#[-abp-pr operties='foo']"], ["[-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']"], []] | |
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.
| |
40 ]; | |
41 | |
42 test("Domain restrictions", function() | |
43 { | |
44 for (let selectorTest of selectorTests) | |
45 runSelectorTest(selectorTest); | |
Wladimir Palant
2015/11/10 10:49:02
selectorTests.forEach(runSelectorTest)?
Thomas Greiner
2015/12/03 12:55:20
Done.
| |
46 }); | |
47 | |
48 let testObjectCount = 0; | |
49 function constructTestObject(domain) | |
50 { | |
51 let selector = "filter_" + (++testObjectCount); | |
52 return { | |
53 filter: Filter.fromText(domain + "##" + selector), | |
54 selector: selector | |
55 }; | |
56 } | |
57 | |
58 function compareRules(text, domain, expected) | |
59 { | |
60 let result = CSSRules.getRulesForDomain(domain); | |
61 deepEqual(result.sort(), expected.sort(), text); | |
62 } | |
63 | |
64 test("CSS property filters container", function() | |
65 { | |
66 let generic = constructTestObject(""); | |
67 let domain = constructTestObject("example.com"); | |
68 let subdomain = constructTestObject("www.example.com"); | |
69 let otherDomain = constructTestObject("other.example.com"); | |
70 | |
71 CSSRules.add(generic.filter); | |
72 CSSRules.add(domain.filter); | |
73 CSSRules.add(subdomain.filter); | |
74 CSSRules.add(otherDomain.filter); | |
75 compareRules("Return all matching filters", "www.example.com", | |
76 [generic.selector, domain.selector, subdomain.selector]); | |
77 | |
78 CSSRules.clear(); | |
79 CSSRules.add(subdomain.filter); | |
80 CSSRules.add(otherDomain.filter); | |
81 compareRules("Don't match other subdomain", "www.example.com", | |
82 [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
| |
83 }); | |
84 })(); | |
OLD | NEW |