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: properly handle exception filters. some test fixes. Created Nov. 3, 2017, 5:02 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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}", BlockingFilter, "blocking"],
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, "elemhideexcepti on"],
80 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter , "elemhideemulation"], 80 ["example.com#?#foo:-abp-properties(something)bar", ElemHideEmulationFilter, "elemhideemulation"],
81 ["example.com#@#foo[-abp-properties='something']bar", ElemHideException, "el emhideexception"], 81 ["example.com#@#foo:-abp-properties(something)bar", ElemHideException, "elem hideexception"],
82 ["~example.com##foo[-abp-properties='something']bar", InvalidFilter, "invali d"], 82 ["~example.com#?#foo:-abp-properties(something)bar", InvalidFilter, "invalid "],
83 ["~example.com#@#foo[-abp-properties='something']bar", ElemHideException, "e lemhideexception"], 83 ["~example.com#@#foo:-abp-properties(something)bar", ElemHideException, "ele mhideexception"],
84 ["~example.com,~example.info##foo[-abp-properties='something']bar", InvalidF ilter, "invalid"], 84 ["~example.com,~example.info#?#foo:-abp-properties(something)bar", InvalidFi lter, "invalid"],
85 ["~example.com,~example.info#@#foo[-abp-properties='something']bar", ElemHid eException, "elemhideexception"], 85 ["~example.com,~example.info#@#foo:-abp-properties(something)bar", ElemHideE xception, "elemhideexception"],
86 ["~sub.example.com,example.com##foo[-abp-properties='something']bar", ElemHi deEmulationFilter, "elemhideemulation"], 86 ["~sub.example.com,example.com#?#foo:-abp-properties(something)bar", ElemHid eEmulationFilter, "elemhideemulation"],
87 ["~sub.example.com,example.com#@#foo[-abp-properties='something']bar", ElemH ideException, "elemhideexception"], 87 ["~sub.example.com,example.com#@#foo:-abp-properties(something)bar", ElemHid eException, "elemhideexception"],
88 ["example.com,~sub.example.com##foo[-abp-properties='something']bar", ElemHi deEmulationFilter, "elemhideemulation"], 88 ["example.com,~sub.example.com#?#foo:-abp-properties(something)bar", ElemHid eEmulationFilter, "elemhideemulation"],
89 ["example.com,~sub.example.com#@#foo[-abp-properties='something']bar", ElemH ideException, "elemhideexception"], 89 ["example.com,~sub.example.com#@#foo:-abp-properties(something)bar", ElemHid eException, "elemhideexception"],
90 ["example.com##[-abp-properties='something']", ElemHideEmulationFilter, "ele mhideemulation"], 90 ["example.com#?#:-abp-properties(something)", ElemHideEmulationFilter, "elem hideemulation"],
91 ["example.com#@#[-abp-properties='something']", ElemHideException, "elemhide exception"], 91 ["example.com#@#:-abp-properties(something)", ElemHideException, "elemhideex ception"],
92 ["example.com##[-abp-properties=\"something\"]", ElemHideEmulationFilter, "e lemhideemulation"], 92 ["example.com#?#:-abp-properties((something))", ElemHideEmulationFilter, "el emhideemulation"],
93 ["example.com#@#[-abp-properties=\"something\"]", ElemHideException, "elemhi deexception"], 93 ["example.com#@#:-abp-properties((something))", ElemHideException, "elemhide exception"]
94 ["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "ele mhideemulation"],
95 ["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhide exception"]
96 ]; 94 ];
97 for (let [text, type, typeName] of tests) 95 for (let [text, type, typeName] of tests)
98 { 96 {
99 let filter = Filter.fromText(text); 97 let filter = Filter.fromText(text);
100 test.ok(filter instanceof Filter, "Got filter for " + text); 98 test.ok(filter instanceof Filter, "Got filter for " + text);
101 test.equal(filter.text, text, "Correct filter text for " + text); 99 test.equal(filter.text, text, "Correct filter text for " + text);
102 test.ok(filter instanceof type, "Correct filter type for " + text); 100 test.ok(filter instanceof type, "Correct filter type for " + text);
103 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam e); 101 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam e);
104 if (type == InvalidFilter) 102 if (type == InvalidFilter)
105 test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); 103 test.ok(filter.reason, "Invalid filter " + text + " has a reason set");
106 filter.delete(); 104 filter.delete();
107 } 105 }
108 test.done(); 106 test.done();
109 }; 107 };
110 108
111 exports.testClassHierarchy = function(test) 109 exports.testClassHierarchy = function(test)
112 { 110 {
113 let allClasses = [ 111 let allClasses = [
114 Filter, InvalidFilter, CommentFilter, ActiveFilter, 112 Filter, InvalidFilter, CommentFilter, ActiveFilter,
115 RegExpFilter, BlockingFilter, WhitelistFilter, ElemHideBase, 113 RegExpFilter, BlockingFilter, WhitelistFilter, ElemHideBase,
116 ElemHideFilter, ElemHideException, ElemHideEmulationFilter 114 ElemHideFilter, ElemHideException, ElemHideEmulationFilter
117 ]; 115 ];
118 let tests = [ 116 let tests = [
119 ["/asdf??+/", Filter, InvalidFilter], 117 ["/asdf??+/", Filter, InvalidFilter],
120 ["!asdf", Filter, CommentFilter], 118 ["!asdf", Filter, CommentFilter],
121 ["asdf", Filter, ActiveFilter, RegExpFilter, BlockingFilter], 119 ["asdf", Filter, ActiveFilter, RegExpFilter, BlockingFilter],
122 ["@@asdf", Filter, ActiveFilter, RegExpFilter, WhitelistFilter], 120 ["@@asdf", Filter, ActiveFilter, RegExpFilter, WhitelistFilter],
123 ["##asdf", Filter, ActiveFilter, ElemHideBase, ElemHideFilter], 121 ["##asdf", Filter, ActiveFilter, ElemHideBase, ElemHideFilter],
124 ["#@#asdf", Filter, ActiveFilter, ElemHideBase, ElemHideException], 122 ["#@#asdf", Filter, ActiveFilter, ElemHideBase, ElemHideException],
125 ["example.com##[-abp-properties='something']", Filter, ActiveFilter, ElemHid eBase, ElemHideEmulationFilter] 123 ["example.com#?#:-abp-properties(something)", Filter, ActiveFilter, ElemHide Base, ElemHideEmulationFilter]
126 ]; 124 ];
127 125
128 for (let list of tests) 126 for (let list of tests)
129 { 127 {
130 let filter = Filter.fromText(list.shift()); 128 let filter = Filter.fromText(list.shift());
131 for (let cls of list) 129 for (let cls of list)
132 { 130 {
133 test.ok(filter instanceof cls, 131 test.ok(filter instanceof cls,
134 "Testing correct superclass for filter " + filter.text); 132 "Testing correct superclass for filter " + filter.text);
135 } 133 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 filter.delete(); 260 filter.delete();
263 261
264 test.done(); 262 test.done();
265 }; 263 };
266 264
267 exports.testInvalidReasons = function(test) 265 exports.testInvalidReasons = function(test)
268 { 266 {
269 let tests = [ 267 let tests = [
270 ["/??/", "filter_invalid_regexp"], 268 ["/??/", "filter_invalid_regexp"],
271 ["asd$foobar", "filter_unknown_option"], 269 ["asd$foobar", "filter_unknown_option"],
272 ["~foo.com##[-abp-properties='abc']", "filter_elemhideemulation_nodomain"] 270 ["~foo.com#?#:-abp-properties(abc)", "filter_elemhideemulation_nodomain"]
273 ]; 271 ];
274 272
275 for (let [text, reason] of tests) 273 for (let [text, reason] of tests)
276 { 274 {
277 let filter = Filter.fromText(text); 275 let filter = Filter.fromText(text);
278 test.equals(filter.reason, reason, "Reason why filter " + text + " is invali d"); 276 test.equals(filter.reason, reason, "Reason why filter " + text + " is invali d");
279 filter.delete(); 277 filter.delete();
280 } 278 }
281 279
282 test.done(); 280 test.done();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 filter.delete(); 355 filter.delete();
358 } 356 }
359 357
360 let tests = [ 358 let tests = [
361 ["##foobar", "foobar", ""], 359 ["##foobar", "foobar", ""],
362 ["~example.com##foobar", "foobar", ""], 360 ["~example.com##foobar", "foobar", ""],
363 ["example.com##body > div:first-child", "body > div:first-child", "example.c om"], 361 ["example.com##body > div:first-child", "body > div:first-child", "example.c om"],
364 ["xYz,~example.com##foobar:not(whatever)", "foobar:not(whatever)", "xyz"], 362 ["xYz,~example.com##foobar:not(whatever)", "foobar:not(whatever)", "xyz"],
365 ["~xyz,com,~abc.com,example.info##foobar", "foobar", "com,example.info"], 363 ["~xyz,com,~abc.com,example.info##foobar", "foobar", "com,example.info"],
366 ["foo,bar,bas,bam##foobar", "foobar", "foo,bar,bas,bam"], 364 ["foo,bar,bas,bam##foobar", "foobar", "foo,bar,bas,bam"],
367 ["foo.com##x[-abp-properties='abc']y", "x[-abp-properties='abc']y", "foo.com "], 365 ["foo.com##x:-abp-properties(abc)y", "x:-abp-properties(abc)y", "foo.com"],
368 366
369 // Good idea to test this? Maybe consider behavior undefined in this case. 367 // Good idea to test this? Maybe consider behavior undefined in this case.
370 ["foo,bar,bas,~bar##foobar", "foobar", "foo,bas"] 368 ["foo,bar,bas,~bar##foobar", "foobar", "foo,bas"]
371 ]; 369 ];
372 370
373 for (let [text, selector, selectorDomain] of tests) 371 for (let [text, selector, selectorDomain] of tests)
374 { 372 {
375 doTest(text, selector, selectorDomain); 373 doTest(text, selector, selectorDomain);
376 doTest(text.replace("##", "#@#"), selector, selectorDomain); 374 doTest(text.replace("##", "#@#"), selector, selectorDomain);
377 } 375 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 filter.hitCount++; 427 filter.hitCount++;
430 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); 428 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts");
431 checkNotifications(() => 429 checkNotifications(() =>
432 { 430 {
433 filter.hitCount = 0; 431 filter.hitCount = 0;
434 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); 432 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts");
435 433
436 filter.delete(); 434 filter.delete();
437 test.done(); 435 test.done();
438 }; 436 };
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