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

Side by Side Diff: test/filterClasses.js

Issue 29580558: Issue 5174 - Allow '{' and '}' in selectors (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Oct. 16, 2017, 5:10 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') | no next file » | 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 ["@@/asdf??+/", InvalidFilter, "invalid"], 60 ["@@/asdf??+/", InvalidFilter, "invalid"],
61 ["##asdf", ElemHideFilter, "elemhide"], 61 ["##asdf", ElemHideFilter, "elemhide"],
62 ["#@#asdf", ElemHideException, "elemhideexception"], 62 ["#@#asdf", ElemHideException, "elemhideexception"],
63 ["foobar##asdf", ElemHideFilter, "elemhide"], 63 ["foobar##asdf", ElemHideFilter, "elemhide"],
64 ["foobar#@#asdf", ElemHideException, "elemhideexception"], 64 ["foobar#@#asdf", ElemHideException, "elemhideexception"],
65 ["foobar##a", ElemHideFilter, "elemhide"], 65 ["foobar##a", ElemHideFilter, "elemhide"],
66 ["foobar#@#a", ElemHideException, "elemhideexception"], 66 ["foobar#@#a", ElemHideException, "elemhideexception"],
67 67
68 ["foobar#asdf", BlockingFilter, "blocking"], 68 ["foobar#asdf", BlockingFilter, "blocking"],
69 ["foobar|foobas##asdf", BlockingFilter, "blocking"], 69 ["foobar|foobas##asdf", BlockingFilter, "blocking"],
70 ["foobar##asdf{asdf}", BlockingFilter, "blocking"], 70 ["foobar##asdf{asdf}", ElemHideFilter, "elemhide"],
71 ["foobar##", BlockingFilter, "blocking"], 71 ["foobar##", BlockingFilter, "blocking"],
72 ["foobar#@#", BlockingFilter, "blocking"], 72 ["foobar#@#", BlockingFilter, "blocking"],
73 ["asdf$foobar", InvalidFilter, "invalid"], 73 ["asdf$foobar", InvalidFilter, "invalid"],
74 ["asdf$image,foobar", InvalidFilter, "invalid"], 74 ["asdf$image,foobar", InvalidFilter, "invalid"],
75 ["asdf$image=foobar", BlockingFilter, "blocking"], 75 ["asdf$image=foobar", BlockingFilter, "blocking"],
76 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking"], 76 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking"],
77 77
78 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"], 78 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"],
79 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep tion"], 79 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep tion"],
80 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter , "elemhideemulation"], 80 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter , "elemhideemulation"],
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 344
345 test.done(); 345 test.done();
346 }; 346 };
347 347
348 exports.testElemHideSelector = function(test) 348 exports.testElemHideSelector = function(test)
349 { 349 {
350 function doTest(text, selector, selectorDomain) 350 function doTest(text, selector, selectorDomain)
351 { 351 {
352 let filter = Filter.fromText(text); 352 let filter = Filter.fromText(text);
353 test.equal(filter.selector, selector, "Correct selector for " + text); 353 test.equal(filter.selector, selector, "Correct selector for " + text);
354
355 let actualDomains = filter.selectorDomain.split(",").sort().join(","); 354 let actualDomains = filter.selectorDomain.split(",").sort().join(",");
356 let expectedDomains = selectorDomain.split(",").sort().join(","); 355 let expectedDomains = selectorDomain.split(",").sort().join(",");
357 test.equal(actualDomains, expectedDomains, "Correct domains list for " + tex t); 356 test.equal(actualDomains, expectedDomains, "Correct domains list for " + tex t);
358 357
359 filter.delete(); 358 filter.delete();
360 } 359 }
361 360
362 let tests = [ 361 let tests = [
363 ["##foobar", "foobar", ""], 362 ["##foobar", "foobar", ""],
364 ["~example.com##foobar", "foobar", ""], 363 ["~example.com##foobar", "foobar", ""],
365 ["example.com##body > div:first-child", "body > div:first-child", "example.c om"], 364 ["example.com##body > div:first-child", "body > div:first-child", "example.c om"],
366 ["xYz,~example.com##foobar:not(whatever)", "foobar:not(whatever)", "xyz"], 365 ["xYz,~example.com##foobar:not(whatever)", "foobar:not(whatever)", "xyz"],
367 ["~xyz,com,~abc.com,example.info##foobar", "foobar", "com,example.info"], 366 ["~xyz,com,~abc.com,example.info##foobar", "foobar", "com,example.info"],
368 ["foo,bar,bas,bam##foobar", "foobar", "foo,bar,bas,bam"], 367 ["foo,bar,bas,bam##foobar", "foobar", "foo,bar,bas,bam"],
369 ["foo.com##x[-abp-properties='abc']y", "x[-abp-properties='abc']y", "foo.com "], 368 ["foo.com##x[-abp-properties='abc']y", "x[-abp-properties='abc']y", "foo.com "],
370 369
371 // Good idea to test this? Maybe consider behavior undefined in this case. 370 // Good idea to test this? Maybe consider behavior undefined in this case.
372 ["foo,bar,bas,~bar##foobar", "foobar", "foo,bas"] 371 ["foo,bar,bas,~bar##foobar", "foobar", "foo,bas"]
373 ]; 372 ];
374 373
375 for (let [text, selector, selectorDomain] of tests) 374 for (let [text, selector, selectorDomain] of tests)
376 { 375 {
377 doTest(text, selector, selectorDomain); 376 doTest(text, selector, selectorDomain);
378 doTest(text.replace("##", "#@#"), selector, selectorDomain); 377 doTest(text.replace("##", "#@#"), selector, selectorDomain);
379 } 378 }
380 379
381 test.done(); 380 test.done();
382 }; 381 };
383 382
383 exports.testElemHideRulesWithBraces = function(test)
384 {
385 let filter = Filter.fromText("###foo{color: red}");
386 test.equal(filter.type, "elemhide");
387 test.equal(filter.selector, "#foo\\x7B color: red\\x7D ");
388 filter.delete();
389
390 test.done();
391 };
392
384 exports.testNotifications = function(test) 393 exports.testNotifications = function(test)
385 { 394 {
386 function checkNotifications(action, expected, message) 395 function checkNotifications(action, expected, message)
387 { 396 {
388 let result = null; 397 let result = null;
389 let listener = (topic, filter) => 398 let listener = (topic, filter) =>
390 { 399 {
391 if (result) 400 if (result)
392 test.ok(false, "Got more that one notification - " + message); 401 test.ok(false, "Got more that one notification - " + message);
393 else 402 else
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 filter.hitCount++; 440 filter.hitCount++;
432 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); 441 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts");
433 checkNotifications(() => 442 checkNotifications(() =>
434 { 443 {
435 filter.hitCount = 0; 444 filter.hitCount = 0;
436 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); 445 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts");
437 446
438 filter.delete(); 447 filter.delete();
439 test.done(); 448 test.done();
440 }; 449 };
OLDNEW
« no previous file with comments | « compiled/filter/ElemHideBase.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld