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

Side by Side Diff: test/filterClasses.js

Issue 29470687: Issue 5344 - Element hiding emulation exceptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 21, 2017, 6:50 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 | « lib/filterClasses.js ('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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 12 matching lines...) Expand all
23 let InvalidFilter = null; 23 let InvalidFilter = null;
24 let CommentFilter = null; 24 let CommentFilter = null;
25 let ActiveFilter = null; 25 let ActiveFilter = null;
26 let RegExpFilter = null; 26 let RegExpFilter = null;
27 let BlockingFilter = null; 27 let BlockingFilter = null;
28 let WhitelistFilter = null; 28 let WhitelistFilter = null;
29 let ElemHideBase = null; 29 let ElemHideBase = null;
30 let ElemHideFilter = null; 30 let ElemHideFilter = null;
31 let ElemHideException = null; 31 let ElemHideException = null;
32 let ElemHideEmulationFilter = null; 32 let ElemHideEmulationFilter = null;
33 let ElemHideEmulationException = null;
33 34
34 let t = null; 35 let t = null;
35 let defaultTypes = null; 36 let defaultTypes = null;
36 37
37 exports.setUp = function(callback) 38 exports.setUp = function(callback)
38 { 39 {
39 let sandboxedRequire = createSandbox(); 40 let sandboxedRequire = createSandbox();
40 ( 41 (
41 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, 42 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter,
42 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, 43 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter,
43 ElemHideException, 44 ElemHideException,
44 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses") 45 ElemHideEmulationFilter,
46 ElemHideEmulationException} = sandboxedRequire("../lib/filterClasses")
45 ); 47 );
46 t = RegExpFilter.typeMap; 48 t = RegExpFilter.typeMap;
47 defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP | 49 defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP |
48 t.GENERICHIDE | t.GENERICBLOCK); 50 t.GENERICHIDE | t.GENERICBLOCK);
49 51
50 callback(); 52 callback();
51 }; 53 };
52 54
53 function serializeFilter(filter) 55 function serializeFilter(filter)
54 { 56 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 result.push("type=whitelist"); 100 result.push("type=whitelist");
99 } 101 }
100 else if (filter instanceof ElemHideBase) 102 else if (filter instanceof ElemHideBase)
101 { 103 {
102 if (filter instanceof ElemHideFilter) 104 if (filter instanceof ElemHideFilter)
103 result.push("type=elemhide"); 105 result.push("type=elemhide");
104 else if (filter instanceof ElemHideException) 106 else if (filter instanceof ElemHideException)
105 result.push("type=elemhideexception"); 107 result.push("type=elemhideexception");
106 else if (filter instanceof ElemHideEmulationFilter) 108 else if (filter instanceof ElemHideEmulationFilter)
107 result.push("type=elemhideemulation"); 109 result.push("type=elemhideemulation");
110 else if (filter instanceof ElemHideEmulationException)
111 result.push("type=elemhideemulationexception");
108 112
109 result.push("selectorDomain=" + (filter.selectorDomain || "")); 113 result.push("selectorDomain=" + (filter.selectorDomain || ""));
110 result.push("selector=" + filter.selector); 114 result.push("selector=" + filter.selector);
111 } 115 }
112 } 116 }
113 return result; 117 return result;
114 } 118 }
115 119
116 function addDefaults(expected) 120 function addDefaults(expected)
117 { 121 {
118 let type = null; 122 let type = null;
119 let hasProperty = {}; 123 let hasProperty = {};
120 for (let entry of expected) 124 for (let entry of expected)
121 { 125 {
122 if (/^type=(.*)/.test(entry)) 126 if (/^type=(.*)/.test(entry))
123 type = RegExp.$1; 127 type = RegExp.$1;
124 else if (/^(\w+)/.test(entry)) 128 else if (/^(\w+)/.test(entry))
125 hasProperty[RegExp.$1] = true; 129 hasProperty[RegExp.$1] = true;
126 } 130 }
127 131
128 function addProperty(prop, value) 132 function addProperty(prop, value)
129 { 133 {
130 if (!(prop in hasProperty)) 134 if (!(prop in hasProperty))
131 expected.push(prop + "=" + value); 135 expected.push(prop + "=" + value);
132 } 136 }
133 137
134 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || 138 if (type == "whitelist" || type == "filterlist" || type == "elemhide" ||
135 type == "elemhideexception" || type == "elemhideemulation") 139 type == "elemhideexception" || type == "elemhideemulation" ||
140 type == "elemhideemulationexception")
136 { 141 {
137 addProperty("disabled", "false"); 142 addProperty("disabled", "false");
138 addProperty("lastHit", "0"); 143 addProperty("lastHit", "0");
139 addProperty("hitCount", "0"); 144 addProperty("hitCount", "0");
140 } 145 }
141 if (type == "whitelist" || type == "filterlist") 146 if (type == "whitelist" || type == "filterlist")
142 { 147 {
143 addProperty("contentType", 0x7FFFFFFF & ~( 148 addProperty("contentType", 0x7FFFFFFF & ~(
144 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE | 149 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE |
145 RegExpFilter.typeMap.POPUP | RegExpFilter.typeMap.GENERICHIDE | 150 RegExpFilter.typeMap.POPUP | RegExpFilter.typeMap.GENERICHIDE |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); 202 test.equal(typeof CommentFilter, "function", "typeof CommentFilter");
198 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); 203 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter");
199 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); 204 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter");
200 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); 205 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter");
201 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); 206 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter");
202 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); 207 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase");
203 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); 208 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter");
204 test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); 209 test.equal(typeof ElemHideException, "function", "typeof ElemHideException");
205 test.equal(typeof ElemHideEmulationFilter, "function", 210 test.equal(typeof ElemHideEmulationFilter, "function",
206 "typeof ElemHideEmulationFilter"); 211 "typeof ElemHideEmulationFilter");
212 test.equal(typeof ElemHideEmulationException, "function",
213 "typeof ElemHideEmulationException");
207 214
208 test.done(); 215 test.done();
209 }; 216 };
210 217
211 exports.testComments = function(test) 218 exports.testComments = function(test)
212 { 219 {
213 compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]); 220 compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]);
214 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]); 221 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]);
215 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]); 222 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]);
216 223
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 335
329 exports.testElementHidingExceptions = function(test) 336 exports.testElementHidingExceptions = function(test)
330 { 337 {
331 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec tor=ddd"]); 338 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec tor=ddd"]);
332 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t ext=#@#body > div:first-child", "selector=body > div:first-child"]); 339 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t ext=#@#body > div:first-child", "selector=body > div:first-child"]);
333 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO"]); 340 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO"]);
334 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar# @#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 341 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar# @#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
335 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba r#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); 342 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba r#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
336 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo ,~baz,bar#@#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BA Z"]); 343 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo ,~baz,bar#@#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BA Z"]);
337 344
345 // elemhideemulationexception
346 // invalid exception, elemehideemulation requires a domain
347 compareFilter(test, "#^#ddd", ["type=invalid", "reason=filter_elemhideemulatio n_nodomain", "text=#^#ddd"]);
348 compareFilter(test, "foo.bar#^#ddd", ["type=elemhideemulationexception", "text =foo.bar#^#ddd", "selectorDomain=foo.bar", "selector=ddd", "domains=FOO.BAR"]);
349
338 test.done(); 350 test.done();
339 }; 351 };
340 352
341 exports.testElemHideEmulationFilters = function(test) 353 exports.testElemHideEmulationFilters = function(test)
342 { 354 {
343 // Check valid domain combinations 355 // Check valid domain combinations
344 compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulatio n", "text=foo.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector= :-abp-properties(abc)", "domains=FOO.COM"]); 356 compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulatio n", "text=foo.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector= :-abp-properties(abc)", "domains=FOO.COM"]);
345 compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "selectorDomain=fo o.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]); 357 compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "selectorDomain=fo o.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]);
346 compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemu lation", "text=foo.com,~bar#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]); 358 compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemu lation", "text=foo.com,~bar#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]);
347 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "selectorDomain=ba r.com", "selector=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]); 359 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "selectorDomain=ba r.com", "selector=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ 411 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [
400 "type=elemhideemulation", 412 "type=elemhideemulation",
401 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", 413 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)",
402 "selectorDomain=foo.com", 414 "selectorDomain=foo.com",
403 "selector=:-abp-properties(/margin: [3-4]\\x7B 2\\x7D /)", 415 "selector=:-abp-properties(/margin: [3-4]\\x7B 2\\x7D /)",
404 "domains=FOO.COM" 416 "domains=FOO.COM"
405 ] 417 ]
406 ); 418 );
407 test.done(); 419 test.done();
408 }; 420 };
OLDNEW
« no previous file with comments | « lib/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld