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

Delta Between Two Patch Sets: test/snippets.js

Issue 29849575: Issue 6797 - Require active domains in snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Aug. 7, 2018, 2:39 p.m.
Right Patch Set: Use different snippets names Created Aug. 8, 2018, 1:55 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « lib/filterClasses.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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
57 testScriptMatches(
58 "Ignore generic filters",
59 [
60 "#$#foo-1", "example.com#$#foo-2",
61 "~example.com#$#foo-3"
62 ],
63 "example.com",
64 ["foo-2"]
65 );
53 testScriptMatches( 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 [
64 "www.example.com#$#foo", 77 "www.example.com#$#foo-1",
65 "other.example.com#$#foo" 78 "other.example.com#$#foo-2"
66 ], 79 ],
67 "other.example.com", 80 "other.example.com",
68 ["foo"] 81 ["foo-2"]
69 ); 82 );
70 83
71 test.done(); 84 test.done();
72 }; 85 };
73 86
74 exports.testSnippetFiltersContainer = function(test) 87 exports.testSnippetFiltersContainer = function(test)
75 { 88 {
76 function compareRules(description, domain, expectedMatches) 89 function compareRules(description, domain, expectedMatches)
77 { 90 {
78 let result = Snippets.getScriptsForDomain(domain); 91 let result = Snippets.getScriptsForDomain(domain);
(...skipping 155 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 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld