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

Delta Between Two Patch Sets: test/filterClasses.js

Issue 29361668: Issue 4394 - Create a filter class for element hiding emulation filters (Closed) Base URL: https://bitbucket.org/fhd/adblockpluscore
Left Patch Set: Address Wladimir's comments Created Nov. 21, 2016, 2:34 p.m.
Right Patch Set: Improve compliance with the 80 column rule Created Nov. 21, 2016, 8:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/elemHideEmulation.js ('k') | test/filterListener.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 22 matching lines...) Expand all
33 33
34 let t = null; 34 let t = null;
35 let defaultTypes = null; 35 let defaultTypes = null;
36 36
37 exports.setUp = function(callback) 37 exports.setUp = function(callback)
38 { 38 {
39 let sandboxedRequire = createSandbox(); 39 let sandboxedRequire = createSandbox();
40 ( 40 (
41 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, 41 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter,
42 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, 42 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter,
43 ElemHideException, ElemHideEmulationFilter} = sandboxedRequire("../lib/filt erClasses") 43 ElemHideException,
kzar 2016/11/21 16:24:55 Nit: This and some of the other lines you've modif
Felix Dahlke 2016/11/21 17:26:12 I'd actually prefer to leave those alone as part o
kzar 2016/11/21 19:18:22 On 2016/11/21 17:26:12, Felix Dahlke wrote:
Felix Dahlke 2016/11/21 20:11:48 Fair enough, I fixed all lines I'm touching know,
44 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses")
44 ); 45 );
45 t = RegExpFilter.typeMap; 46 t = RegExpFilter.typeMap;
46 defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP | 47 defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP |
47 t.GENERICHIDE | t.GENERICBLOCK); 48 t.GENERICHIDE | t.GENERICBLOCK);
48 49
49 callback(); 50 callback();
50 }; 51 };
51 52
52 function serializeFilter(filter) 53 function serializeFilter(filter)
53 { 54 {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 else if (/^(\w+)/.test(entry)) 126 else if (/^(\w+)/.test(entry))
126 hasProperty[RegExp.$1] = true; 127 hasProperty[RegExp.$1] = true;
127 } 128 }
128 129
129 function addProperty(prop, value) 130 function addProperty(prop, value)
130 { 131 {
131 if (!(prop in hasProperty)) 132 if (!(prop in hasProperty))
132 expected.push(prop + "=" + value); 133 expected.push(prop + "=" + value);
133 } 134 }
134 135
135 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || type == "elemhideexception" || type == "elemhideemulation") 136 if (type == "whitelist" || type == "filterlist" || type == "elemhide" ||
137 type == "elemhideexception" || type == "elemhideemulation")
136 { 138 {
137 addProperty("disabled", "false"); 139 addProperty("disabled", "false");
138 addProperty("lastHit", "0"); 140 addProperty("lastHit", "0");
139 addProperty("hitCount", "0"); 141 addProperty("hitCount", "0");
140 } 142 }
141 if (type == "whitelist" || type == "filterlist") 143 if (type == "whitelist" || type == "filterlist")
142 { 144 {
143 addProperty("contentType", 0x7FFFFFFF & ~( 145 addProperty("contentType", 0x7FFFFFFF & ~(
144 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE | 146 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE |
145 RegExpFilter.typeMap.POPUP | RegExpFilter.typeMap.GENERICHIDE | 147 RegExpFilter.typeMap.POPUP | RegExpFilter.typeMap.GENERICHIDE |
146 RegExpFilter.typeMap.GENERICBLOCK 148 RegExpFilter.typeMap.GENERICBLOCK
147 )); 149 ));
148 addProperty("matchCase", "false"); 150 addProperty("matchCase", "false");
149 addProperty("thirdParty", "null"); 151 addProperty("thirdParty", "null");
150 addProperty("domains", ""); 152 addProperty("domains", "");
151 addProperty("sitekeys", ""); 153 addProperty("sitekeys", "");
152 } 154 }
153 if (type == "filterlist") 155 if (type == "filterlist")
154 { 156 {
155 addProperty("collapse", "null"); 157 addProperty("collapse", "null");
156 } 158 }
157 if (type == "elemhide" || type == "elemhideexception" || type == "elemhideemul ation") 159 if (type == "elemhide" || type == "elemhideexception" ||
160 type == "elemhideemulation")
158 { 161 {
159 addProperty("selectorDomain", ""); 162 addProperty("selectorDomain", "");
160 addProperty("domains", ""); 163 addProperty("domains", "");
161 } 164 }
162 } 165 }
163 166
164 function compareFilter(test, text, expected, postInit) 167 function compareFilter(test, text, expected, postInit)
165 { 168 {
166 addDefaults(expected); 169 addDefaults(expected);
167 170
(...skipping 30 matching lines...) Expand all
198 test.equal(typeof Filter, "function", "typeof Filter"); 201 test.equal(typeof Filter, "function", "typeof Filter");
199 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); 202 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter");
200 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); 203 test.equal(typeof CommentFilter, "function", "typeof CommentFilter");
201 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); 204 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter");
202 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); 205 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter");
203 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); 206 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter");
204 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); 207 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter");
205 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); 208 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase");
206 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); 209 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter");
207 test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); 210 test.equal(typeof ElemHideException, "function", "typeof ElemHideException");
208 test.equal(typeof ElemHideEmulationFilter, "function", "typeof ElemHideEmulati onFilter"); 211 test.equal(typeof ElemHideEmulationFilter, "function",
212 "typeof ElemHideEmulationFilter");
209 213
210 test.done(); 214 test.done();
211 }; 215 };
212 216
213 exports.testComments = function(test) 217 exports.testComments = function(test)
214 { 218 {
215 compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]); 219 compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]);
216 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]); 220 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]);
217 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]); 221 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]);
218 222
219 test.done(); 223 test.done();
220 }; 224 };
221 225
222 exports.testInvalidFilters = function(test) 226 exports.testInvalidFilters = function(test)
223 { 227 {
224 compareFilter(test, "/??/", ["type=invalid", "text=/??/", "reason=filter_inval id_regexp"]); 228 compareFilter(test, "/??/", ["type=invalid", "text=/??/", "reason=filter_inval id_regexp"]);
225 compareFilter(test, "asd$foobar", ["type=invalid", "text=asd$foobar", "reason= filter_unknown_option"]); 229 compareFilter(test, "asd$foobar", ["type=invalid", "text=asd$foobar", "reason= filter_unknown_option"]);
226 compareFilter(test, "#dd(asd)(ddd)", ["type=invalid", "text=#dd(asd)(ddd)", "r eason=filter_elemhide_duplicate_id"]); 230 compareFilter(test, "#dd(asd)(ddd)", ["type=invalid", "text=#dd(asd)(ddd)", "r eason=filter_elemhide_duplicate_id"]);
227 compareFilter(test, "#*", ["type=invalid", "text=#*", "reason=filter_elemhide_ nocriteria"]); 231 compareFilter(test, "#*", ["type=invalid", "text=#*", "reason=filter_elemhide_ nocriteria"]);
228 232
229 function checkElemHideEmulationFilterInvalid(domains) 233 function checkElemHideEmulationFilterInvalid(domains)
230 { 234 {
231 let filterText = domains + "##[-abp-properties='abc']"; 235 let filterText = domains + "##[-abp-properties='abc']";
232 compareFilter(test, filterText, ["type=invalid", "text=" + filterText, "reas on=filter_elemhideemulation_nodomain"]); 236 compareFilter(test, filterText,
237 ["type=invalid", "text=" + filterText,
238 "reason=filter_elemhideemulation_nodomain"]);
233 } 239 }
234 checkElemHideEmulationFilterInvalid(""); 240 checkElemHideEmulationFilterInvalid("");
235 checkElemHideEmulationFilterInvalid("~foo.com"); 241 checkElemHideEmulationFilterInvalid("~foo.com");
236 checkElemHideEmulationFilterInvalid("~foo.com,~bar.com"); 242 checkElemHideEmulationFilterInvalid("~foo.com,~bar.com");
237 checkElemHideEmulationFilterInvalid("foo"); 243 checkElemHideEmulationFilterInvalid("foo");
238 checkElemHideEmulationFilterInvalid("~foo.com,bar"); 244 checkElemHideEmulationFilterInvalid("~foo.com,bar");
239 245
240 test.done(); 246 test.done();
241 }; 247 };
242 248
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 372
367 for (let filterText of emptyDomainFilters) 373 for (let filterText of emptyDomainFilters)
368 { 374 {
369 let filter = Filter.fromText(filterText); 375 let filter = Filter.fromText(filterText);
370 test.ok(filter instanceof InvalidFilter); 376 test.ok(filter instanceof InvalidFilter);
371 test.equal(filter.reason, "filter_invalid_domain"); 377 test.equal(filter.reason, "filter_invalid_domain");
372 } 378 }
373 379
374 test.done(); 380 test.done();
375 }; 381 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld