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

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

Issue 29345397: Issue 4092 - Adapt unit tests for changes to InvalidFilter.reason (Closed)
Patch Set: Created May 31, 2016, 10:14 a.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 | « no previous file | 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 (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)
11 { 11 {
12 result.push("type=invalid"); 12 result.push("type=invalid");
13 if (filter.reason) 13 if (filter.reason)
14 result.push("hasReason"); 14 result.push("reason=" + filter.reason);
15 } 15 }
16 else if (filter instanceof CommentFilter) 16 else if (filter instanceof CommentFilter)
17 { 17 {
18 result.push("type=comment"); 18 result.push("type=comment");
19 } 19 }
20 else if (filter instanceof ActiveFilter) 20 else if (filter instanceof ActiveFilter)
21 { 21 {
22 result.push("disabled=" + filter.disabled); 22 result.push("disabled=" + filter.disabled);
23 result.push("lastHit=" + filter.lastHit); 23 result.push("lastHit=" + filter.lastHit);
24 result.push("hitCount=" + filter.hitCount); 24 result.push("hitCount=" + filter.hitCount);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 test("Comments", function() 176 test("Comments", function()
177 { 177 {
178 compareFilter("!asdf", ["type=comment", "text=!asdf"]); 178 compareFilter("!asdf", ["type=comment", "text=!asdf"]);
179 compareFilter("!foo#bar", ["type=comment", "text=!foo#bar"]); 179 compareFilter("!foo#bar", ["type=comment", "text=!foo#bar"]);
180 compareFilter("!foo##bar", ["type=comment", "text=!foo##bar"]); 180 compareFilter("!foo##bar", ["type=comment", "text=!foo##bar"]);
181 }); 181 });
182 182
183 test("Invalid filters", function() 183 test("Invalid filters", function()
184 { 184 {
185 compareFilter("/??/", ["type=invalid", "text=/??/", "hasReason"]); 185 compareFilter("/??/", ["type=invalid", "text=/??/", "reason=filter_invalid_r egexp"]);
186 186 compareFilter("#dd(asd)(ddd)", ["type=invalid", "text=#dd(asd)(ddd)", "reaso n=filter_elemhide_duplicate_id"]);
187 compareFilter("#dd(asd)(ddd)", ["type=invalid", "text=#dd(asd)(ddd)", "hasRe ason"]); 187 compareFilter("#*", ["type=invalid", "text=#*", "reason=filter_elemhide_nocr iteria"]);
188 {
189 let result = Filter.fromText("#dd(asd)(ddd)").reason;
190 equal(result, Utils.getString("filter_elemhide_duplicate_id"), "#dd(asd)(d dd).reason");
191 }
192
193 compareFilter("#*", ["type=invalid", "text=#*", "hasReason"]);
194 {
195 let result = Filter.fromText("#*").reason;
196 equal(result, Utils.getString("filter_elemhide_nocriteria"), "#*.reason");
197 }
198 188
199 function compareCSSRule(domains) 189 function compareCSSRule(domains)
200 { 190 {
201 let filterText = domains + "##[-abp-properties='abc']"; 191 let filterText = domains + "##[-abp-properties='abc']";
202 compareFilter(filterText, ["type=invalid", "text=" + filterText, "hasReaso n"]); 192 compareFilter(filterText, ["type=invalid", "text=" + filterText, "reason=f ilter_cssproperty_nodomain"]);
203 let reason = Filter.fromText(filterText).reason;
204 equal(reason, Utils.getString("filter_cssproperty_nodomain"), filterText + ".reason");
205 } 193 }
206 compareCSSRule(""); 194 compareCSSRule("");
207 compareCSSRule("~foo.com"); 195 compareCSSRule("~foo.com");
208 compareCSSRule("~foo.com,~bar.com"); 196 compareCSSRule("~foo.com,~bar.com");
209 compareCSSRule("foo"); 197 compareCSSRule("foo");
210 compareCSSRule("~foo.com,bar"); 198 compareCSSRule("~foo.com,bar");
211 }); 199 });
212 200
213 test("Filters with state", function() 201 test("Filters with state", function()
214 { 202 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 compareFilter("@@bla$~script,~other", ["type=whitelist", "text=@@bla$~script ,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))] ); 246 compareFilter("@@bla$~script,~other", ["type=whitelist", "text=@@bla$~script ,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))] );
259 compareFilter("@@http://bla$~script,~other", ["type=whitelist", "text=@@http ://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER))]); 247 compareFilter("@@http://bla$~script,~other", ["type=whitelist", "text=@@http ://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER))]);
260 compareFilter("@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@|ftp ://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER))]); 248 compareFilter("@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@|ftp ://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER))]);
261 compareFilter("@@bla$~script,~other,document", ["type=whitelist", "text=@@bl a$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~(t. SCRIPT | t.OTHER) | t.DOCUMENT)]); 249 compareFilter("@@bla$~script,~other,document", ["type=whitelist", "text=@@bl a$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~(t. SCRIPT | t.OTHER) | t.DOCUMENT)]);
262 compareFilter("@@bla$~script,~other,~document", ["type=whitelist", "text=@@b la$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes & ~(t .SCRIPT | t.OTHER))]); 250 compareFilter("@@bla$~script,~other,~document", ["type=whitelist", "text=@@b la$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes & ~(t .SCRIPT | t.OTHER))]);
263 compareFilter("@@bla$document", ["type=whitelist", "text=@@bla$document", "r egexp=bla", "contentType=" + t.DOCUMENT]); 251 compareFilter("@@bla$document", ["type=whitelist", "text=@@bla$document", "r egexp=bla", "contentType=" + t.DOCUMENT]);
264 compareFilter("@@bla$~script,~other,elemhide", ["type=whitelist", "text=@@bl a$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t. SCRIPT | t.OTHER) | t.ELEMHIDE)]); 252 compareFilter("@@bla$~script,~other,elemhide", ["type=whitelist", "text=@@bl a$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t. SCRIPT | t.OTHER) | t.ELEMHIDE)]);
265 compareFilter("@@bla$~script,~other,~elemhide", ["type=whitelist", "text=@@b la$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t .SCRIPT | t.OTHER))]); 253 compareFilter("@@bla$~script,~other,~elemhide", ["type=whitelist", "text=@@b la$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t .SCRIPT | t.OTHER))]);
266 compareFilter("@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide", "r egexp=bla", "contentType=" + t.ELEMHIDE]); 254 compareFilter("@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide", "r egexp=bla", "contentType=" + t.ELEMHIDE]);
267 255
268 compareFilter("@@bla$~script,~other,donottrack", ["type=invalid", "text=@@bl a$~script,~other,donottrack", "hasReason"]); 256 compareFilter("@@bla$~script,~other,donottrack", ["type=invalid", "text=@@bl a$~script,~other,donottrack", "reason=filter_unknown_option"]);
269 compareFilter("@@bla$~script,~other,~donottrack", ["type=invalid", "text=@@b la$~script,~other,~donottrack", "hasReason"]); 257 compareFilter("@@bla$~script,~other,~donottrack", ["type=invalid", "text=@@b la$~script,~other,~donottrack", "reason=filter_unknown_option"]);
270 compareFilter("@@bla$donottrack", ["type=invalid", "text=@@bla$donottrack", "hasReason"]); 258 compareFilter("@@bla$donottrack", ["type=invalid", "text=@@bla$donottrack", "reason=filter_unknown_option"]);
271 compareFilter("@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "hasReas on"]); 259 compareFilter("@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "reason= filter_unknown_option"]);
272 compareFilter("@@bla$image,foobar", ["type=invalid", "text=@@bla$image,fooba r", "hasReason"]); 260 compareFilter("@@bla$image,foobar", ["type=invalid", "text=@@bla$image,fooba r", "reason=filter_unknown_option"]);
273 compareFilter("@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar,imag e", "hasReason"]); 261 compareFilter("@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar,imag e", "reason=filter_unknown_option"]);
274 }); 262 });
275 263
276 test("Element hiding rules", function() 264 test("Element hiding rules", function()
277 { 265 {
278 compareFilter("#ddd", ["type=elemhide", "text=#ddd", "selector=ddd"]); 266 compareFilter("#ddd", ["type=elemhide", "text=#ddd", "selector=ddd"]);
279 compareFilter("#ddd(fff)", ["type=elemhide", "text=#ddd(fff)", "selector=ddd .fff,ddd#fff"]); 267 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"]']); 268 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"]']); 269 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"]); 270 compareFilter("#*(fff)", ["type=elemhide", "text=#*(fff)", "selector=.fff,#f ff"]);
283 compareFilter("#*(foo=bar)", ["type=elemhide", "text=#*(foo=bar)", 'selector =[foo="bar"]']); 271 compareFilter("#*(foo=bar)", ["type=elemhide", "text=#*(foo=bar)", 'selector =[foo="bar"]']);
(...skipping 26 matching lines...) Expand all
310 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"]); 298 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"]);
311 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"]); 299 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"]);
312 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"]); 300 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"]);
313 301
314 compareFilter("##[-abp-properties='']", ["type=elemhide", "text=##[-abp-prop erties='']", "selector=[-abp-properties='']"]); 302 compareFilter("##[-abp-properties='']", ["type=elemhide", "text=##[-abp-prop erties='']", "selector=[-abp-properties='']"]);
315 compareFilter("foo.com#@#[-abp-properties='abc']", ["type=elemhideexception" , "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selector= [-abp-properties='abc']", "domains=FOO.COM"]); 303 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##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"]); 304 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", "regexp=^background\\-image\\:\\ url\\(data\\: .*\\)"]); 305 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 }); 306 });
319 })(); 307 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld