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

Side by Side Diff: test/filterClasses.js

Issue 29453590: Issue 5287 - Change syntax for element hiding emulation filters and remove simplified element hidin… (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 1, 2017, 12:01 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/elemHideEmulation.js ('k') | test/filterListener.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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]); 214 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]);
215 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]); 215 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]);
216 216
217 test.done(); 217 test.done();
218 }; 218 };
219 219
220 exports.testInvalidFilters = function(test) 220 exports.testInvalidFilters = function(test)
221 { 221 {
222 compareFilter(test, "/??/", ["type=invalid", "text=/??/", "reason=filter_inval id_regexp"]); 222 compareFilter(test, "/??/", ["type=invalid", "text=/??/", "reason=filter_inval id_regexp"]);
223 compareFilter(test, "asd$foobar", ["type=invalid", "text=asd$foobar", "reason= filter_unknown_option"]); 223 compareFilter(test, "asd$foobar", ["type=invalid", "text=asd$foobar", "reason= filter_unknown_option"]);
224 compareFilter(test, "#dd(asd)(ddd)", ["type=invalid", "text=#dd(asd)(ddd)", "r eason=filter_elemhide_duplicate_id"]);
225 compareFilter(test, "#*", ["type=invalid", "text=#*", "reason=filter_elemhide_ nocriteria"]);
226 224
227 function checkElemHideEmulationFilterInvalid(domains) 225 function checkElemHideEmulationFilterInvalid(domains)
228 { 226 {
229 let filterText = domains + "##[-abp-properties='abc']"; 227 let filterText = domains + "#?#:-abp-properties(abc)";
Sebastian Noack 2017/06/01 14:15:37 Didn't we plan to keep supporting this syntax (in
Wladimir Palant 2017/06/01 14:30:23 We do, for some limited time. But it makes little
Sebastian Noack 2017/06/01 14:36:43 I guess, if it is still tested in one place, at le
230 compareFilter( 228 compareFilter(
231 test, filterText, [ 229 test, filterText, [
232 "type=invalid", "text=" + filterText, 230 "type=invalid", "text=" + filterText,
233 "reason=filter_elemhideemulation_nodomain" 231 "reason=filter_elemhideemulation_nodomain"
234 ] 232 ]
235 ); 233 );
236 } 234 }
237 checkElemHideEmulationFilterInvalid(""); 235 checkElemHideEmulationFilterInvalid("");
238 checkElemHideEmulationFilterInvalid("~foo.com"); 236 checkElemHideEmulationFilterInvalid("~foo.com");
239 checkElemHideEmulationFilterInvalid("~foo.com,~bar.com"); 237 checkElemHideEmulationFilterInvalid("~foo.com,~bar.com");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac k", "reason=filter_unknown_option"]); 309 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac k", "reason=filter_unknown_option"]);
312 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea son=filter_unknown_option"]); 310 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea son=filter_unknown_option"]);
313 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f oobar", "reason=filter_unknown_option"]); 311 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f oobar", "reason=filter_unknown_option"]);
314 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar, image", "reason=filter_unknown_option"]); 312 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar, image", "reason=filter_unknown_option"]);
315 313
316 test.done(); 314 test.done();
317 }; 315 };
318 316
319 exports.testElementHidingRules = function(test) 317 exports.testElementHidingRules = function(test)
320 { 318 {
321 compareFilter(test, "#ddd", ["type=elemhide", "text=#ddd", "selector=ddd"]); 319 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]);
322 compareFilter(test, "#ddd(fff)", ["type=elemhide", "text=#ddd(fff)", "selector =ddd.fff,ddd#fff"]);
323 compareFilter(test, "#ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", ["typ e=elemhide", "text=#ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", 'selector =ddd[foo="bar"][foo2^="bar2"][foo3*="bar3"][foo4$="bar4"]']);
324 compareFilter(test, "#ddd(fff)(foo=bar)", ["type=elemhide", "text=#ddd(fff)(fo o=bar)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']);
325 compareFilter(test, "#*(fff)", ["type=elemhide", "text=#*(fff)", "selector=.ff f,#fff"]);
326 compareFilter(test, "#*(foo=bar)", ["type=elemhide", "text=#*(foo=bar)", 'sele ctor=[foo="bar"]']);
327 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]); 320 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]);
328 compareFilter(test, "foo#ddd", ["type=elemhide", "text=foo#ddd", "selectorDoma in=foo", "selector=ddd", "domains=FOO"]); 321 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo main=foo", "selector=ddd", "domains=FOO"]);
329 compareFilter(test, "foo,bar#ddd", ["type=elemhide", "text=foo,bar#ddd", "sele ctorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 322 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se lectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
330 compareFilter(test, "foo,~bar#ddd", ["type=elemhide", "text=foo,~bar#ddd", "se lectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); 323 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", " selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
331 compareFilter(test, "foo,~baz,bar#ddd", ["type=elemhide", "text=foo,~baz,bar#d dd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]); 324 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar# #ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
332 325
333 test.done(); 326 test.done();
334 }; 327 };
335 328
336 exports.testElementHidingExceptions = function(test) 329 exports.testElementHidingExceptions = function(test)
337 { 330 {
338 compareFilter(test, "#@ddd", ["type=elemhideexception", "text=#@ddd", "selecto r=ddd"]); 331 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec tor=ddd"]);
339 compareFilter(test, "#@ddd(fff)", ["type=elemhideexception", "text=#@ddd(fff)" , "selector=ddd.fff,ddd#fff"]);
340 compareFilter(test, "#@ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", ["ty pe=elemhideexception", "text=#@ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)" , 'selector=ddd[foo="bar"][foo2^="bar2"][foo3*="bar3"][foo4$="bar4"]']);
341 compareFilter(test, "#@ddd(fff)(foo=bar)", ["type=elemhideexception", "text=#@ ddd(fff)(foo=bar)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']);
342 compareFilter(test, "#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "s elector=.fff,#fff"]);
343 compareFilter(test, "#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=b ar)", 'selector=[foo="bar"]']);
344 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t ext=#@#body > div:first-child", "selector=body > div:first-child"]); 332 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t ext=#@#body > div:first-child", "selector=body > div:first-child"]);
345 compareFilter(test, "foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "s electorDomain=foo", "selector=ddd", "domains=FOO"]); 333 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO"]);
346 compareFilter(test, "foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 334 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar# @#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
347 compareFilter(test, "foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar #@ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); 335 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba r#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
348 compareFilter(test, "foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo, ~baz,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ" ]); 336 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo ,~baz,bar#@#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BA Z"]);
349 337
350 test.done(); 338 test.done();
351 }; 339 };
352 340
353 exports.testElemHideEmulationFilters = function(test) 341 exports.testElemHideEmulationFilters = function(test)
354 { 342 {
355 // Check valid domain combinations 343 // Check valid domain combinations
356 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulati on", "text=foo.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selecto r=[-abp-properties='abc']", "domains=FOO.COM"]); 344 compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulatio n", "text=foo.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector= :-abp-properties(abc)", "domains=FOO.COM"]);
357 compareFilter(test, "foo.com,~bar.com##[-abp-properties='abc']", ["type=elemhi deemulation", "text=foo.com,~bar.com##[-abp-properties='abc']", "selectorDomain= foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR.COM"]); 345 compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "selectorDomain=fo o.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]);
358 compareFilter(test, "foo.com,~bar##[-abp-properties='abc']", ["type=elemhideem ulation", "text=foo.com,~bar##[-abp-properties='abc']", "selectorDomain=foo.com" , "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR"]); 346 compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemu lation", "text=foo.com,~bar#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]);
359 compareFilter(test, "~foo.com,bar.com##[-abp-properties='abc']", ["type=elemhi deemulation", "text=~foo.com,bar.com##[-abp-properties='abc']", "selectorDomain= bar.com", "selector=[-abp-properties='abc']", "domains=BAR.COM|~FOO.COM"]); 347 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "selectorDomain=ba r.com", "selector=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]);
360 348
361 compareFilter(test, "##[-abp-properties='']", ["type=invalid", "text=##[-abp-p roperties='']", "reason=filter_elemhideemulation_nodomain"]); 349 // Check some special cases
350 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]);
351 compareFilter(test, "foo.com#?#abc", ["type=invalid", "text=foo.com#?#abc", "r eason=filter_elemhideemulation_plainselector"]);
352 compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-foobar(abc)", "selectorDomain=foo.com", "selector=:-abp-fo obar(abc)", "domains=FOO.COM"]);
353 compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhide emulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomain=foo. com", "selector=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]);
354 compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*) )", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-imag e: url(data:*))", "selectorDomain=foo.com", "selector=:-abp-properties(|backgrou nd-image: url(data:*))", "domains=FOO.COM"]);
355
356 // Check conversion of legacy filters
357 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulati on", "text=foo.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector =:-abp-properties(abc)", "domains=FOO.COM"]);
358 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex t("foo.com#?#:-abp-properties(abc)"));
362 compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexcept ion", "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selec tor=[-abp-properties='abc']", "domains=FOO.COM"]); 359 compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexcept ion", "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selec tor=[-abp-properties='abc']", "domains=FOO.COM"]);
363 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhid eemulation", "text=foo.com##aaa [-abp-properties='abc'] bbb", "selectorDomain=fo o.com", "selector=aaa [-abp-properties='abc'] bbb", "domains=FOO.COM"]); 360 compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=invalid", "tex t=foo.com#?#[-abp-properties='abc']", "reason=filter_elemhideemulation_plainsele ctor"]);
364 compareFilter(test, "foo.com##[-abp-properties='|background-image: url(data:*) ']", ["type=elemhideemulation", "text=foo.com##[-abp-properties='|background-ima ge: url(data:*)']", "selectorDomain=foo.com", "selector=[-abp-properties='|backg round-image: url(data:*)']", "domains=FOO.COM"]); 361 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhid eemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomain=foo .com", "selector=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]);
365 362
366 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037) . 363 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037) .
367 compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide" , "text=foo.com##[-abp-properties-bogus='abc']", "selectorDomain=foo.com", "sele ctor=[-abp-properties-bogus='abc']", "domains=FOO.COM"]); 364 compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide" , "text=foo.com##[-abp-properties-bogus='abc']", "selectorDomain=foo.com", "sele ctor=[-abp-properties-bogus='abc']", "domains=FOO.COM"]);
368 365
369 test.done(); 366 test.done();
370 }; 367 };
371 368
372 exports.testEmptyElemHideDomains = function(test) 369 exports.testEmptyElemHideDomains = function(test)
373 { 370 {
374 let emptyDomainFilters = [ 371 let emptyDomainFilters = [
(...skipping 17 matching lines...) Expand all
392 compareFilter( 389 compareFilter(
393 test, "###foo{color: red}", [ 390 test, "###foo{color: red}", [
394 "type=elemhide", 391 "type=elemhide",
395 "text=###foo{color: red}", 392 "text=###foo{color: red}",
396 "selectorDomain=", 393 "selectorDomain=",
397 "selector=#foo\\x7B color: red\\x7D ", 394 "selector=#foo\\x7B color: red\\x7D ",
398 "domains=" 395 "domains="
399 ] 396 ]
400 ); 397 );
401 compareFilter( 398 compareFilter(
402 test, "foo.com##[-abp-properties='/margin: [3-4]{2}/']", [ 399 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [
403 "type=elemhideemulation", 400 "type=elemhideemulation",
404 "text=foo.com##[-abp-properties='/margin: [3-4]{2}/']", 401 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)",
405 "selectorDomain=foo.com", 402 "selectorDomain=foo.com",
406 "selector=[-abp-properties='/margin: [3-4]\\x7B 2\\x7D /']", 403 "selector=:-abp-properties(/margin: [3-4]\\x7B 2\\x7D /)",
407 "domains=FOO.COM" 404 "domains=FOO.COM"
408 ] 405 ]
409 ); 406 );
410 test.done(); 407 test.done();
411 }; 408 };
OLDNEW
« no previous file with comments | « test/elemHideEmulation.js ('k') | test/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld