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

Side by Side Diff: test/snippets.js

Issue 29761597: Issue 6538, 6781 - Implement script parsing for snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Move parseScript to top level Created April 26, 2018, 2:27 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/snippets.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 "use strict"; 18 "use strict";
19 19
20 const {createSandbox} = require("./_common"); 20 const {createSandbox} = require("./_common");
21 21
22 let SnippetFilter = null; 22 let SnippetFilter = null;
23 let Snippets = null; 23 let Snippets = null;
24 let parseScript = null;
24 let ElemHide = null; 25 let ElemHide = null;
25 let Filter = null; 26 let Filter = null;
26 27
27 exports.setUp = function(callback) 28 exports.setUp = function(callback)
28 { 29 {
29 let sandboxedRequire = createSandbox(); 30 let sandboxedRequire = createSandbox();
30 ( 31 (
31 {Filter, SnippetFilter} = sandboxedRequire("../lib/filterClasses"), 32 {Filter, SnippetFilter} = sandboxedRequire("../lib/filterClasses"),
32 {ElemHide} = sandboxedRequire("../lib/elemHide"), 33 {ElemHide} = sandboxedRequire("../lib/elemHide"),
33 {Snippets} = sandboxedRequire("../lib/snippets") 34 {Snippets, parseScript} = sandboxedRequire("../lib/snippets")
34 ); 35 );
35 36
36 callback(); 37 callback();
37 }; 38 };
38 39
39 exports.testDomainRestrictions = function(test) 40 exports.testDomainRestrictions = function(test)
40 { 41 {
41 function testSelectorMatches(description, filters, domain, expectedMatches) 42 function testSelectorMatches(description, filters, domain, expectedMatches)
42 { 43 {
43 for (let filter of filters) 44 for (let filter of filters)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 130
130 Snippets.clear(); 131 Snippets.clear();
131 compareRules( 132 compareRules(
132 "Return no filters after clearing", 133 "Return no filters after clearing",
133 "www.example.com", 134 "www.example.com",
134 [] 135 []
135 ); 136 );
136 137
137 test.done(); 138 test.done();
138 }; 139 };
140
141 exports.testScriptParsing = function(test)
142 {
143 function checkParsedScript(description, script, expectedTree)
144 {
145 let tree = parseScript(script);
146 test.deepEqual(tree, expectedTree, description);
147 }
148
149 checkParsedScript("Script with no arguments", "foo", [["foo"]]);
150 checkParsedScript("Script with one argument", "foo 1", [["foo", "1"]]);
151 checkParsedScript("Script with two arguments", "foo 1 Hello",
152 [["foo", "1", "Hello"]]);
153 checkParsedScript("Script with argument containing an escaped space",
154 "foo Hello\\ world",
155 [["foo", "Hello world"]]);
156 checkParsedScript("Script with argument containing a quoted space",
157 "foo 'Hello world'",
158 [["foo", "Hello world"]]);
159 checkParsedScript("Script with argument containing a quoted escaped quote",
160 "foo 'Hello \\'world\\''",
161 [["foo", "Hello 'world'"]]);
162 checkParsedScript("Script with argument containing an escaped semicolon",
163 "foo TL\\;DR",
164 [["foo", "TL;DR"]]);
165 checkParsedScript("Script with argument containing a quoted semicolon",
166 "foo 'TL;DR'",
167 [["foo", "TL;DR"]]);
168 checkParsedScript("Script with multiple commands", "foo; bar",
169 [["foo"], ["bar"]]);
170 checkParsedScript("Script with multiple commands and multiple arguments each",
171 "foo 1 Hello; bar world! #",
172 [["foo", "1", "Hello"], ["bar", "world!", "#"]]);
173 checkParsedScript(
174 "Script with multiple commands and multiple " +
175 "escaped and quoted arguments each",
176 "foo 1 'Hello, \\'Tommy\\'!' ;" +
177 "bar Hi!\\ How\\ are\\ you? http://example.com",
178 [["foo", "1", "Hello, 'Tommy'!"],
179 ["bar", "Hi! How are you?", "http://example.com"]]
180 );
181 checkParsedScript("Script with command names containing " +
182 "whitespace (spaces, tabs, newlines, etc.), " +
183 "quotes, and semicolons",
184 "fo\\'\\ \\ \\\t\\\n\\;o 1 2 3; 'b a r' 1 2",
185 [["fo' \t\n;o", "1", "2", "3"], ["b a r", "1", "2"]]);
186 checkParsedScript("Script containing Unicode composite characters",
187 "f\ud83d\ude42\ud83d\ude42 b\ud83d\ude02r",
188 [["f\ud83d\ude42\ud83d\ude42", "b\ud83d\ude02r"]]);
189 checkParsedScript("Script with no-op commands", "foo; ;;; ; ; bar 1",
190 [["foo"], ["bar", "1"]]);
191
192 test.done();
193 };
OLDNEW
« no previous file with comments | « lib/snippets.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld