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: Rebased and adapted to review changes from #2392 and #2393 Created Nov. 25, 2015, 6:53 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 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"]);
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"]']); 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"]']);
281 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"]']);
282 compareFilter("#*(fff)", ["type=elemhide", "text=#*(fff)", "selector=.fff,#f ff"]); 282 compareFilter("#*(fff)", ["type=elemhide", "text=#*(fff)", "selector=.fff,#f ff"]);
283 compareFilter("#*(foo=bar)", ["type=elemhide", "text=#*(foo=bar)", 'selector =[foo="bar"]']); 283 compareFilter("#*(foo=bar)", ["type=elemhide", "text=#*(foo=bar)", 'selector =[foo="bar"]']);
284 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"]);
285 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"]);
286 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"]);
287 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"]);
288 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"]);
289 compareFilter("##[-abp-properties='']", ["type=elemhide", "text=##[-abp-prop erties='']", "selector=[-abp-properties='']"]);
290 }); 289 });
291 290
292 test("Element hiding exceptions", function() 291 test("Element hiding exceptions", function()
293 { 292 {
294 compareFilter("#@ddd", ["type=elemhideexception", "text=#@ddd", "selector=dd d"]); 293 compareFilter("#@ddd", ["type=elemhideexception", "text=#@ddd", "selector=dd d"]);
295 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"]);
296 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"]']);
297 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"]']);
298 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]); 297 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]);
299 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']); 298 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']);
300 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"]);
301 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"]);
302 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"]);
303 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"]);
304 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='']"]);
305 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"]);
306 });
307
308 test("CSS property filters", function()
309 {
310 // Check valid domain combinations
311 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="]);
312 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="]);
313 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 ="]);
314 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="]);
315
316 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"]);
317 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\\: .*\\)"]);
318 }); 319 });
319 })(); 320 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld