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

Side by Side Diff: test/snippets.js

Issue 29849575: Issue 6797 - Require active domains in snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add tests Created Aug. 7, 2018, 2:49 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 | « lib/filterClasses.js ('k') | 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 /* 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /* eslint no-new-func: "off" */ 18 /* eslint no-new-func: "off" */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {createSandbox} = require("./_common"); 22 const {createSandbox} = require("./_common");
23 23
24 let Snippets = null; 24 let Snippets = null;
25 let parseScript = null; 25 let parseScript = null;
26 let compileScript = null; 26 let compileScript = null;
27 let Filter = null; 27 let Filter = null;
28 let SnippetFilter = null;
28 29
29 exports.setUp = function(callback) 30 exports.setUp = function(callback)
30 { 31 {
31 let sandboxedRequire = createSandbox(); 32 let sandboxedRequire = createSandbox();
32 ( 33 (
33 {Filter} = sandboxedRequire("../lib/filterClasses"), 34 {Filter, SnippetFilter} = sandboxedRequire("../lib/filterClasses"),
34 {Snippets, parseScript, compileScript} = sandboxedRequire("../lib/snippets") 35 {Snippets, parseScript, compileScript} = sandboxedRequire("../lib/snippets")
35 ); 36 );
36 37
37 callback(); 38 callback();
38 }; 39 };
39 40
40 exports.testDomainRestrictions = function(test) 41 exports.testDomainRestrictions = function(test)
41 { 42 {
42 function testScriptMatches(description, filters, domain, expectedMatches) 43 function testScriptMatches(description, filters, domain, expectedMatches)
43 { 44 {
44 for (let filter of filters) 45 for (let filter of filters.map(Filter.fromText))
45 Snippets.add(Filter.fromText(filter)); 46 {
47 if (filter instanceof SnippetFilter)
48 Snippets.add(filter);
49 }
46 50
47 let matches = Snippets.getScriptsForDomain(domain); 51 let matches = Snippets.getScriptsForDomain(domain);
48 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 52 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
49 53
50 Snippets.clear(); 54 Snippets.clear();
51 } 55 }
52 56
53 testScriptMatches( 57 testScriptMatches(
58 "Ignore generic filters",
59 [
60 "#$#foo", "example.com#$#foo",
kzar 2018/08/08 11:31:50 Shouldn't we use different snippet names for these
Manish Jethani 2018/08/08 13:56:42 Thanks, this makes sense. Done.
61 "~example.com#$#foo"
62 ],
63 "example.com",
64 ["foo"]
65 );
66 testScriptMatches(
54 "Ignore filters that include parent domain but exclude subdomain", 67 "Ignore filters that include parent domain but exclude subdomain",
55 [ 68 [
56 "~www.example.com,example.com#$#foo" 69 "~www.example.com,example.com#$#foo"
57 ], 70 ],
58 "www.example.com", 71 "www.example.com",
59 [] 72 []
60 ); 73 );
61 testScriptMatches( 74 testScriptMatches(
62 "Ignore filters for other subdomain", 75 "Ignore filters for other subdomain",
63 [ 76 [
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // between executions. In the example below, assertFoo does not find 456 but 247 // between executions. In the example below, assertFoo does not find 456 but
235 // it doesn't find 123 either. It's the initial value 0. 248 // it doesn't find 123 either. It's the initial value 0.
236 new Function( 249 new Function(
237 compileScript("setFoo 456; assertFoo 0", [ 250 compileScript("setFoo 456; assertFoo 0", [
238 ...libraries, "let foo = 1; exports.setFoo = value => { foo = value; };" 251 ...libraries, "let foo = 1; exports.setFoo = value => { foo = value; };"
239 ]) 252 ])
240 )(); 253 )();
241 254
242 test.done(); 255 test.done();
243 }; 256 };
OLDNEW
« no previous file with comments | « lib/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld