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

Side by Side Diff: test/elemHideEmulation.js

Issue 29595633: Issue 5870 - Implement the new ElemHideEmulation filter type (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: properly handle exception filters. some test fixes. Created Nov. 3, 2017, 5:02 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 | « compiled/filter/ElemHideBase.cpp ('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-present eyeo GmbH 3 * Copyright (C) 2006-present 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
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0); 91 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
92 test.equal(selectors.selectorCount, 3); 92 test.equal(selectors.selectorCount, 3);
93 93
94 ElemHide.remove(filter3); 94 ElemHide.remove(filter3);
95 selectors = ElemHide.getSelectorsForDomain("example.com", 0); 95 selectors = ElemHide.getSelectorsForDomain("example.com", 0);
96 test.equal(selectors.selectorCount, 2); 96 test.equal(selectors.selectorCount, 2);
97 97
98 test.done(); 98 test.done();
99 }; 99 };
100 100
101 exports.testSyntaxConversion = function(test)
102 {
103 function checkConvertedFilter(old, converted)
104 {
105 let filter = Filter.fromText(old);
106
107 test.equal(filter.text, converted);
108 }
109
110 checkConvertedFilter("example.com#?#foo[-abp-properties='something']bar", "exa mple.com#?#foo:-abp-properties(something)bar");
111 checkConvertedFilter("example.com#@#foo[-abp-properties='something']bar", "exa mple.com#@#foo:-abp-properties(something)bar");
112 checkConvertedFilter("example.com#?#[-abp-properties=\"something\"]", "example .com#?#:-abp-properties(something)");
113 checkConvertedFilter("example.com#?#[-abp-properties=(something)]", "example.c om#?#:-abp-properties((something))");
114
115 test.done();
116 };
117
101 exports.testDomainRestrictions = function(test) 118 exports.testDomainRestrictions = function(test)
102 { 119 {
103 function testSelectorMatches(description, filters, domain, expectedMatches) 120 function testSelectorMatches(description, filters, domain, expectedMatches)
104 { 121 {
105 for (let text of filters) 122 for (let text of filters)
106 { 123 {
107 let filter = Filter.fromText(text); 124 let filter = Filter.fromText(text);
108 if (filter instanceof ElemHideEmulationFilter) 125 if (filter instanceof ElemHideEmulationFilter)
109 ElemHideEmulation.add(filter); 126 ElemHideEmulation.add(filter);
110 else 127 else
111 ElemHide.add(filter); 128 ElemHide.add(filter);
112 } 129 }
113 130
114 let rules = ElemHideEmulation.getRulesForDomain(domain); 131 let rules = ElemHideEmulation.getRulesForDomain(domain);
115 let matches = []; 132 let matches = [];
116 for (let i = 0; i < rules.filterCount; i++) 133 for (let i = 0; i < rules.filterCount; i++)
117 matches.push(rules.filterAt(i).text); 134 matches.push(rules.filterAt(i).text);
118 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 135 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
119 136
120 ElemHideEmulation.clear(); 137 ElemHideEmulation.clear();
121 ElemHide.clear(); 138 ElemHide.clear();
122 } 139 }
123 140
124 testSelectorMatches( 141 testSelectorMatches(
125 "Ignore generic filters", 142 "Ignore generic filters",
126 [ 143 [
127 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 144 "#?#:-abp-properties(foo)", "example.com#?#:-abp-properties(foo)",
128 "~example.com##[-abp-properties='foo']" 145 "~example.com##:-abp-properties(foo)"
129 ], 146 ],
130 "example.com", 147 "example.com",
131 ["example.com##[-abp-properties='foo']"] 148 ["example.com#?#:-abp-properties(foo)"]
132 ); 149 );
133 testSelectorMatches( 150 testSelectorMatches(
134 "Ignore selectors with exceptions", 151 "Ignore selectors with exceptions",
135 [ 152 [
136 "example.com##[-abp-properties='foo']", 153 "example.com#?#:-abp-properties(foo)",
137 "example.com##[-abp-properties='bar']", 154 "example.com#?#:-abp-properties(bar)",
138 "example.com#@#[-abp-properties='foo']" 155 "example.com#@#:-abp-properties(foo)"
139 ], 156 ],
140 "example.com", 157 "example.com",
141 ["example.com##[-abp-properties='bar']"] 158 ["example.com#?#:-abp-properties(bar)"]
142 ); 159 );
143 testSelectorMatches( 160 testSelectorMatches(
144 "Ignore filters that include parent domain but exclude subdomain", 161 "Ignore filters that include parent domain but exclude subdomain",
145 [ 162 [
146 "~www.example.com,example.com##[-abp-properties='foo']" 163 "~www.example.com,example.com#?#:-abp-properties(foo)"
147 ], 164 ],
148 "www.example.com", 165 "www.example.com",
149 [] 166 []
150 ); 167 );
151 testSelectorMatches( 168 testSelectorMatches(
152 "Ignore filters with parent domain if exception matches subdomain", 169 "Ignore filters with parent domain if exception matches subdomain",
153 [ 170 [
154 "www.example.com#@#[-abp-properties='foo']", 171 "www.example.com#@#:-abp-properties(foo)",
155 "example.com##[-abp-properties='foo']" 172 "example.com#?#:-abp-properties(foo)"
156 ], 173 ],
157 "www.example.com", 174 "www.example.com",
158 [] 175 []
159 ); 176 );
160 testSelectorMatches( 177 testSelectorMatches(
161 "Ignore filters for other subdomain", 178 "Ignore filters for other subdomain",
162 [ 179 [
163 "www.example.com##[-abp-properties='foo']", 180 "www.example.com#?#:-abp-properties(foo)",
164 "other.example.com##[-abp-properties='foo']" 181 "other.example.com#?#:-abp-properties(foo)"
165 ], 182 ],
166 "other.example.com", 183 "other.example.com",
167 ["other.example.com##[-abp-properties='foo']"] 184 ["other.example.com#?#:-abp-properties(foo)"]
168 ); 185 );
169 186
170 test.done(); 187 test.done();
171 }; 188 };
172 189
173 exports.testElemHideEmulationFiltersContainer = function(test) 190 exports.testElemHideEmulationFiltersContainer = function(test)
174 { 191 {
175 function compareRules(description, domain, expectedMatches) 192 function compareRules(description, domain, expectedMatches)
176 { 193 {
177 let rules = ElemHideEmulation.getRulesForDomain(domain); 194 let rules = ElemHideEmulation.getRulesForDomain(domain);
(...skipping 26 matching lines...) Expand all
204 221
205 ElemHideEmulation.clear(); 222 ElemHideEmulation.clear();
206 compareRules( 223 compareRules(
207 "Return no filters after clearing", 224 "Return no filters after clearing",
208 "www.example.com", 225 "www.example.com",
209 [] 226 []
210 ); 227 );
211 228
212 test.done(); 229 test.done();
213 }; 230 };
OLDNEW
« no previous file with comments | « compiled/filter/ElemHideBase.cpp ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld