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

Delta Between Two Patch Sets: chrome/content/tests/filterClasses.js

Issue 29324604: Issue 2394 - Added unit tests for CSS property filters (Closed)
Left Patch Set: Created Aug. 25, 2015, 3:51 p.m.
Right Patch Set: Created Dec. 7, 2015, 5:21 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 | « chrome/content/tests/cssRules.js ('k') | chrome/content/tests/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 (function() 1 (function()
2 { 2 {
3 module("Filter classes", {setup: prepareFilterComponents, teardown: restoreFil terComponents}); 3 module("Filter classes", {setup: prepareFilterComponents, teardown: restoreFil terComponents});
4 4
5 function serializeFilter(filter) 5 function serializeFilter(filter)
6 { 6 {
7 // Filter serialization only writes out essential properties, need to do a f ull serialization here 7 // Filter serialization only writes out essential properties, need to do a f ull serialization here
8 let result = []; 8 let result = [];
9 result.push("text=" + filter.text); 9 result.push("text=" + filter.text);
10 if (filter instanceof InvalidFilter) 10 if (filter instanceof InvalidFilter)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 93
94 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || typ e == "elemhideexception" || type == "cssrule") 94 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || typ e == "elemhideexception" || type == "cssrule")
95 { 95 {
96 addProperty("disabled", "false"); 96 addProperty("disabled", "false");
97 addProperty("lastHit", "0"); 97 addProperty("lastHit", "0");
98 addProperty("hitCount", "0"); 98 addProperty("hitCount", "0");
99 } 99 }
100 if (type == "whitelist" || type == "filterlist") 100 if (type == "whitelist" || type == "filterlist")
101 { 101 {
102 addProperty("contentType", 0x7FFFFFFF & ~(RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP)); 102 addProperty("contentType", 0x7FFFFFFF & ~(
103 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE |
104 RegExpFilter.typeMap.POPUP | RegExpFilter.typeMap.GENERICHIDE |
105 RegExpFilter.typeMap.GENERICBLOCK
106 ));
103 addProperty("matchCase", "false"); 107 addProperty("matchCase", "false");
104 addProperty("thirdParty", "null"); 108 addProperty("thirdParty", "null");
105 addProperty("domains", ""); 109 addProperty("domains", "");
106 addProperty("sitekeys", ""); 110 addProperty("sitekeys", "");
107 } 111 }
108 if (type == "filterlist") 112 if (type == "filterlist")
109 { 113 {
110 addProperty("collapse", "null"); 114 addProperty("collapse", "null");
111 } 115 }
112 if (type == "elemhide" || type == "elemhideexception" || type == "cssrule") 116 if (type == "elemhide" || type == "elemhideexception" || type == "cssrule")
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 function compareCSSRule(domains) 199 function compareCSSRule(domains)
196 { 200 {
197 let filterText = domains + "##[-abp-properties='abc']"; 201 let filterText = domains + "##[-abp-properties='abc']";
198 compareFilter(filterText, ["type=invalid", "text=" + filterText, "hasReaso n"]); 202 compareFilter(filterText, ["type=invalid", "text=" + filterText, "hasReaso n"]);
199 let reason = Filter.fromText(filterText).reason; 203 let reason = Filter.fromText(filterText).reason;
200 equal(reason, Utils.getString("filter_cssproperty_nodomain"), filterText + ".reason"); 204 equal(reason, Utils.getString("filter_cssproperty_nodomain"), filterText + ".reason");
201 } 205 }
202 compareCSSRule(""); 206 compareCSSRule("");
203 compareCSSRule("~foo.com"); 207 compareCSSRule("~foo.com");
204 compareCSSRule("~foo.com,~bar.com"); 208 compareCSSRule("~foo.com,~bar.com");
205 compareCSSRule("foo"); 209 compareCSSRule("foo");
Wladimir Palant 2015/11/10 10:49:03 Why is foo##[-abp-properties='abc'] invalid?
Thomas Greiner 2015/12/03 12:55:20 Considering domains with only one part (e.g. "com"
206 compareCSSRule("~foo.com,bar"); 210 compareCSSRule("~foo.com,bar");
207 }); 211 });
208 212
209 test("Filters with state", function() 213 test("Filters with state", function()
210 { 214 {
211 compareFilter("blabla", ["type=filterlist", "text=blabla", "regexp=blabla"]) ; 215 compareFilter("blabla", ["type=filterlist", "text=blabla", "regexp=blabla"]) ;
212 compareFilter("blabla_default", ["type=filterlist", "text=blabla_default", " regexp=blabla_default"], function(filter) 216 compareFilter("blabla_default", ["type=filterlist", "text=blabla_default", " regexp=blabla_default"], function(filter)
213 { 217 {
214 filter.disabled = false; 218 filter.disabled = false;
215 filter.hitCount = 0; 219 filter.hitCount = 0;
216 filter.lastHit = 0; 220 filter.lastHit = 0;
217 }); 221 });
218 compareFilter("blabla_non_default", ["type=filterlist", "text=blabla_non_def ault", "regexp=blabla_non_default", "disabled=true", "hitCount=12", "lastHit=20" ], function(filter) 222 compareFilter("blabla_non_default", ["type=filterlist", "text=blabla_non_def ault", "regexp=blabla_non_default", "disabled=true", "hitCount=12", "lastHit=20" ], function(filter)
219 { 223 {
220 filter.disabled = true; 224 filter.disabled = true;
221 filter.hitCount = 12; 225 filter.hitCount = 12;
222 filter.lastHit = 20; 226 filter.lastHit = 20;
223 }); 227 });
224 }); 228 });
225 229
226 let t = RegExpFilter.typeMap; 230 let t = RegExpFilter.typeMap;
227 let defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP); 231 let defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP | t.GENERI CHIDE | t.GENERICBLOCK);
228 232
229 test("Special characters", function() 233 test("Special characters", function()
230 { 234 {
231 compareFilter("/ddd|f?a[s]d/", ["type=filterlist", "text=/ddd|f?a[s]d/", "re gexp=ddd|f?a[s]d"]); 235 compareFilter("/ddd|f?a[s]d/", ["type=filterlist", "text=/ddd|f?a[s]d/", "re gexp=ddd|f?a[s]d"]);
232 compareFilter("*asdf*d**dd*", ["type=filterlist", "text=*asdf*d**dd*", "rege xp=asdf.*d.*dd"]); 236 compareFilter("*asdf*d**dd*", ["type=filterlist", "text=*asdf*d**dd*", "rege xp=asdf.*d.*dd"]);
233 compareFilter("|*asd|f*d**dd*|", ["type=filterlist", "text=|*asd|f*d**dd*|", "regexp=^.*asd\\|f.*d.*dd.*$"]); 237 compareFilter("|*asd|f*d**dd*|", ["type=filterlist", "text=|*asd|f*d**dd*|", "regexp=^.*asd\\|f.*d.*dd.*$"]);
234 compareFilter("dd[]{}$%<>&()d", ["type=filterlist", "text=dd[]{}$%<>&()d", " regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d"]); 238 compareFilter("dd[]{}$%<>&()d", ["type=filterlist", "text=dd[]{}$%<>&()d", " regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d"]);
235 239
236 compareFilter("@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); 240 compareFilter("@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]);
237 compareFilter("@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*", "r egexp=asdf.*d.*dd", "contentType=" + defaultTypes]); 241 compareFilter("@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*", "r egexp=asdf.*d.*dd", "contentType=" + defaultTypes]);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 compareFilter("#ddd(fff)", ["type=elemhide", "text=#ddd(fff)", "selector=ddd .fff,ddd#fff"]); 279 compareFilter("#ddd(fff)", ["type=elemhide", "text=#ddd(fff)", "selector=ddd .fff,ddd#fff"]);
276 compareFilter("#ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", ["type=el emhide", "text=#ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", 'selector=ddd [foo="bar"][foo2^="bar2"][foo3*="bar3"][foo4$="bar4"]']); 280 compareFilter("#ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", ["type=el emhide", "text=#ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", 'selector=ddd [foo="bar"][foo2^="bar2"][foo3*="bar3"][foo4$="bar4"]']);
277 compareFilter("#ddd(fff)(foo=bar)", ["type=elemhide", "text=#ddd(fff)(foo=ba r)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']); 281 compareFilter("#ddd(fff)(foo=bar)", ["type=elemhide", "text=#ddd(fff)(foo=ba r)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']);
278 compareFilter("#*(fff)", ["type=elemhide", "text=#*(fff)", "selector=.fff,#f ff"]); 282 compareFilter("#*(fff)", ["type=elemhide", "text=#*(fff)", "selector=.fff,#f ff"]);
279 compareFilter("#*(foo=bar)", ["type=elemhide", "text=#*(foo=bar)", 'selector =[foo="bar"]']); 283 compareFilter("#*(foo=bar)", ["type=elemhide", "text=#*(foo=bar)", 'selector =[foo="bar"]']);
280 compareFilter("##body > div:first-child", ["type=elemhide", "text=##body > d iv:first-child", "selector=body > div:first-child"]); 284 compareFilter("##body > div:first-child", ["type=elemhide", "text=##body > d iv:first-child", "selector=body > div:first-child"]);
281 compareFilter("foo#ddd", ["type=elemhide", "text=foo#ddd", "selectorDomain=f oo", "selector=ddd", "domains=FOO"]); 285 compareFilter("foo#ddd", ["type=elemhide", "text=foo#ddd", "selectorDomain=f oo", "selector=ddd", "domains=FOO"]);
282 compareFilter("foo,bar#ddd", ["type=elemhide", "text=foo,bar#ddd", "selector Domain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 286 compareFilter("foo,bar#ddd", ["type=elemhide", "text=foo,bar#ddd", "selector Domain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
283 compareFilter("foo,~bar#ddd", ["type=elemhide", "text=foo,~bar#ddd", "select orDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); 287 compareFilter("foo,~bar#ddd", ["type=elemhide", "text=foo,~bar#ddd", "select orDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
284 compareFilter("foo,~baz,bar#ddd", ["type=elemhide", "text=foo,~baz,bar#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]); 288 compareFilter("foo,~baz,bar#ddd", ["type=elemhide", "text=foo,~baz,bar#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
285 compareFilter("##[-abp-properties='']", ["type=elemhide", "text=##[-abp-prop erties='']", "selector=[-abp-properties='']"]);
Wladimir Palant 2015/11/10 10:49:03 Wouldn't it make sense to have this filter in the
Thomas Greiner 2015/12/03 12:55:20 Done.
286 }); 289 });
287 290
288 test("Element hiding exceptions", function() 291 test("Element hiding exceptions", function()
289 { 292 {
290 compareFilter("#@ddd", ["type=elemhideexception", "text=#@ddd", "selector=dd d"]); 293 compareFilter("#@ddd", ["type=elemhideexception", "text=#@ddd", "selector=dd d"]);
291 compareFilter("#@ddd(fff)", ["type=elemhideexception", "text=#@ddd(fff)", "s elector=ddd.fff,ddd#fff"]); 294 compareFilter("#@ddd(fff)", ["type=elemhideexception", "text=#@ddd(fff)", "s elector=ddd.fff,ddd#fff"]);
292 compareFilter("#@ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", ["type=e lemhideexception", "text=#@ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", 's elector=ddd[foo="bar"][foo2^="bar2"][foo3*="bar3"][foo4$="bar4"]']); 295 compareFilter("#@ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", ["type=e lemhideexception", "text=#@ddd(foo=bar)(foo2^=bar2)(foo3*=bar3)(foo4$=bar4)", 's elector=ddd[foo="bar"][foo2^="bar2"][foo3*="bar3"][foo4$="bar4"]']);
293 compareFilter("#@ddd(fff)(foo=bar)", ["type=elemhideexception", "text=#@ddd( fff)(foo=bar)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']); 296 compareFilter("#@ddd(fff)(foo=bar)", ["type=elemhideexception", "text=#@ddd( fff)(foo=bar)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']);
294 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]); 297 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]);
295 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']); 298 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']);
296 compareFilter("#@#body > div:first-child", ["type=elemhideexception", "text= #@#body > div:first-child", "selector=body > div:first-child"]); 299 compareFilter("#@#body > div:first-child", ["type=elemhideexception", "text= #@#body > div:first-child", "selector=body > div:first-child"]);
297 compareFilter("foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "selec torDomain=foo", "selector=ddd", "domains=FOO"]); 300 compareFilter("foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "selec torDomain=foo", "selector=ddd", "domains=FOO"]);
298 compareFilter("foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ddd" , "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 301 compareFilter("foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ddd" , "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
299 compareFilter("foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar#@dd d", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); 302 compareFilter("foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar#@dd d", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
300 compareFilter("foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz ,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]); 303 compareFilter("foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz ,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
304 });
305
306 test("CSS property filters", function()
307 {
308
309 // Check valid domain combinations
310 compareFilter("foo.com##[-abp-properties='abc']", ["type=cssrule", "text=foo .com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-proper ties='abc']", "domains=FOO.COM", "regexp=abc"]);
311 compareFilter("foo.com,~bar.com##[-abp-properties='abc']", ["type=cssrule", "text=foo.com,~bar.com##[-abp-properties='abc']", "selectorDomain=foo.com", "sel ector=[-abp-properties='abc']", "domains=FOO.COM|~BAR.COM", "regexp=abc"]);
312 compareFilter("foo.com,~bar##[-abp-properties='abc']", ["type=cssrule", "tex t=foo.com,~bar##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[- abp-properties='abc']", "domains=FOO.COM|~BAR", "regexp=abc"]);
313 compareFilter("~foo.com,bar.com##[-abp-properties='abc']", ["type=cssrule", "text=~foo.com,bar.com##[-abp-properties='abc']", "selectorDomain=bar.com", "sel ector=[-abp-properties='abc']", "domains=BAR.COM|~FOO.COM", "regexp=abc"]);
314
315 compareFilter("##[-abp-properties='']", ["type=elemhide", "text=##[-abp-prop erties='']", "selector=[-abp-properties='']"]);
301 compareFilter("foo.com#@#[-abp-properties='abc']", ["type=elemhideexception" , "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selector= [-abp-properties='abc']", "domains=FOO.COM"]); 316 compareFilter("foo.com#@#[-abp-properties='abc']", ["type=elemhideexception" , "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selector= [-abp-properties='abc']", "domains=FOO.COM"]);
Wladimir Palant 2015/11/10 10:49:02 Wouldn't it make sense to have this filter in the
Thomas Greiner 2015/12/03 12:55:21 Done.
302 });
303
304 test("CSS property filters", function()
305 {
306 // Check valid domain combinations
307 compareFilter("foo.com##[-abp-properties='abc']", ["type=cssrule", "text=foo .com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-proper ties='abc']", "domains=FOO.COM", "prefix=", "regexp=abc", "suffix="]);
308 compareFilter("foo.com,~bar.com##[-abp-properties='abc']", ["type=cssrule", "text=foo.com,~bar.com##[-abp-properties='abc']", "selectorDomain=foo.com", "sel ector=[-abp-properties='abc']", "domains=FOO.COM|~BAR.COM", "prefix=", "regexp=a bc", "suffix="]);
309 compareFilter("foo.com,~bar##[-abp-properties='abc']", ["type=cssrule", "tex t=foo.com,~bar##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[- abp-properties='abc']", "domains=FOO.COM|~BAR", "prefix=", "regexp=abc", "suffix ="]);
310 compareFilter("~foo.com,bar.com##[-abp-properties='abc']", ["type=cssrule", "text=~foo.com,bar.com##[-abp-properties='abc']", "selectorDomain=bar.com", "sel ector=[-abp-properties='abc']", "domains=BAR.COM|~FOO.COM", "prefix=", "regexp=a bc", "suffix="]);
Wladimir Palant 2015/11/10 10:49:03 You make prefix and suffix default to an empty str
Thomas Greiner 2015/12/03 12:55:21 Done.
311
312 compareFilter("foo.com##aaa [-abp-properties='abc'] bbb", ["type=cssrule", " text=foo.com##aaa [-abp-properties='abc'] bbb", "selectorDomain=foo.com", "selec tor=aaa [-abp-properties='abc'] bbb", "domains=FOO.COM", "prefix=aaa ", "regexp= abc", "suffix= bbb"]); 317 compareFilter("foo.com##aaa [-abp-properties='abc'] bbb", ["type=cssrule", " text=foo.com##aaa [-abp-properties='abc'] bbb", "selectorDomain=foo.com", "selec tor=aaa [-abp-properties='abc'] bbb", "domains=FOO.COM", "prefix=aaa ", "regexp= abc", "suffix= bbb"]);
313 compareFilter("foo.com##[-abp-properties='|background-image: url(data:*)']", ["type=cssrule", "text=foo.com##[-abp-properties='|background-image: url(data:* )']", "selectorDomain=foo.com", "selector=[-abp-properties='|background-image: u rl(data:*)']", "domains=FOO.COM", "prefix=", "regexp=^background\\-image\\:\\ ur l\\(data\\:.*\\)", "suffix="]); 318 compareFilter("foo.com##[-abp-properties='|background-image: url(data:*)']", ["type=cssrule", "text=foo.com##[-abp-properties='|background-image: url(data:* )']", "selectorDomain=foo.com", "selector=[-abp-properties='|background-image: u rl(data:*)']", "domains=FOO.COM", "regexp=^background\\-image\\:\\ url\\(data\\: .*\\)"]);
314 }); 319 });
315 })(); 320 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld