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

Side by Side Diff: test/elemHideEmulation.js

Issue 29361668: Issue 4394 - Create a filter class for element hiding emulation filters (Closed) Base URL: https://bitbucket.org/fhd/adblockpluscore
Patch Set: Created Nov. 3, 2016, 3:42 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
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 let {createSandbox} = require("./_common"); 20 let {createSandbox} = require("./_common");
21 21
22 let CSSPropertyFilter = null; 22 let ElemHideEmulationFilter = null;
23 let CSSRules = null; 23 let ElemHideEmulation = null;
24 let ElemHide = null; 24 let ElemHide = null;
25 let Filter = null; 25 let Filter = null;
26 26
27 exports.setUp = function(callback) 27 exports.setUp = function(callback)
28 { 28 {
29 let sandboxedRequire = createSandbox(); 29 let sandboxedRequire = createSandbox();
30 ( 30 (
31 {Filter, CSSPropertyFilter} = sandboxedRequire("../lib/filterClasses"), 31 {Filter, ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses") ,
kzar 2016/11/04 15:45:56 Nit: Mind fixing the few long lines here?
Felix Dahlke 2016/11/04 16:43:35 It bothered me too, but I don't see an obvious way
kzar 2016/11/07 17:19:26 Well this line is not the worst, but none the less
Felix Dahlke 2016/11/08 17:45:35 Yeah, that's nice actually.
Felix Dahlke 2016/11/11 11:51:42 Done.
32 {CSSRules} = sandboxedRequire("../lib/cssRules"), 32 {ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"),
33 {ElemHide} = sandboxedRequire("../lib/elemHide") 33 {ElemHide} = sandboxedRequire("../lib/elemHide")
34 ); 34 );
35 35
36 callback(); 36 callback();
37 }; 37 };
38 38
39 exports.testDomainRestrictions = function(test) 39 exports.testDomainRestrictions = function(test)
40 { 40 {
41 function testSelectorMatches(description, filters, domain, expectedMatches) 41 function testSelectorMatches(description, filters, domain, expectedMatches)
42 { 42 {
43 for (let filter of filters) 43 for (let filter of filters)
44 { 44 {
45 filter = Filter.fromText(filter); 45 filter = Filter.fromText(filter);
46 if (filter instanceof CSSPropertyFilter) 46 if (filter instanceof ElemHideEmulationFilter)
47 CSSRules.add(filter); 47 ElemHideEmulation.add(filter);
48 else 48 else
49 ElemHide.add(filter); 49 ElemHide.add(filter);
50 } 50 }
51 51
52 let matches = CSSRules.getRulesForDomain(domain).map(filter => filter.text); 52 let matches = ElemHideEmulation.getRulesForDomain(domain).map(filter => filt er.text);
53 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 53 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
54 54
55 CSSRules.clear(); 55 ElemHideEmulation.clear();
56 ElemHide.clear(); 56 ElemHide.clear();
57 } 57 }
58 58
59 testSelectorMatches( 59 testSelectorMatches(
60 "Ignore generic filters", 60 "Ignore generic filters",
61 ["##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 61 ["##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
62 "~example.com##[-abp-properties='foo']"], 62 "~example.com##[-abp-properties='foo']"],
63 "example.com", 63 "example.com",
64 ["example.com##[-abp-properties='foo']"] 64 ["example.com##[-abp-properties='foo']"]
65 ); 65 );
(...skipping 22 matching lines...) Expand all
88 "Ignore filters for other subdomain", 88 "Ignore filters for other subdomain",
89 ["www.example.com##[-abp-properties='foo']", 89 ["www.example.com##[-abp-properties='foo']",
90 "other.example.com##[-abp-properties='foo']"], 90 "other.example.com##[-abp-properties='foo']"],
91 "other.example.com", 91 "other.example.com",
92 ["other.example.com##[-abp-properties='foo']"] 92 ["other.example.com##[-abp-properties='foo']"]
93 ); 93 );
94 94
95 test.done(); 95 test.done();
96 }; 96 };
97 97
98 exports.testCSSPropertyFiltersContainer = function(test) 98 exports.testElemHideEmulationFiltersContainer = function(test)
99 { 99 {
100 function compareRules(description, domain, expectedMatches) 100 function compareRules(description, domain, expectedMatches)
101 { 101 {
102 let result = CSSRules.getRulesForDomain(domain) 102 let result = ElemHideEmulation.getRulesForDomain(domain)
103 .map((filter) => filter.text); 103 .map((filter) => filter.text);
104 expectedMatches = expectedMatches.map(filter => filter.text); 104 expectedMatches = expectedMatches.map(filter => filter.text);
105 test.deepEqual(result.sort(), expectedMatches.sort(), description); 105 test.deepEqual(result.sort(), expectedMatches.sort(), description);
106 } 106 }
107 107
108 let domainFilter = Filter.fromText("example.com##filter1"); 108 let domainFilter = Filter.fromText("example.com##filter1");
109 let subdomainFilter = Filter.fromText("www.example.com##filter2"); 109 let subdomainFilter = Filter.fromText("www.example.com##filter2");
110 let otherDomainFilter = Filter.fromText("other.example.com##filter3"); 110 let otherDomainFilter = Filter.fromText("other.example.com##filter3");
111 111
112 CSSRules.add(domainFilter); 112 ElemHideEmulation.add(domainFilter);
113 CSSRules.add(subdomainFilter); 113 ElemHideEmulation.add(subdomainFilter);
114 CSSRules.add(otherDomainFilter); 114 ElemHideEmulation.add(otherDomainFilter);
115 compareRules( 115 compareRules(
116 "Return all matching filters", 116 "Return all matching filters",
117 "www.example.com", 117 "www.example.com",
118 [domainFilter, subdomainFilter] 118 [domainFilter, subdomainFilter]
119 ); 119 );
120 120
121 CSSRules.remove(domainFilter); 121 ElemHideEmulation.remove(domainFilter);
122 compareRules( 122 compareRules(
123 "Return all matching filters after removing one", 123 "Return all matching filters after removing one",
124 "www.example.com", 124 "www.example.com",
125 [subdomainFilter] 125 [subdomainFilter]
126 ); 126 );
127 127
128 CSSRules.clear(); 128 ElemHideEmulation.clear();
129 compareRules( 129 compareRules(
130 "Return no filters after clearing", 130 "Return no filters after clearing",
131 "www.example.com", 131 "www.example.com",
132 [] 132 []
133 ); 133 );
134 134
135 test.done(); 135 test.done();
136 }; 136 };
OLDNEW

Powered by Google App Engine
This is Rietveld