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

Side by Side Diff: test/filterClasses.js

Issue 29595633: Issue 5870 - Implement the new ElemHideEmulation filter type (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased Created Dec. 5, 2017, 6:04 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/subscriptionClasses.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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 ["foobar#asdf", BlockingFilter, "blocking", 1], 70 ["foobar#asdf", BlockingFilter, "blocking", 1],
71 ["foobar|foobas##asdf", BlockingFilter, "blocking", 1], 71 ["foobar|foobas##asdf", BlockingFilter, "blocking", 1],
72 ["foobar##asdf{asdf}", ElemHideFilter, "elemhide"], 72 ["foobar##asdf{asdf}", ElemHideFilter, "elemhide"],
73 ["foobar##", BlockingFilter, "blocking", 1], 73 ["foobar##", BlockingFilter, "blocking", 1],
74 ["foobar#@#", BlockingFilter, "blocking", 1], 74 ["foobar#@#", BlockingFilter, "blocking", 1],
75 ["asdf$foobar", InvalidFilter, "invalid"], 75 ["asdf$foobar", InvalidFilter, "invalid"],
76 ["asdf$image,foobar", InvalidFilter, "invalid"], 76 ["asdf$image,foobar", InvalidFilter, "invalid"],
77 ["asdf$image=foobar", BlockingFilter, "blocking", 1], 77 ["asdf$image=foobar", BlockingFilter, "blocking", 1],
78 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking", 0], 78 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking", 0],
79 79
80 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"], 80 ["#?#foo:-abp-properties(something)bar", InvalidFilter, "invalid"],
81 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep tion"], 81 ["#@#foo:-abp-properties(something)bar", ElemHideException, "elemhideexcepti on"],
82 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter , "elemhideemulation"], 82 ["example.com#?#foo:-abp-properties(something)bar", ElemHideEmulationFilter, "elemhideemulation"],
83 ["example.com#@#foo[-abp-properties='something']bar", ElemHideException, "el emhideexception"], 83 ["example.com#@#foo:-abp-properties(something)bar", ElemHideException, "elem hideexception"],
84 ["~example.com##foo[-abp-properties='something']bar", InvalidFilter, "invali d"], 84 ["~example.com#?#foo:-abp-properties(something)bar", InvalidFilter, "invalid "],
85 ["~example.com#@#foo[-abp-properties='something']bar", ElemHideException, "e lemhideexception"], 85 ["~example.com#@#foo:-abp-properties(something)bar", ElemHideException, "ele mhideexception"],
86 ["~example.com,~example.info##foo[-abp-properties='something']bar", InvalidF ilter, "invalid"], 86 ["~example.com,~example.info#?#foo:-abp-properties(something)bar", InvalidFi lter, "invalid"],
87 ["~example.com,~example.info#@#foo[-abp-properties='something']bar", ElemHid eException, "elemhideexception"], 87 ["~example.com,~example.info#@#foo:-abp-properties(something)bar", ElemHideE xception, "elemhideexception"],
88 ["~sub.example.com,example.com##foo[-abp-properties='something']bar", ElemHi deEmulationFilter, "elemhideemulation"], 88 ["~sub.example.com,example.com#?#foo:-abp-properties(something)bar", ElemHid eEmulationFilter, "elemhideemulation"],
89 ["~sub.example.com,example.com#@#foo[-abp-properties='something']bar", ElemH ideException, "elemhideexception"], 89 ["~sub.example.com,example.com#@#foo:-abp-properties(something)bar", ElemHid eException, "elemhideexception"],
90 ["example.com,~sub.example.com##foo[-abp-properties='something']bar", ElemHi deEmulationFilter, "elemhideemulation"], 90 ["example.com,~sub.example.com#?#foo:-abp-properties(something)bar", ElemHid eEmulationFilter, "elemhideemulation"],
91 ["example.com,~sub.example.com#@#foo[-abp-properties='something']bar", ElemH ideException, "elemhideexception"], 91 ["example.com,~sub.example.com#@#foo:-abp-properties(something)bar", ElemHid eException, "elemhideexception"],
92 ["example.com##[-abp-properties='something']", ElemHideEmulationFilter, "ele mhideemulation"], 92 ["example.com#?#:-abp-properties(something)", ElemHideEmulationFilter, "elem hideemulation"],
93 ["example.com#@#[-abp-properties='something']", ElemHideException, "elemhide exception"], 93 ["example.com#@#:-abp-properties(something)", ElemHideException, "elemhideex ception"],
94 ["example.com##[-abp-properties=\"something\"]", ElemHideEmulationFilter, "e lemhideemulation"], 94 ["example.com#?#:-abp-properties((something))", ElemHideEmulationFilter, "el emhideemulation"],
95 ["example.com#@#[-abp-properties=\"something\"]", ElemHideException, "elemhi deexception"], 95 ["example.com#@#:-abp-properties((something))", ElemHideException, "elemhide exception"]
96 ["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "ele mhideemulation"],
97 ["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhide exception"]
98 ]; 96 ];
99 for (let [text, type, typeName, collapse] of tests) 97 for (let [text, type, typeName, collapse] of tests)
100 { 98 {
101 let filter = Filter.fromText(text); 99 let filter = Filter.fromText(text);
102 test.ok(filter instanceof Filter, "Got filter for " + text); 100 test.ok(filter instanceof Filter, "Got filter for " + text);
103 test.equal(filter.text, text, "Correct filter text for " + text); 101 test.equal(filter.text, text, "Correct filter text for " + text);
104 test.ok(filter instanceof type, "Correct filter type for " + text); 102 test.ok(filter instanceof type, "Correct filter type for " + text);
105 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam e); 103 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam e);
106 if (filter instanceof BlockingFilter) 104 if (filter instanceof BlockingFilter)
107 test.equal(filter.collapse, collapse); 105 test.equal(filter.collapse, collapse);
(...skipping 13 matching lines...) Expand all
121 RegExpFilter, BlockingFilter, WhitelistFilter, ElemHideBase, 119 RegExpFilter, BlockingFilter, WhitelistFilter, ElemHideBase,
122 ElemHideFilter, ElemHideException, ElemHideEmulationFilter 120 ElemHideFilter, ElemHideException, ElemHideEmulationFilter
123 ]; 121 ];
124 let tests = [ 122 let tests = [
125 ["/asdf??+/", Filter, InvalidFilter], 123 ["/asdf??+/", Filter, InvalidFilter],
126 ["!asdf", Filter, CommentFilter], 124 ["!asdf", Filter, CommentFilter],
127 ["asdf", Filter, ActiveFilter, RegExpFilter, BlockingFilter], 125 ["asdf", Filter, ActiveFilter, RegExpFilter, BlockingFilter],
128 ["@@asdf", Filter, ActiveFilter, RegExpFilter, WhitelistFilter], 126 ["@@asdf", Filter, ActiveFilter, RegExpFilter, WhitelistFilter],
129 ["##asdf", Filter, ActiveFilter, ElemHideBase, ElemHideFilter], 127 ["##asdf", Filter, ActiveFilter, ElemHideBase, ElemHideFilter],
130 ["#@#asdf", Filter, ActiveFilter, ElemHideBase, ElemHideException], 128 ["#@#asdf", Filter, ActiveFilter, ElemHideBase, ElemHideException],
131 ["example.com##[-abp-properties='something']", Filter, ActiveFilter, ElemHid eBase, ElemHideEmulationFilter] 129 ["example.com#?#:-abp-properties(something)", Filter, ActiveFilter, ElemHide Base, ElemHideEmulationFilter]
132 ]; 130 ];
133 131
134 for (let list of tests) 132 for (let list of tests)
135 { 133 {
136 let filter = Filter.fromText(list.shift()); 134 let filter = Filter.fromText(list.shift());
137 for (let cls of list) 135 for (let cls of list)
138 { 136 {
139 test.ok(filter instanceof cls, 137 test.ok(filter instanceof cls,
140 "Testing correct superclass for filter " + filter.text); 138 "Testing correct superclass for filter " + filter.text);
141 } 139 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 filter.delete(); 268 filter.delete();
271 269
272 test.done(); 270 test.done();
273 }; 271 };
274 272
275 exports.testInvalidReasons = function(test) 273 exports.testInvalidReasons = function(test)
276 { 274 {
277 let tests = [ 275 let tests = [
278 ["/??/", "filter_invalid_regexp"], 276 ["/??/", "filter_invalid_regexp"],
279 ["asd$foobar", "filter_unknown_option"], 277 ["asd$foobar", "filter_unknown_option"],
280 ["~foo.com##[-abp-properties='abc']", "filter_elemhideemulation_nodomain"] 278 ["~foo.com#?#:-abp-properties(abc)", "filter_elemhideemulation_nodomain"]
281 ]; 279 ];
282 280
283 for (let [text, reason] of tests) 281 for (let [text, reason] of tests)
284 { 282 {
285 let filter = Filter.fromText(text); 283 let filter = Filter.fromText(text);
286 test.equals(filter.reason, reason, "Reason why filter " + text + " is invali d"); 284 test.equals(filter.reason, reason, "Reason why filter " + text + " is invali d");
287 filter.delete(); 285 filter.delete();
288 } 286 }
289 287
290 test.done(); 288 test.done();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 filter.delete(); 363 filter.delete();
366 } 364 }
367 365
368 let tests = [ 366 let tests = [
369 ["##foobar", "foobar", ""], 367 ["##foobar", "foobar", ""],
370 ["~example.com##foobar", "foobar", ""], 368 ["~example.com##foobar", "foobar", ""],
371 ["example.com##body > div:first-child", "body > div:first-child", "example.c om"], 369 ["example.com##body > div:first-child", "body > div:first-child", "example.c om"],
372 ["xYz,~example.com##foobar:not(whatever)", "foobar:not(whatever)", "xyz"], 370 ["xYz,~example.com##foobar:not(whatever)", "foobar:not(whatever)", "xyz"],
373 ["~xyz,com,~abc.com,example.info##foobar", "foobar", "com,example.info"], 371 ["~xyz,com,~abc.com,example.info##foobar", "foobar", "com,example.info"],
374 ["foo,bar,bas,bam##foobar", "foobar", "foo,bar,bas,bam"], 372 ["foo,bar,bas,bam##foobar", "foobar", "foo,bar,bas,bam"],
375 ["foo.com##x[-abp-properties='abc']y", "x[-abp-properties='abc']y", "foo.com "], 373 ["foo.com##x:-abp-properties(abc)y", "x:-abp-properties(abc)y", "foo.com"],
376 374
377 // Good idea to test this? Maybe consider behavior undefined in this case. 375 // Good idea to test this? Maybe consider behavior undefined in this case.
378 ["foo,bar,bas,~bar##foobar", "foobar", "foo,bas"] 376 ["foo,bar,bas,~bar##foobar", "foobar", "foo,bas"]
379 ]; 377 ];
380 378
381 for (let [text, selector, selectorDomain] of tests) 379 for (let [text, selector, selectorDomain] of tests)
382 { 380 {
383 doTest(text, selector, selectorDomain); 381 doTest(text, selector, selectorDomain);
384 doTest(text.replace("##", "#@#"), selector, selectorDomain); 382 doTest(text.replace("##", "#@#"), selector, selectorDomain);
385 } 383 }
386 384
387 test.done(); 385 test.done();
388 }; 386 };
389 387
390 exports.testElemHideRulesWithBraces = function(test) 388 exports.testElemHideRulesWithBraces = function(test)
391 { 389 {
392 let filter = Filter.fromText("###foo{color: red}"); 390 let filter = Filter.fromText("###foo{color: red}");
393 test.equal(filter.type, "elemhide"); 391 test.equal(filter.type, "elemhide");
394 test.equal(filter.selector, "#foo\\7B color: red\\7D "); 392 test.equal(filter.selector, "#foo\\7B color: red\\7D ");
395 filter.delete(); 393 filter.delete();
396 394
397 filter = Filter.fromText("foo.com##[-abp-properties='/margin: [3-4]{2}/']"); 395 filter = Filter.fromText("foo.com#?#[-abp-properties='/margin: [3-4]{2}/']");
398 test.equal(filter.type, "elemhideemulation"); 396 test.equal(filter.type, "elemhideemulation");
399 test.equal(filter.selector, "[-abp-properties='/margin: [3-4]\\7B 2\\7D /']"); 397 test.equal(filter.selector, ":-abp-properties(/margin: [3-4]\\7B 2\\7D /)");
400 filter.delete(); 398 filter.delete();
401 399
402 test.done(); 400 test.done();
403 }; 401 };
404 402
405 exports.testNotifications = function(test) 403 exports.testNotifications = function(test)
406 { 404 {
407 function checkNotifications(action, expected, message) 405 function checkNotifications(action, expected, message)
408 { 406 {
409 let result = null; 407 let result = null;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 filter.hitCount++; 450 filter.hitCount++;
453 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); 451 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts");
454 checkNotifications(() => 452 checkNotifications(() =>
455 { 453 {
456 filter.hitCount = 0; 454 filter.hitCount = 0;
457 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); 455 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts");
458 456
459 filter.delete(); 457 filter.delete();
460 test.done(); 458 test.done();
461 }; 459 };
OLDNEW
« no previous file with comments | « test/elemHideEmulation.js ('k') | test/subscriptionClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld