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

Side by Side Diff: test/filterClasses.js

Issue 29574665: Issue 5159 - Expose collapse property for BlockingFilter (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: added test for the property Created Nov. 21, 2017, 3:37 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/RegExpFilter.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 30 matching lines...) Expand all
41 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, 41 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter,
42 ElemHideException, ElemHideEmulationFilter 42 ElemHideException, ElemHideEmulationFilter
43 } = sandboxedRequire("../lib/filterClasses") 43 } = sandboxedRequire("../lib/filterClasses")
44 ); 44 );
45 ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier")); 45 ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier"));
46 callback(); 46 callback();
47 }; 47 };
48 48
49 exports.testFromText = function(test) 49 exports.testFromText = function(test)
50 { 50 {
51 // fields are:
52 // text, type, typeName, collapse (optional, BlockingFilter only)
51 let tests = [ 53 let tests = [
52 ["!asdf", CommentFilter, "comment"], 54 ["!asdf", CommentFilter, "comment"],
53 ["asdf", BlockingFilter, "blocking"], 55 ["asdf", BlockingFilter, "blocking", 1],
54 ["asdf$image,~collapse", BlockingFilter, "blocking"], 56 ["asdf$image,~collapse", BlockingFilter, "blocking", 0],
55 ["/asdf/", BlockingFilter, "blocking"], 57 ["/asdf/", BlockingFilter, "blocking", 1],
56 ["/asdf??+/", InvalidFilter, "invalid"], 58 ["/asdf??+/", InvalidFilter, "invalid"],
57 ["@@asdf", WhitelistFilter, "whitelist"], 59 ["@@asdf", WhitelistFilter, "whitelist"],
58 ["@@asdf$image,~collapse", WhitelistFilter, "whitelist"], 60 ["@@asdf$image,~collapse", WhitelistFilter, "whitelist", 0],
59 ["@@/asdf/", WhitelistFilter, "whitelist"], 61 ["@@/asdf/", WhitelistFilter, "whitelist"],
60 ["@@/asdf??+/", InvalidFilter, "invalid"], 62 ["@@/asdf??+/", InvalidFilter, "invalid"],
61 ["##asdf", ElemHideFilter, "elemhide"], 63 ["##asdf", ElemHideFilter, "elemhide"],
62 ["#@#asdf", ElemHideException, "elemhideexception"], 64 ["#@#asdf", ElemHideException, "elemhideexception"],
63 ["foobar##asdf", ElemHideFilter, "elemhide"], 65 ["foobar##asdf", ElemHideFilter, "elemhide"],
64 ["foobar#@#asdf", ElemHideException, "elemhideexception"], 66 ["foobar#@#asdf", ElemHideException, "elemhideexception"],
65 ["foobar##a", ElemHideFilter, "elemhide"], 67 ["foobar##a", ElemHideFilter, "elemhide"],
66 ["foobar#@#a", ElemHideException, "elemhideexception"], 68 ["foobar#@#a", ElemHideException, "elemhideexception"],
67 69
68 ["foobar#asdf", BlockingFilter, "blocking"], 70 ["foobar#asdf", BlockingFilter, "blocking", 1],
69 ["foobar|foobas##asdf", BlockingFilter, "blocking"], 71 ["foobar|foobas##asdf", BlockingFilter, "blocking", 1],
70 ["foobar##asdf{asdf}", BlockingFilter, "blocking"], 72 ["foobar##asdf{asdf}", BlockingFilter, "blocking", 1],
71 ["foobar##", BlockingFilter, "blocking"], 73 ["foobar##", BlockingFilter, "blocking", 1],
72 ["foobar#@#", BlockingFilter, "blocking"], 74 ["foobar#@#", BlockingFilter, "blocking", 1],
73 ["asdf$foobar", InvalidFilter, "invalid"], 75 ["asdf$foobar", InvalidFilter, "invalid"],
74 ["asdf$image,foobar", InvalidFilter, "invalid"], 76 ["asdf$image,foobar", InvalidFilter, "invalid"],
75 ["asdf$image=foobar", BlockingFilter, "blocking"], 77 ["asdf$image=foobar", BlockingFilter, "blocking", 1],
76 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking"], 78 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking", 0],
77 79
78 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"], 80 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"],
79 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep tion"], 81 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep tion"],
80 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter , "elemhideemulation"], 82 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter , "elemhideemulation"],
81 ["example.com#@#foo[-abp-properties='something']bar", ElemHideException, "el emhideexception"], 83 ["example.com#@#foo[-abp-properties='something']bar", ElemHideException, "el emhideexception"],
82 ["~example.com##foo[-abp-properties='something']bar", InvalidFilter, "invali d"], 84 ["~example.com##foo[-abp-properties='something']bar", InvalidFilter, "invali d"],
83 ["~example.com#@#foo[-abp-properties='something']bar", ElemHideException, "e lemhideexception"], 85 ["~example.com#@#foo[-abp-properties='something']bar", ElemHideException, "e lemhideexception"],
84 ["~example.com,~example.info##foo[-abp-properties='something']bar", InvalidF ilter, "invalid"], 86 ["~example.com,~example.info##foo[-abp-properties='something']bar", InvalidF ilter, "invalid"],
85 ["~example.com,~example.info#@#foo[-abp-properties='something']bar", ElemHid eException, "elemhideexception"], 87 ["~example.com,~example.info#@#foo[-abp-properties='something']bar", ElemHid eException, "elemhideexception"],
86 ["~sub.example.com,example.com##foo[-abp-properties='something']bar", ElemHi deEmulationFilter, "elemhideemulation"], 88 ["~sub.example.com,example.com##foo[-abp-properties='something']bar", ElemHi deEmulationFilter, "elemhideemulation"],
87 ["~sub.example.com,example.com#@#foo[-abp-properties='something']bar", ElemH ideException, "elemhideexception"], 89 ["~sub.example.com,example.com#@#foo[-abp-properties='something']bar", ElemH ideException, "elemhideexception"],
88 ["example.com,~sub.example.com##foo[-abp-properties='something']bar", ElemHi deEmulationFilter, "elemhideemulation"], 90 ["example.com,~sub.example.com##foo[-abp-properties='something']bar", ElemHi deEmulationFilter, "elemhideemulation"],
89 ["example.com,~sub.example.com#@#foo[-abp-properties='something']bar", ElemH ideException, "elemhideexception"], 91 ["example.com,~sub.example.com#@#foo[-abp-properties='something']bar", ElemH ideException, "elemhideexception"],
90 ["example.com##[-abp-properties='something']", ElemHideEmulationFilter, "ele mhideemulation"], 92 ["example.com##[-abp-properties='something']", ElemHideEmulationFilter, "ele mhideemulation"],
91 ["example.com#@#[-abp-properties='something']", ElemHideException, "elemhide exception"], 93 ["example.com#@#[-abp-properties='something']", ElemHideException, "elemhide exception"],
92 ["example.com##[-abp-properties=\"something\"]", ElemHideEmulationFilter, "e lemhideemulation"], 94 ["example.com##[-abp-properties=\"something\"]", ElemHideEmulationFilter, "e lemhideemulation"],
93 ["example.com#@#[-abp-properties=\"something\"]", ElemHideException, "elemhi deexception"], 95 ["example.com#@#[-abp-properties=\"something\"]", ElemHideException, "elemhi deexception"],
94 ["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "ele mhideemulation"], 96 ["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "ele mhideemulation"],
95 ["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhide exception"] 97 ["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhide exception"]
96 ]; 98 ];
97 for (let [text, type, typeName] of tests) 99 for (let [text, type, typeName, collapse] of tests)
98 { 100 {
99 let filter = Filter.fromText(text); 101 let filter = Filter.fromText(text);
100 test.ok(filter instanceof Filter, "Got filter for " + text); 102 test.ok(filter instanceof Filter, "Got filter for " + text);
101 test.equal(filter.text, text, "Correct filter text for " + text); 103 test.equal(filter.text, text, "Correct filter text for " + text);
102 test.ok(filter instanceof type, "Correct filter type for " + text); 104 test.ok(filter instanceof type, "Correct filter type for " + text);
103 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam e); 105 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam e);
106 if (filter instanceof BlockingFilter)
sergei 2017/11/21 16:17:01 What about checking that `filter.collapse` and `co
hub 2017/11/21 17:42:47 done.
107 test.equal(filter.collapse, collapse);
104 if (type == InvalidFilter) 108 if (type == InvalidFilter)
105 test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); 109 test.ok(filter.reason, "Invalid filter " + text + " has a reason set");
106 filter.delete(); 110 filter.delete();
107 } 111 }
108 test.done(); 112 test.done();
109 }; 113 };
110 114
111 exports.testClassHierarchy = function(test) 115 exports.testClassHierarchy = function(test)
112 { 116 {
113 let allClasses = [ 117 let allClasses = [
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 232 }
229 233
230 test.done(); 234 test.done();
231 }; 235 };
232 236
233 exports.testSerialize = function(test) 237 exports.testSerialize = function(test)
234 { 238 {
235 // Comment 239 // Comment
236 let filter = Filter.fromText("! serialize"); 240 let filter = Filter.fromText("! serialize");
237 test.equal(filter.serialize(), "[Filter]\ntext=! serialize\n"); 241 test.equal(filter.serialize(), "[Filter]\ntext=! serialize\n");
242 test.equal(filter.collapse, undefined);
238 filter.delete(); 243 filter.delete();
239 244
240 // Blocking filter 245 // Blocking filter
241 filter = Filter.fromText("serialize"); 246 filter = Filter.fromText("serialize");
242 test.equal(filter.serialize(), "[Filter]\ntext=serialize\n"); 247 test.equal(filter.serialize(), "[Filter]\ntext=serialize\n");
243 filter.disabled = true; 248 filter.disabled = true;
244 test.equal(filter.serialize(), "[Filter]\ntext=serialize\ndisabled=true\n"); 249 test.equal(filter.serialize(), "[Filter]\ntext=serialize\ndisabled=true\n");
245 filter.disabled = false; 250 filter.disabled = false;
246 filter.hitCount = 10; 251 filter.hitCount = 10;
247 filter.lastHit = 12; 252 filter.lastHit = 12;
248 test.equal(filter.serialize(), "[Filter]\ntext=serialize\nhitCount=10\nlastHit =12\n"); 253 test.equal(filter.serialize(), "[Filter]\ntext=serialize\nhitCount=10\nlastHit =12\n");
254 test.ok(filter.collapse);
249 filter.delete(); 255 filter.delete();
250 256
251 // Invalid filter 257 // Invalid filter
252 filter = Filter.fromText("serialize$foobar"); 258 filter = Filter.fromText("serialize$foobar");
253 test.equal(filter.serialize(), "[Filter]\ntext=serialize$foobar\n"); 259 test.equal(filter.serialize(), "[Filter]\ntext=serialize$foobar\n");
254 filter.delete(); 260 filter.delete();
255 261
256 // Element hiding filter 262 // Element hiding filter
257 filter = Filter.fromText("example.com##serialize"); 263 filter = Filter.fromText("example.com##serialize");
258 test.equal(filter.serialize(), "[Filter]\ntext=example.com##serialize\n"); 264 test.equal(filter.serialize(), "[Filter]\ntext=example.com##serialize\n");
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 filter.hitCount++; 435 filter.hitCount++;
430 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); 436 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts");
431 checkNotifications(() => 437 checkNotifications(() =>
432 { 438 {
433 filter.hitCount = 0; 439 filter.hitCount = 0;
434 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); 440 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts");
435 441
436 filter.delete(); 442 filter.delete();
437 test.done(); 443 test.done();
438 }; 444 };
OLDNEW
« no previous file with comments | « compiled/filter/RegExpFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld