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

Side by Side Diff: test/elemHide.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Patch Set: Removed unused imports Created March 15, 2017, 3:11 a.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 | « test/domainRestrictions.js ('k') | test/elemHideEmulation.js » ('j') | 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 let {createSandbox} = require("./_common"); 20 const {createSandbox} = require("./_common");
21 21
22 let ElemHide = null; 22 let ElemHide = null;
23 let Filter = null; 23 let Filter = null;
24 24
25 exports.setUp = function(callback) 25 exports.setUp = function(callback)
26 { 26 {
27 let sandboxedRequire = createSandbox(); 27 let sandboxedRequire = createSandbox();
28 ( 28 (
29 {ElemHide} = sandboxedRequire("../lib/elemHide"), 29 {ElemHide} = sandboxedRequire("../lib/elemHide"),
30 {Filter} = sandboxedRequire("../lib/filterClasses") 30 {Filter} = sandboxedRequire("../lib/filterClasses")
31 ); 31 );
32 32
33 callback(); 33 callback();
34 }; 34 };
35 35
36 function normalizeSelectors(selectors) 36 function normalizeSelectors(selectors)
37 { 37 {
38 // getSelectorsForDomain is currently allowed to return duplicate selectors 38 // getSelectorsForDomain is currently allowed to return duplicate selectors
39 // for performance reasons, so we need to remove duplicates here. 39 // for performance reasons, so we need to remove duplicates here.
40 return selectors.sort().filter((selector, index, selectors) => 40 return selectors.sort().filter((selector, index, sortedSelectors) =>
41 { 41 {
42 return index == 0 || selector != selectors[index - 1]; 42 return index == 0 || selector != sortedSelectors[index - 1];
43 }); 43 });
44 } 44 }
45 45
46 function testResult(test, domain, expectedSelectors, criteria) 46 function testResult(test, domain, expectedSelectors, criteria)
47 { 47 {
48 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors); 48 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors);
49 49
50 // Test without filter keys 50 // Test without filter keys
51 test.deepEqual( 51 test.deepEqual(
52 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), 52 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)),
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 testResult(test, "foo.com", [], ElemHide.ALL_MATCHING); 208 testResult(test, "foo.com", [], ElemHide.ALL_MATCHING);
209 testResult(test, "foo.com", []); 209 testResult(test, "foo.com", []);
210 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); 210 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY);
211 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL); 211 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL);
212 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING); 212 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING);
213 testResult(test, "bar.com", ["hello"]); 213 testResult(test, "bar.com", ["hello"]);
214 removeFilter("foo.com#@#hello"); 214 removeFilter("foo.com#@#hello");
215 testResult(test, "foo.com", [], ElemHide.SPECIFIC_ONLY); 215 testResult(test, "foo.com", [], ElemHide.SPECIFIC_ONLY);
216 // Note: We don't take care to track conditional selectors which became 216 // Note: We don't take care to track conditional selectors which became
217 // unconditional when a filter was removed. This was too expensive. 217 // unconditional when a filter was removed. This was too expensive.
218 //testResult(test, "foo.com", [], ElemHide.NO_UNCONDITIONAL); 218 // testResult(test, "foo.com", [], ElemHide.NO_UNCONDITIONAL);
219 testResult(test, "foo.com", ["hello"], ElemHide.ALL_MATCHING); 219 testResult(test, "foo.com", ["hello"], ElemHide.ALL_MATCHING);
220 testResult(test, "foo.com", ["hello"]); 220 testResult(test, "foo.com", ["hello"]);
221 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); 221 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY);
222 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL); 222 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL);
223 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING); 223 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING);
224 testResult(test, "bar.com", ["hello"]); 224 testResult(test, "bar.com", ["hello"]);
225 removeFilter("##hello"); 225 removeFilter("##hello");
226 testResult(test, "foo.com", []); 226 testResult(test, "foo.com", []);
227 testResult(test, "bar.com", []); 227 testResult(test, "bar.com", []);
228 228
(...skipping 17 matching lines...) Expand all
246 }; 246 };
247 247
248 exports.testZeroFilterKey = function(test) 248 exports.testZeroFilterKey = function(test)
249 { 249 {
250 ElemHide.add(Filter.fromText("##test")); 250 ElemHide.add(Filter.fromText("##test"));
251 ElemHide.add(Filter.fromText("foo.com#@#test")); 251 ElemHide.add(Filter.fromText("foo.com#@#test"));
252 testResult(test, "foo.com", []); 252 testResult(test, "foo.com", []);
253 testResult(test, "bar.com", ["test"]); 253 testResult(test, "bar.com", ["test"]);
254 test.done(); 254 test.done();
255 }; 255 };
OLDNEW
« no previous file with comments | « test/domainRestrictions.js ('k') | test/elemHideEmulation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld