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

Side by Side Diff: test/cssRules.js

Issue 29354864: Issue 4223 - Migrate some more of adblockplustests (Closed)
Patch Set: Addressed final nit Created Oct. 4, 2016, 12:16 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
« no previous file with comments | « test/_common.js ('k') | test/domainRestrictions.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 let {createSandbox} = require("./_common");
21
22 let CSSPropertyFilter = null;
23 let CSSRules = null;
24 let ElemHide = null;
25 let Filter = null;
26
27 exports.setUp = function(callback)
28 {
29 let sandboxedRequire = createSandbox();
30 (
31 {Filter, CSSPropertyFilter} = sandboxedRequire("../lib/filterClasses"),
32 {CSSRules} = sandboxedRequire("../lib/cssRules"),
33 {ElemHide} = sandboxedRequire("../lib/elemHide")
34 );
35
36 callback();
37 };
38
39 exports.testDomainRestrictions = function(test)
40 {
41 function testSelectorMatches(description, filters, domain, expectedMatches)
42 {
43 for (let filter of filters)
44 {
45 filter = Filter.fromText(filter);
46 if (filter instanceof CSSPropertyFilter)
47 CSSRules.add(filter);
48 else
49 ElemHide.add(filter);
50 }
51
52 let matches = CSSRules.getRulesForDomain(domain).map(filter => filter.text);
53 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
54
55 CSSRules.clear();
56 ElemHide.clear();
57 }
58
59 testSelectorMatches(
60 "Ignore generic filters",
61 ["##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
62 "~example.com##[-abp-properties='foo']"],
63 "example.com",
64 ["example.com##[-abp-properties='foo']"]
65 );
66 testSelectorMatches(
67 "Ignore selectors with exceptions",
68 ["example.com##[-abp-properties='foo']",
69 "example.com##[-abp-properties='bar']",
70 "example.com#@#[-abp-properties='foo']"],
71 "example.com",
72 ["example.com##[-abp-properties='bar']"]
73 );
74 testSelectorMatches(
75 "Ignore filters that include parent domain but exclude subdomain",
76 ["~www.example.com,example.com##[-abp-properties='foo']"],
77 "www.example.com",
78 []
79 );
80 testSelectorMatches(
81 "Ignore filters with parent domain if exception matches subdomain",
82 ["www.example.com#@#[-abp-properties='foo']",
83 "example.com##[-abp-properties='foo']"],
84 "www.example.com",
85 []
86 );
87 testSelectorMatches(
88 "Ignore filters for other subdomain",
89 ["www.example.com##[-abp-properties='foo']",
90 "other.example.com##[-abp-properties='foo']"],
91 "other.example.com",
92 ["other.example.com##[-abp-properties='foo']"]
93 );
94
95 test.done();
96 };
97
98 exports.testCSSPropertyFiltersContainer = function(test)
99 {
100 function compareRules(description, domain, expectedMatches)
101 {
102 let result = CSSRules.getRulesForDomain(domain)
103 .map((filter) => filter.text);
104 expectedMatches = expectedMatches.map(filter => filter.text);
105 test.deepEqual(result.sort(), expectedMatches.sort(), description);
106 }
107
108 let domainFilter = Filter.fromText("example.com##filter1");
109 let subdomainFilter = Filter.fromText("www.example.com##filter2");
110 let otherDomainFilter = Filter.fromText("other.example.com##filter3");
111
112 CSSRules.add(domainFilter);
113 CSSRules.add(subdomainFilter);
114 CSSRules.add(otherDomainFilter);
115 compareRules(
116 "Return all matching filters",
117 "www.example.com",
118 [domainFilter, subdomainFilter]
119 );
120
121 CSSRules.remove(domainFilter);
122 compareRules(
123 "Return all matching filters after removing one",
124 "www.example.com",
125 [subdomainFilter]
126 );
127
128 CSSRules.clear();
129 compareRules(
130 "Return no filters after clearing",
131 "www.example.com",
132 []
133 );
134
135 test.done();
136 };
OLDNEW
« no previous file with comments | « test/_common.js ('k') | test/domainRestrictions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld