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

Side by Side Diff: chrome/content/tests/filterListener.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/filterClasses.js ('k') | chrome/content/tests/filterNotifier.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 listener", { 3 module("Filter listener", {
4 setup: function() 4 setup: function()
5 { 5 {
6 prepareFilterComponents.call(this, true); 6 prepareFilterComponents.call(this, true);
7 preparePrefs.call(this); 7 preparePrefs.call(this);
8 8
9 FilterStorage.addSubscription(Subscription.fromURL("~fl~")); 9 FilterStorage.addSubscription(Subscription.fromURL("~fl~"));
10 FilterStorage.addSubscription(Subscription.fromURL("~wl~")); 10 FilterStorage.addSubscription(Subscription.fromURL("~wl~"));
11 FilterStorage.addSubscription(Subscription.fromURL("~eh~")); 11 FilterStorage.addSubscription(Subscription.fromURL("~eh~"));
12 12
13 Subscription.fromURL("~fl~").defaults = ["blocking"]; 13 Subscription.fromURL("~fl~").defaults = ["blocking"];
14 Subscription.fromURL("~wl~").defaults = ["whitelist"]; 14 Subscription.fromURL("~wl~").defaults = ["whitelist"];
15 Subscription.fromURL("~eh~").defaults = ["elemhide"]; 15 Subscription.fromURL("~eh~").defaults = ["elemhide"];
16 }, 16 },
17 teardown: function() 17 teardown: function()
18 { 18 {
19 restoreFilterComponents.call(this); 19 restoreFilterComponents.call(this);
20 restorePrefs.call(this); 20 restorePrefs.call(this);
21 } 21 }
22 }); 22 });
23 23
24 function checkKnownFilters(text, expected) 24 function checkKnownFilters(text, expected)
25 { 25 {
26 let result = {}; 26 let result = {};
27 for each (let type in ["blacklist", "whitelist"]) 27 for (let type of ["blacklist", "whitelist"])
28 { 28 {
29 let matcher = defaultMatcher[type] 29 let matcher = defaultMatcher[type]
30 let filters = []; 30 let filters = [];
31 for (let keyword in matcher.filterByKeyword) 31 for (let keyword in matcher.filterByKeyword)
32 { 32 {
33 let list = matcher.filterByKeyword[keyword]; 33 let list = matcher.filterByKeyword[keyword];
34 for (let i = 0; i < list.length; i++) 34 for (let i = 0; i < list.length; i++)
35 { 35 {
36 let filter = list[i]; 36 let filter = list[i];
37 equal(matcher.getKeywordForFilter(filter), keyword, "Keyword of filter " + filter.text); 37 equal(matcher.getKeywordForFilter(filter), keyword, "Keyword of filter " + filter.text);
38 filters.push(filter.text); 38 filters.push(filter.text);
39 } 39 }
40 } 40 }
41 result[type] = filters; 41 result[type] = filters;
42 } 42 }
43 43
44 let ElemHideGlobal = getModuleGlobal("elemHide"); 44 let ElemHideGlobal = getModuleGlobal("elemHide");
45 result.elemhide = []; 45 result.elemhide = [];
46 for (let key in ElemHideGlobal.filterByKey) 46 for (let key in ElemHideGlobal.filterByKey)
47 result.elemhide.push(ElemHideGlobal.filterByKey[key].text); 47 result.elemhide.push(ElemHideGlobal.filterByKey[key].text);
48 48
49 result.elemhideexception = []; 49 result.elemhideexception = [];
50 for (let selector in ElemHideGlobal.exceptions) 50 for (let selector in ElemHideGlobal.exceptions)
51 { 51 {
52 let list = ElemHideGlobal.exceptions[selector]; 52 let list = ElemHideGlobal.exceptions[selector];
53 for (let i = 0; i < list.length; i++) 53 for (let i = 0; i < list.length; i++)
54 result.elemhideexception.push(list[i].text); 54 result.elemhideexception.push(list[i].text);
55 } 55 }
56 56
57 for each (let type in ["blacklist", "whitelist", "elemhide", "elemhideexcept ion"]) 57 for (let type of ["blacklist", "whitelist", "elemhide", "elemhideexception"] )
58 if (!(type in expected)) 58 if (!(type in expected))
59 expected[type] = []; 59 expected[type] = [];
60 60
61 deepEqual(result, expected, text); 61 deepEqual(result, expected, text);
62 } 62 }
63 63
64 test("Adding and removing filters", function() 64 test("Adding and removing filters", function()
65 { 65 {
66 let filter1 = Filter.fromText("filter1"); 66 let filter1 = Filter.fromText("filter1");
67 let filter2 = Filter.fromText("@@filter2"); 67 let filter2 = Filter.fromText("@@filter2");
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 subscription3.disabled = true; 244 subscription3.disabled = true;
245 checkKnownFilters("disable exception rules", {blacklist: [filter1.text, filt er3.text], whitelist: [filter2.text]}); 245 checkKnownFilters("disable exception rules", {blacklist: [filter1.text, filt er3.text], whitelist: [filter2.text]});
246 246
247 FilterStorage.removeSubscription(subscription4); 247 FilterStorage.removeSubscription(subscription4);
248 checkKnownFilters("remove subscription from the list", {blacklist: [filter1. text]}); 248 checkKnownFilters("remove subscription from the list", {blacklist: [filter1. text]});
249 249
250 subscription3.disabled = false; 250 subscription3.disabled = false;
251 checkKnownFilters("enable exception rules", {blacklist: [filter1.text], whit elist: [filter2.text]}); 251 checkKnownFilters("enable exception rules", {blacklist: [filter1.text], whit elist: [filter2.text]});
252 }); 252 });
253 })(); 253 })();
OLDNEW
« no previous file with comments | « chrome/content/tests/filterClasses.js ('k') | chrome/content/tests/filterNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld