| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 30 matching lines...) Expand all Loading... | |
| 41 exports.testDomainRestrictions = function(test) | 41 exports.testDomainRestrictions = function(test) |
| 42 { | 42 { |
| 43 function testScriptMatches(description, filters, domain, expectedMatches) | 43 function testScriptMatches(description, filters, domain, expectedMatches) |
| 44 { | 44 { |
| 45 for (let filter of filters.map(Filter.fromText)) | 45 for (let filter of filters.map(Filter.fromText)) |
| 46 { | 46 { |
| 47 if (filter instanceof SnippetFilter) | 47 if (filter instanceof SnippetFilter) |
| 48 Snippets.add(filter); | 48 Snippets.add(filter); |
| 49 } | 49 } |
| 50 | 50 |
| 51 let matches = Snippets.getSnippetsForDomain(domain); | 51 let matches = Snippets.getFiltersForDomain(domain).map( |
|
Manish Jethani
2018/08/27 05:40:10
I think it would be cleaner to keep the call to `t
hub
2018/08/27 12:14:35
Done.
| |
| 52 test.deepEqual(matches.map(elem => elem.script).sort(), expectedMatches.sort (), description); | 52 filter => filter.script |
| 53 ); | |
| 54 test.deepEqual(matches.sort(), expectedMatches.sort(), description); | |
| 53 | 55 |
| 54 Snippets.clear(); | 56 Snippets.clear(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 testScriptMatches( | 59 testScriptMatches( |
| 58 "Ignore generic filters", | 60 "Ignore generic filters", |
| 59 [ | 61 [ |
| 60 "#$#foo-1", "example.com#$#foo-2", | 62 "#$#foo-1", "example.com#$#foo-2", |
| 61 "~example.com#$#foo-3" | 63 "~example.com#$#foo-3" |
| 62 ], | 64 ], |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 81 ["foo-2"] | 83 ["foo-2"] |
| 82 ); | 84 ); |
| 83 | 85 |
| 84 test.done(); | 86 test.done(); |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 exports.testSnippetFiltersContainer = function(test) | 89 exports.testSnippetFiltersContainer = function(test) |
| 88 { | 90 { |
| 89 function compareRules(description, domain, expectedMatches) | 91 function compareRules(description, domain, expectedMatches) |
| 90 { | 92 { |
| 91 let result = Snippets.getSnippetsForDomain(domain); | 93 let result = Snippets.getFiltersForDomain(domain); |
| 92 test.deepEqual(result.sort(), expectedMatches.sort(), description); | 94 test.deepEqual(result.sort(), expectedMatches.sort(), description); |
| 93 } | 95 } |
| 94 | 96 |
| 95 let domainFilter = Filter.fromText("example.com#$#filter1"); | 97 let domainFilter = Filter.fromText("example.com#$#filter1"); |
| 96 let subdomainFilter = Filter.fromText("www.example.com#$#filter2"); | 98 let subdomainFilter = Filter.fromText("www.example.com#$#filter2"); |
| 97 let otherDomainFilter = Filter.fromText("other.example.com#$#filter3"); | 99 let otherDomainFilter = Filter.fromText("other.example.com#$#filter3"); |
| 98 | 100 |
| 99 Snippets.add(domainFilter); | 101 Snippets.add(domainFilter); |
| 100 Snippets.add(subdomainFilter); | 102 Snippets.add(subdomainFilter); |
| 101 Snippets.add(otherDomainFilter); | 103 Snippets.add(otherDomainFilter); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 // between executions. In the example below, assertFoo does not find 456 but | 282 // between executions. In the example below, assertFoo does not find 456 but |
| 281 // it doesn't find 123 either. It's the initial value 0. | 283 // it doesn't find 123 either. It's the initial value 0. |
| 282 new Function( | 284 new Function( |
| 283 compileScript("setFoo 456; assertFoo 0", [ | 285 compileScript("setFoo 456; assertFoo 0", [ |
| 284 ...libraries, "let foo = 1; exports.setFoo = value => { foo = value; };" | 286 ...libraries, "let foo = 1; exports.setFoo = value => { foo = value; };" |
| 285 ]) | 287 ]) |
| 286 )(); | 288 )(); |
| 287 | 289 |
| 288 test.done(); | 290 test.done(); |
| 289 }; | 291 }; |
| LEFT | RIGHT |