Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/tests/cssRules.js

Issue 29324604: Issue 2394 - Added unit tests for CSS property filters (Closed)
Patch Set: Created Dec. 3, 2015, 12:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(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 genericFilter = Filter.fromText("##filter1");
Wladimir Palant 2015/12/04 13:09:48 This comment hasn't been addressed from the previo
Thomas Greiner 2015/12/07 17:29:26 Done.
59 let domainFilter = Filter.fromText("example.com##filter2");
60 let subdomainFilter = Filter.fromText("www.example.com##filter3");
61 let otherDomainFilter = Filter.fromText("other.example.com##filter4");
62
63 CSSRules.add(genericFilter);
64 CSSRules.add(domainFilter);
65 CSSRules.add(subdomainFilter);
66 CSSRules.add(otherDomainFilter);
67 compareRules("Return all matching filters", "www.example.com",
68 [genericFilter, domainFilter, subdomainFilter]);
69
70 CSSRules.remove(genericFilter);
71 compareRules("Return all matching filters after removing one",
72 "www.example.com", [domainFilter, subdomainFilter]);
73
74 CSSRules.clear();
75 compareRules("Return no filters after clearing", "www.example.com", []);
76 });
77 })();
OLDNEW

Powered by Google App Engine
This is Rietveld