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

Side by Side Diff: test/filterClasses.js

Issue 29361640: Issue 4593 - Support regular expressions for CSS property matching (Closed) Base URL: https://bitbucket.org/fhd/adblockpluscore
Patch Set: Created Nov. 3, 2016, 11:40 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
« lib/filterClasses.js ('K') | « lib/filterClasses.js ('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-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
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=cssrule", "text =foo.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-pr operties='abc']", "domains=FOO.COM", "regexp=abc"]); 357 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=cssrule", "text =foo.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-pr operties='abc']", "domains=FOO.COM", "regexp=abc"]);
358 compareFilter(test, "foo.com,~bar.com##[-abp-properties='abc']", ["type=cssrul e", "text=foo.com,~bar.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR.COM", "regexp=abc"]); 358 compareFilter(test, "foo.com,~bar.com##[-abp-properties='abc']", ["type=cssrul e", "text=foo.com,~bar.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR.COM", "regexp=abc"]);
359 compareFilter(test, "foo.com,~bar##[-abp-properties='abc']", ["type=cssrule", "text=foo.com,~bar##[-abp-properties='abc']", "selectorDomain=foo.com", "selecto r=[-abp-properties='abc']", "domains=FOO.COM|~BAR", "regexp=abc"]); 359 compareFilter(test, "foo.com,~bar##[-abp-properties='abc']", ["type=cssrule", "text=foo.com,~bar##[-abp-properties='abc']", "selectorDomain=foo.com", "selecto r=[-abp-properties='abc']", "domains=FOO.COM|~BAR", "regexp=abc"]);
360 compareFilter(test, "~foo.com,bar.com##[-abp-properties='abc']", ["type=cssrul e", "text=~foo.com,bar.com##[-abp-properties='abc']", "selectorDomain=bar.com", "selector=[-abp-properties='abc']", "domains=BAR.COM|~FOO.COM", "regexp=abc"]); 360 compareFilter(test, "~foo.com,bar.com##[-abp-properties='abc']", ["type=cssrul e", "text=~foo.com,bar.com##[-abp-properties='abc']", "selectorDomain=bar.com", "selector=[-abp-properties='abc']", "domains=BAR.COM|~FOO.COM", "regexp=abc"]);
361 361
362 compareFilter(test, "##[-abp-properties='']", ["type=elemhide", "text=##[-abp- properties='']", "selector=[-abp-properties='']"]); 362 compareFilter(test, "##[-abp-properties='']", ["type=elemhide", "text=##[-abp- properties='']", "selector=[-abp-properties='']"]);
363 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#@#[-abp-properties='abc']", ["type=elemhideexcept ion", "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selec tor=[-abp-properties='abc']", "domains=FOO.COM"]);
364 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=cssrule ", "text=foo.com##aaa [-abp-properties='abc'] bbb", "selectorDomain=foo.com", "s elector=aaa [-abp-properties='abc'] bbb", "domains=FOO.COM", "prefix=aaa ", "reg exp=abc", "suffix= bbb"]); 364 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=cssrule ", "text=foo.com##aaa [-abp-properties='abc'] bbb", "selectorDomain=foo.com", "s elector=aaa [-abp-properties='abc'] bbb", "domains=FOO.COM", "prefix=aaa ", "reg exp=abc", "suffix= bbb"]);
365 compareFilter(test, "foo.com##[-abp-properties='|background-image: url(data:*) ']", ["type=cssrule", "text=foo.com##[-abp-properties='|background-image: url(da ta:*)']", "selectorDomain=foo.com", "selector=[-abp-properties='|background-imag e: url(data:*)']", "domains=FOO.COM", "regexp=^background\\-image\\:\\ url\\(dat a\\:.*\\)"]); 365 compareFilter(test, "foo.com##[-abp-properties='|background-image: url(data:*) ']", ["type=cssrule", "text=foo.com##[-abp-properties='|background-image: url(da ta:*)']", "selectorDomain=foo.com", "selector=[-abp-properties='|background-imag e: url(data:*)']", "domains=FOO.COM", "regexp=^background\\-image\\:\\ url\\(dat a\\:.*\\)"]);
366 366
367 // Test regexp property matching
368 compareFilter(test, "foo.com##[-abp-properties='/abc']", ["type=cssrule", "tex t=foo.com##[-abp-properties='/abc']", "selectorDomain=foo.com", "selector=[-abp- properties='/abc']", "domains=FOO.COM", "regexp=\\/abc"]);
369 compareFilter(test, "foo.com##[-abp-properties='abc/']", ["type=cssrule", "tex t=foo.com##[-abp-properties='abc/']", "selectorDomain=foo.com", "selector=[-abp- properties='abc/']", "domains=FOO.COM", "regexp=abc\\/"]);
370 compareFilter(test, "foo.com##[-abp-properties='/abc/']", ["type=cssrule", "te xt=foo.com##[-abp-properties='/abc/']", "selectorDomain=foo.com", "selector=[-ab p-properties='/abc/']", "domains=FOO.COM", "regexp=abc"]);
371
367 test.done(); 372 test.done();
368 }; 373 };
369 374
370 exports.testEmptyElemHideDomains = function(test) 375 exports.testEmptyElemHideDomains = function(test)
371 { 376 {
372 let emptyDomainFilters = [ 377 let emptyDomainFilters = [
373 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", 378 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector",
374 ",foo.com##selector", "foo.com,~##selector", 379 ",foo.com##selector", "foo.com,~##selector",
375 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" 380 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector"
376 ]; 381 ];
377 382
378 for (let filterText of emptyDomainFilters) 383 for (let filterText of emptyDomainFilters)
379 { 384 {
380 let filter = Filter.fromText(filterText); 385 let filter = Filter.fromText(filterText);
381 test.ok(filter instanceof InvalidFilter); 386 test.ok(filter instanceof InvalidFilter);
382 test.equal(filter.reason, "filter_invalid_domain"); 387 test.equal(filter.reason, "filter_invalid_domain");
383 } 388 }
384 389
385 test.done(); 390 test.done();
386 }; 391 };
OLDNEW
« lib/filterClasses.js ('K') | « lib/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld