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

Side by Side Diff: chrome/content/tests/matcher.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/filterStorage_readwrite.js ('k') | chrome/content/tests/notification.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 matcher", {setup: prepareFilterComponents, teardown: restoreFil terComponents}); 3 module("Filter matcher", {setup: prepareFilterComponents, teardown: restoreFil terComponents});
4 4
5 function compareKeywords(text, expected) 5 function compareKeywords(text, expected)
6 { 6 {
7 for each (let filter in [Filter.fromText(text), Filter.fromText("@@" + text) ]) 7 for (let filter of [Filter.fromText(text), Filter.fromText("@@" + text)])
8 { 8 {
9 let matcher = new Matcher(); 9 let matcher = new Matcher();
10 let result = []; 10 let result = [];
11 for each (let dummy in expected) 11 for (let dummy of expected)
12 { 12 {
13 keyword = matcher.findKeyword(filter); 13 keyword = matcher.findKeyword(filter);
14 result.push(keyword); 14 result.push(keyword);
15 if (keyword) 15 if (keyword)
16 { 16 {
17 let dummyFilter = Filter.fromText('^' + keyword + '^'); 17 let dummyFilter = Filter.fromText('^' + keyword + '^');
18 dummyFilter.filterCount = Infinity; 18 dummyFilter.filterCount = Infinity;
19 matcher.add(dummyFilter); 19 matcher.add(dummyFilter);
20 } 20 }
21 } 21 }
22 22
23 equal(result.join(", "), expected.join(", "), "Keyword candidates for " + filter.text); 23 equal(result.join(", "), expected.join(", "), "Keyword candidates for " + filter.text);
24 } 24 }
25 } 25 }
26 26
27 function checkMatch(filters, location, contentType, docDomain, thirdParty, exp ected) 27 function checkMatch(filters, location, contentType, docDomain, thirdParty, exp ected)
28 { 28 {
29 let matcher = new Matcher(); 29 let matcher = new Matcher();
30 for each (let filter in filters) 30 for (let filter of filters)
31 matcher.add(Filter.fromText(filter)); 31 matcher.add(Filter.fromText(filter));
32 32
33 let result = matcher.matchesAny(location, contentType, docDomain, thirdParty ); 33 let result = matcher.matchesAny(location, contentType, docDomain, thirdParty );
34 if (result) 34 if (result)
35 result = result.text; 35 result = result.text;
36 36
37 equal(result, expected, "match(" + location + ", " + contentType + ", " + do cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with:\n" + fi lters.join("\n")); 37 equal(result, expected, "match(" + location + ", " + contentType + ", " + do cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with:\n" + fi lters.join("\n"));
38 38
39 let combinedMatcher = new CombinedMatcher(); 39 let combinedMatcher = new CombinedMatcher();
40 for (let i = 0; i < 2; i++) 40 for (let i = 0; i < 2; i++)
41 { 41 {
42 for each (let filter in filters) 42 for (let filter of filters)
43 combinedMatcher.add(Filter.fromText(filter)); 43 combinedMatcher.add(Filter.fromText(filter));
44 44
45 let result = combinedMatcher.matchesAny(location, contentType, docDomain, thirdParty); 45 let result = combinedMatcher.matchesAny(location, contentType, docDomain, thirdParty);
46 if (result) 46 if (result)
47 result = result.text; 47 result = result.text;
48 48
49 equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") wit h:\n" + filters.join("\n")); 49 equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") wit h:\n" + filters.join("\n"));
50 50
51 // For next run: add whitelisting filters 51 // For next run: add whitelisting filters
52 filters = filters.map(function(text) "@@" + text); 52 filters = filters.map(function(text) "@@" + text);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p arty,~script"); 179 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p arty,~script");
180 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par ty"); 180 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par ty");
181 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, false, "cba$~third-p arty,~script"); 181 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, false, "cba$~third-p arty,~script");
182 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, true, "cba$third-par ty"); 182 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, true, "cba$third-par ty");
183 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script"); 183 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script");
184 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, false, "http: //fed$~third-party,~script"); 184 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, false, "http: //fed$~third-party,~script");
185 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, true, "http:/ /fed$third-party"); 185 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, true, "http:/ /fed$third-party");
186 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http:// def$script"); 186 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http:// def$script");
187 }); 187 });
188 })(); 188 })();
OLDNEW
« no previous file with comments | « chrome/content/tests/filterStorage_readwrite.js ('k') | chrome/content/tests/notification.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld