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

Side by Side Diff: chrome/content/tests/filterClasses.js

Issue 6423769060999168: Issue 301 - adblockplustests: Use for (.. of ..) (Closed)
Patch Set: Created April 12, 2014, 1:48 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 | « chrome/content/tests/elemhide.js ('k') | chrome/content/tests/filterListener.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 result.push("selector=" + filter.selector); 60 result.push("selector=" + filter.selector);
61 } 61 }
62 } 62 }
63 return result; 63 return result;
64 } 64 }
65 65
66 function addDefaults(expected) 66 function addDefaults(expected)
67 { 67 {
68 let type = null; 68 let type = null;
69 let hasProperty = {}; 69 let hasProperty = {};
70 for each (let entry in expected) 70 for (let entry of expected)
71 { 71 {
72 if (/^type=(.*)/.test(entry)) 72 if (/^type=(.*)/.test(entry))
73 type = RegExp.$1; 73 type = RegExp.$1;
74 else if (/^(\w+)/.test(entry)) 74 else if (/^(\w+)/.test(entry))
75 hasProperty[RegExp.$1] = true; 75 hasProperty[RegExp.$1] = true;
76 } 76 }
77 77
78 function addProperty(prop, value) 78 function addProperty(prop, value)
79 { 79 {
80 if (!(prop in hasProperty)) 80 if (!(prop in hasProperty))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 let result = serializeFilter(filter); 115 let result = serializeFilter(filter);
116 equal(result.sort().join("\n"), expected.sort().join("\n"), text); 116 equal(result.sort().join("\n"), expected.sort().join("\n"), text);
117 117
118 // Test round-trip 118 // Test round-trip
119 let filter2; 119 let filter2;
120 let buffer = []; 120 let buffer = [];
121 filter.serialize(buffer); 121 filter.serialize(buffer);
122 if (buffer.length) 122 if (buffer.length)
123 { 123 {
124 let map = {__proto__: null}; 124 let map = {__proto__: null};
125 for each (let line in buffer.slice(1)) 125 for (let line of buffer.slice(1))
126 { 126 {
127 if (/(.*?)=(.*)/.test(line)) 127 if (/(.*?)=(.*)/.test(line))
128 map[RegExp.$1] = RegExp.$2; 128 map[RegExp.$1] = RegExp.$2;
129 } 129 }
130 filter2 = Filter.fromObject(map); 130 filter2 = Filter.fromObject(map);
131 } 131 }
132 else 132 else
133 { 133 {
134 filter2 = Filter.fromText(filter.text); 134 filter2 = Filter.fromText(filter.text);
135 } 135 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 compareFilter("#@ddd(fff)(foo=bar)", ["type=elemhideexception", "text=#@ddd( fff)(foo=bar)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']); 261 compareFilter("#@ddd(fff)(foo=bar)", ["type=elemhideexception", "text=#@ddd( fff)(foo=bar)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']);
262 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]); 262 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]);
263 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']); 263 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']);
264 compareFilter("#@#body > div:first-child", ["type=elemhideexception", "text= #@#body > div:first-child", "selector=body > div:first-child"]); 264 compareFilter("#@#body > div:first-child", ["type=elemhideexception", "text= #@#body > div:first-child", "selector=body > div:first-child"]);
265 compareFilter("foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "selec torDomain=foo", "selector=ddd", "domains=FOO"]); 265 compareFilter("foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "selec torDomain=foo", "selector=ddd", "domains=FOO"]);
266 compareFilter("foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ddd" , "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 266 compareFilter("foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ddd" , "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
267 compareFilter("foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar#@dd d", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); 267 compareFilter("foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar#@dd d", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
268 compareFilter("foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz ,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]); 268 compareFilter("foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz ,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
269 }); 269 });
270 })(); 270 })();
OLDNEW
« no previous file with comments | « chrome/content/tests/elemhide.js ('k') | chrome/content/tests/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld