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: Address kzar's comments Created Nov. 11, 2016, 11:44 a.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 | « lib/filterListener.js ('k') | test/filterClasses.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
32 {CSSRules} = sandboxedRequire("../lib/cssRules"), 32 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"),
33 {ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"),
33 {ElemHide} = sandboxedRequire("../lib/elemHide") 34 {ElemHide} = sandboxedRequire("../lib/elemHide")
34 ); 35 );
35 36
36 callback(); 37 callback();
37 }; 38 };
38 39
39 exports.testDomainRestrictions = function(test) 40 exports.testDomainRestrictions = function(test)
40 { 41 {
41 function testSelectorMatches(description, filters, domain, expectedMatches) 42 function testSelectorMatches(description, filters, domain, expectedMatches)
42 { 43 {
43 for (let filter of filters) 44 for (let filter of filters)
44 { 45 {
45 filter = Filter.fromText(filter); 46 filter = Filter.fromText(filter);
46 if (filter instanceof CSSPropertyFilter) 47 if (filter instanceof ElemHideEmulationFilter)
47 CSSRules.add(filter); 48 ElemHideEmulation.add(filter);
48 else 49 else
49 ElemHide.add(filter); 50 ElemHide.add(filter);
50 } 51 }
51 52
52 let matches = CSSRules.getRulesForDomain(domain).map(filter => filter.text); 53 let matches = ElemHideEmulation.getRulesForDomain(domain)
54 .map(filter => filter.text);
53 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 55 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
54 56
55 CSSRules.clear(); 57 ElemHideEmulation.clear();
56 ElemHide.clear(); 58 ElemHide.clear();
57 } 59 }
58 60
59 testSelectorMatches( 61 testSelectorMatches(
60 "Ignore generic filters", 62 "Ignore generic filters",
61 ["##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 63 ["##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
62 "~example.com##[-abp-properties='foo']"], 64 "~example.com##[-abp-properties='foo']"],
63 "example.com", 65 "example.com",
64 ["example.com##[-abp-properties='foo']"] 66 ["example.com##[-abp-properties='foo']"]
65 ); 67 );
(...skipping 22 matching lines...) Expand all
88 "Ignore filters for other subdomain", 90 "Ignore filters for other subdomain",
89 ["www.example.com##[-abp-properties='foo']", 91 ["www.example.com##[-abp-properties='foo']",
90 "other.example.com##[-abp-properties='foo']"], 92 "other.example.com##[-abp-properties='foo']"],
91 "other.example.com", 93 "other.example.com",
92 ["other.example.com##[-abp-properties='foo']"] 94 ["other.example.com##[-abp-properties='foo']"]
93 ); 95 );
94 96
95 test.done(); 97 test.done();
96 }; 98 };
97 99
98 exports.testCSSPropertyFiltersContainer = function(test) 100 exports.testElemHideEmulationFiltersContainer = function(test)
99 { 101 {
100 function compareRules(description, domain, expectedMatches) 102 function compareRules(description, domain, expectedMatches)
101 { 103 {
102 let result = CSSRules.getRulesForDomain(domain) 104 let result = ElemHideEmulation.getRulesForDomain(domain)
103 .map((filter) => filter.text); 105 .map((filter) => filter.text);
104 expectedMatches = expectedMatches.map(filter => filter.text); 106 expectedMatches = expectedMatches.map(filter => filter.text);
105 test.deepEqual(result.sort(), expectedMatches.sort(), description); 107 test.deepEqual(result.sort(), expectedMatches.sort(), description);
106 } 108 }
107 109
108 let domainFilter = Filter.fromText("example.com##filter1"); 110 let domainFilter = Filter.fromText("example.com##filter1");
109 let subdomainFilter = Filter.fromText("www.example.com##filter2"); 111 let subdomainFilter = Filter.fromText("www.example.com##filter2");
110 let otherDomainFilter = Filter.fromText("other.example.com##filter3"); 112 let otherDomainFilter = Filter.fromText("other.example.com##filter3");
111 113
112 CSSRules.add(domainFilter); 114 ElemHideEmulation.add(domainFilter);
113 CSSRules.add(subdomainFilter); 115 ElemHideEmulation.add(subdomainFilter);
114 CSSRules.add(otherDomainFilter); 116 ElemHideEmulation.add(otherDomainFilter);
115 compareRules( 117 compareRules(
116 "Return all matching filters", 118 "Return all matching filters",
117 "www.example.com", 119 "www.example.com",
118 [domainFilter, subdomainFilter] 120 [domainFilter, subdomainFilter]
119 ); 121 );
120 122
121 CSSRules.remove(domainFilter); 123 ElemHideEmulation.remove(domainFilter);
122 compareRules( 124 compareRules(
123 "Return all matching filters after removing one", 125 "Return all matching filters after removing one",
124 "www.example.com", 126 "www.example.com",
125 [subdomainFilter] 127 [subdomainFilter]
126 ); 128 );
127 129
128 CSSRules.clear(); 130 ElemHideEmulation.clear();
129 compareRules( 131 compareRules(
130 "Return no filters after clearing", 132 "Return no filters after clearing",
131 "www.example.com", 133 "www.example.com",
132 [] 134 []
133 ); 135 );
134 136
135 test.done(); 137 test.done();
136 }; 138 };
OLDNEW
« no previous file with comments | « lib/filterListener.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld