OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 ], | 81 ], |
82 "other.example.com", | 82 "other.example.com", |
83 ["foo-2"] | 83 ["foo-2"] |
84 ); | 84 ); |
85 | 85 |
86 test.done(); | 86 test.done(); |
87 }; | 87 }; |
88 | 88 |
89 exports.testSnippetFiltersContainer = function(test) | 89 exports.testSnippetFiltersContainer = function(test) |
90 { | 90 { |
| 91 let events = []; |
| 92 |
| 93 function eventHandler(...args) |
| 94 { |
| 95 events.push([...args]); |
| 96 } |
| 97 |
91 function compareRules(description, domain, expectedMatches) | 98 function compareRules(description, domain, expectedMatches) |
92 { | 99 { |
93 let result = Snippets.getFiltersForDomain(domain); | 100 let result = Snippets.getFiltersForDomain(domain); |
94 test.deepEqual(result.sort(), expectedMatches.sort(), description); | 101 test.deepEqual(result.sort(), expectedMatches.sort(), description); |
95 } | 102 } |
96 | 103 |
| 104 Snippets.on("snippets.filterAdded", |
| 105 eventHandler.bind(null, "snippets.filterAdded")); |
| 106 Snippets.on("snippets.filterRemoved", |
| 107 eventHandler.bind(null, "snippets.filterRemoved")); |
| 108 Snippets.on("snippets.filtersCleared", |
| 109 eventHandler.bind(null, "snippets.filtersCleared")); |
| 110 |
97 let domainFilter = Filter.fromText("example.com#$#filter1"); | 111 let domainFilter = Filter.fromText("example.com#$#filter1"); |
98 let subdomainFilter = Filter.fromText("www.example.com#$#filter2"); | 112 let subdomainFilter = Filter.fromText("www.example.com#$#filter2"); |
99 let otherDomainFilter = Filter.fromText("other.example.com#$#filter3"); | 113 let otherDomainFilter = Filter.fromText("other.example.com#$#filter3"); |
100 | 114 |
101 Snippets.add(domainFilter); | 115 Snippets.add(domainFilter); |
102 Snippets.add(subdomainFilter); | 116 Snippets.add(subdomainFilter); |
103 Snippets.add(otherDomainFilter); | 117 Snippets.add(otherDomainFilter); |
104 compareRules( | 118 compareRules( |
105 "Return all matching filters", | 119 "Return all matching filters", |
106 "www.example.com", | 120 "www.example.com", |
107 [domainFilter, subdomainFilter] | 121 [domainFilter, subdomainFilter] |
108 ); | 122 ); |
109 | 123 |
110 Snippets.remove(domainFilter); | 124 Snippets.remove(domainFilter); |
111 compareRules( | 125 compareRules( |
112 "Return all matching filters after removing one", | 126 "Return all matching filters after removing one", |
113 "www.example.com", | 127 "www.example.com", |
114 [subdomainFilter] | 128 [subdomainFilter] |
115 ); | 129 ); |
116 | 130 |
117 Snippets.clear(); | 131 Snippets.clear(); |
118 compareRules( | 132 compareRules( |
119 "Return no filters after clearing", | 133 "Return no filters after clearing", |
120 "www.example.com", | 134 "www.example.com", |
121 [] | 135 [] |
122 ); | 136 ); |
123 | 137 |
| 138 test.deepEqual(events, [ |
| 139 ["snippets.filterAdded", domainFilter], |
| 140 ["snippets.filterAdded", subdomainFilter], |
| 141 ["snippets.filterAdded", otherDomainFilter], |
| 142 ["snippets.filterRemoved", domainFilter], |
| 143 ["snippets.filtersCleared"] |
| 144 ], |
| 145 "Event log"); |
| 146 |
124 test.done(); | 147 test.done(); |
125 }; | 148 }; |
126 | 149 |
127 exports.testScriptParsing = function(test) | 150 exports.testScriptParsing = function(test) |
128 { | 151 { |
129 function checkParsedScript(description, script, expectedTree) | 152 function checkParsedScript(description, script, expectedTree) |
130 { | 153 { |
131 let tree = parseScript(script); | 154 let tree = parseScript(script); |
132 test.deepEqual(tree, expectedTree, description); | 155 test.deepEqual(tree, expectedTree, description); |
133 } | 156 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // between executions. In the example below, assertFoo does not find 456 but | 305 // between executions. In the example below, assertFoo does not find 456 but |
283 // it doesn't find 123 either. It's the initial value 0. | 306 // it doesn't find 123 either. It's the initial value 0. |
284 new Function( | 307 new Function( |
285 compileScript("setFoo 456; assertFoo 0", [ | 308 compileScript("setFoo 456; assertFoo 0", [ |
286 ...libraries, "let foo = 1; exports.setFoo = value => { foo = value; };" | 309 ...libraries, "let foo = 1; exports.setFoo = value => { foo = value; };" |
287 ]) | 310 ]) |
288 )(); | 311 )(); |
289 | 312 |
290 test.done(); | 313 test.done(); |
291 }; | 314 }; |
OLD | NEW |