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: Fix test Created Nov. 21, 2017, 5:42 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"],
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}", ElemHideFilter, "elemhide"], 72 ["foobar##asdf{asdf}", ElemHideFilter, "elemhide"],
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)
107 test.equal(filter.collapse, collapse);
108 else
109 test.equal(filter.collapse, undefined);
104 if (type == InvalidFilter) 110 if (type == InvalidFilter)
105 test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); 111 test.ok(filter.reason, "Invalid filter " + text + " has a reason set");
106 filter.delete(); 112 filter.delete();
107 } 113 }
108 test.done(); 114 test.done();
109 }; 115 };
110 116
111 exports.testClassHierarchy = function(test) 117 exports.testClassHierarchy = function(test)
112 { 118 {
113 let allClasses = [ 119 let allClasses = [
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 234 }
229 235
230 test.done(); 236 test.done();
231 }; 237 };
232 238
233 exports.testSerialize = function(test) 239 exports.testSerialize = function(test)
234 { 240 {
235 // Comment 241 // Comment
236 let filter = Filter.fromText("! serialize"); 242 let filter = Filter.fromText("! serialize");
237 test.equal(filter.serialize(), "[Filter]\ntext=! serialize\n"); 243 test.equal(filter.serialize(), "[Filter]\ntext=! serialize\n");
244 test.equal(filter.collapse, undefined);
238 filter.delete(); 245 filter.delete();
239 246
240 // Blocking filter 247 // Blocking filter
241 filter = Filter.fromText("serialize"); 248 filter = Filter.fromText("serialize");
242 test.equal(filter.serialize(), "[Filter]\ntext=serialize\n"); 249 test.equal(filter.serialize(), "[Filter]\ntext=serialize\n");
243 filter.disabled = true; 250 filter.disabled = true;
244 test.equal(filter.serialize(), "[Filter]\ntext=serialize\ndisabled=true\n"); 251 test.equal(filter.serialize(), "[Filter]\ntext=serialize\ndisabled=true\n");
245 filter.disabled = false; 252 filter.disabled = false;
246 filter.hitCount = 10; 253 filter.hitCount = 10;
247 filter.lastHit = 12; 254 filter.lastHit = 12;
248 test.equal(filter.serialize(), "[Filter]\ntext=serialize\nhitCount=10\nlastHit =12\n"); 255 test.equal(filter.serialize(), "[Filter]\ntext=serialize\nhitCount=10\nlastHit =12\n");
256 test.ok(filter.collapse);
249 filter.delete(); 257 filter.delete();
250 258
251 // Invalid filter 259 // Invalid filter
252 filter = Filter.fromText("serialize$foobar"); 260 filter = Filter.fromText("serialize$foobar");
253 test.equal(filter.serialize(), "[Filter]\ntext=serialize$foobar\n"); 261 test.equal(filter.serialize(), "[Filter]\ntext=serialize$foobar\n");
254 filter.delete(); 262 filter.delete();
255 263
256 // Element hiding filter 264 // Element hiding filter
257 filter = Filter.fromText("example.com##serialize"); 265 filter = Filter.fromText("example.com##serialize");
258 test.equal(filter.serialize(), "[Filter]\ntext=example.com##serialize\n"); 266 test.equal(filter.serialize(), "[Filter]\ntext=example.com##serialize\n");
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 filter.hitCount++; 452 filter.hitCount++;
445 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); 453 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts");
446 checkNotifications(() => 454 checkNotifications(() =>
447 { 455 {
448 filter.hitCount = 0; 456 filter.hitCount = 0;
449 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); 457 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts");
450 458
451 filter.delete(); 459 filter.delete();
452 test.done(); 460 test.done();
453 }; 461 };
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