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: Review comments Created Jan. 30, 2018, 10:52 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-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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 withNAD( 132 withNAD(
133 0, selectors => 133 0, selectors =>
134 test.equal(selectors.selectorCount, 2))( 134 test.equal(selectors.selectorCount, 2))(
135 elemHide.getSelectorsForDomain("example.com", 0)); 135 elemHide.getSelectorsForDomain("example.com", 0));
136 })(ElemHide.create()); 136 })(ElemHide.create());
137 137
138 test.done(); 138 test.done();
139 }; 139 };
140 140
141 exports.testSyntaxConversion = function(test)
142 {
143 function checkConvertedFilter(old, converted)
144 {
145 withNAD(
146 0, filter => test.equal(filter.text, converted))(Filter.fromText(old));
147 }
148
149 checkConvertedFilter("example.com#?#foo[-abp-properties='something']bar", "exa mple.com#?#foo:-abp-properties(something)bar");
150 checkConvertedFilter("example.com#@#foo[-abp-properties='something']bar", "exa mple.com#@#foo:-abp-properties(something)bar");
151 checkConvertedFilter("example.com#?#[-abp-properties=\"something\"]", "example .com#?#:-abp-properties(something)");
152 checkConvertedFilter("example.com#?#[-abp-properties=(something)]", "example.c om#?#:-abp-properties((something))");
153
154 test.done();
155 };
156
141 exports.testDomainRestrictions = function(test) 157 exports.testDomainRestrictions = function(test)
142 { 158 {
143 function testSelectorMatches(description, filters, domain, expectedMatches) 159 function testSelectorMatches(description, filters, domain, expectedMatches)
144 { 160 {
145 withNAD([0, 1], (elemHide, elemHideEmulation) => 161 withNAD([0, 1], (elemHide, elemHideEmulation) =>
146 { 162 {
147 let addFilter = withNAD(0, filter => 163 let addFilter = withNAD(0, filter =>
148 { 164 {
149 if (filter instanceof ElemHideEmulationFilter) 165 if (filter instanceof ElemHideEmulationFilter)
150 elemHideEmulation.add(filter); 166 elemHideEmulation.add(filter);
(...skipping 15 matching lines...) Expand all
166 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 182 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
167 })(elemHideEmulation.getRulesForDomain(elemHide, domain)); 183 })(elemHideEmulation.getRulesForDomain(elemHide, domain));
168 184
169 elemHideEmulation.clear(); 185 elemHideEmulation.clear();
170 })(ElemHide.create(), ElemHideEmulation.create()); 186 })(ElemHide.create(), ElemHideEmulation.create());
171 } 187 }
172 188
173 testSelectorMatches( 189 testSelectorMatches(
174 "Ignore generic filters", 190 "Ignore generic filters",
175 [ 191 [
176 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", 192 "#?#:-abp-properties(foo)", "example.com#?#:-abp-properties(foo)",
177 "~example.com##[-abp-properties='foo']" 193 "~example.com##:-abp-properties(foo)"
178 ], 194 ],
179 "example.com", 195 "example.com",
180 ["example.com##[-abp-properties='foo']"] 196 ["example.com#?#:-abp-properties(foo)"]
181 ); 197 );
182 testSelectorMatches( 198 testSelectorMatches(
183 "Ignore selectors with exceptions", 199 "Ignore selectors with exceptions",
184 [ 200 [
185 "example.com##[-abp-properties='foo']", 201 "example.com#?#:-abp-properties(foo)",
186 "example.com##[-abp-properties='bar']", 202 "example.com#?#:-abp-properties(bar)",
187 "example.com#@#[-abp-properties='foo']" 203 "example.com#@#:-abp-properties(foo)"
188 ], 204 ],
189 "example.com", 205 "example.com",
190 ["example.com##[-abp-properties='bar']"] 206 ["example.com#?#:-abp-properties(bar)"]
191 ); 207 );
192 testSelectorMatches( 208 testSelectorMatches(
193 "Ignore filters that include parent domain but exclude subdomain", 209 "Ignore filters that include parent domain but exclude subdomain",
194 [ 210 [
195 "~www.example.com,example.com##[-abp-properties='foo']" 211 "~www.example.com,example.com#?#:-abp-properties(foo)"
196 ], 212 ],
197 "www.example.com", 213 "www.example.com",
198 [] 214 []
199 ); 215 );
200 testSelectorMatches( 216 testSelectorMatches(
201 "Ignore filters with parent domain if exception matches subdomain", 217 "Ignore filters with parent domain if exception matches subdomain",
202 [ 218 [
203 "www.example.com#@#[-abp-properties='foo']", 219 "www.example.com#@#:-abp-properties(foo)",
204 "example.com##[-abp-properties='foo']" 220 "example.com#?#:-abp-properties(foo)"
205 ], 221 ],
206 "www.example.com", 222 "www.example.com",
207 [] 223 []
208 ); 224 );
209 testSelectorMatches( 225 testSelectorMatches(
210 "Ignore filters for other subdomain", 226 "Ignore filters for other subdomain",
211 [ 227 [
212 "www.example.com##[-abp-properties='foo']", 228 "www.example.com#?#:-abp-properties(foo)",
213 "other.example.com##[-abp-properties='foo']" 229 "other.example.com#?#:-abp-properties(foo)"
214 ], 230 ],
215 "other.example.com", 231 "other.example.com",
216 ["other.example.com##[-abp-properties='foo']"] 232 ["other.example.com#?#:-abp-properties(foo)"]
217 ); 233 );
218 234
219 test.done(); 235 test.done();
220 }; 236 };
221 237
222 exports.testElemHideEmulationFiltersContainer = function(test) 238 exports.testElemHideEmulationFiltersContainer = function(test)
223 { 239 {
224 withNAD([0, 1], (elemHide, elemHideEmulation) => 240 withNAD([0, 1], (elemHide, elemHideEmulation) =>
225 { 241 {
226 function compareRules(description, domain, expectedMatches) 242 function compareRules(description, domain, expectedMatches)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 "www.example.com", 276 "www.example.com",
261 [] 277 []
262 ); 278 );
263 })(Filter.fromText("example.com##filter1"), 279 })(Filter.fromText("example.com##filter1"),
264 Filter.fromText("www.example.com##filter2"), 280 Filter.fromText("www.example.com##filter2"),
265 Filter.fromText("other.example.com##filter3")); 281 Filter.fromText("other.example.com##filter3"));
266 })(ElemHide.create(), ElemHideEmulation.create()); 282 })(ElemHide.create(), ElemHideEmulation.create());
267 283
268 test.done(); 284 test.done();
269 }; 285 };
OLDNEW
« test/compiled/Filter.cpp ('K') | « test/compiled/Filter.cpp ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld