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

Side by Side Diff: test/elemHide.js

Issue 29354864: Issue 4223 - Migrate some more of adblockplustests (Closed)
Patch Set: Use sandboxed-module Created Sept. 29, 2016, 3:44 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 | « test/domainRestrictions.js ('k') | test/filterClasses.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 GLOBAL.Ci = {}; 20 let {createSandbox} = require("common");
21 GLOBAL.Cu = { 21 let sandboxedRequire = createSandbox();
22 import: function()
23 {
24 }
25 };
26 22
27 let {ElemHide} = require("elemHide"); 23 let {ElemHide} = sandboxedRequire("elemHide");
28 let {Filter} = require("filterClasses"); 24 let {Filter} = sandboxedRequire("filterClasses");
29 25
30 exports.testGetSelectorsForDomain = function(test) 26 exports.testGetSelectorsForDomain = function(test)
31 { 27 {
32 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); 28 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText));
33 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); 29 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText));
34 30
35 function normalizeSelectors(selectors) 31 function normalizeSelectors(selectors)
36 { 32 {
37 // getSelectorsForDomain is currently allowed to return duplicate selectors 33 // getSelectorsForDomain is currently allowed to return duplicate selectors
38 // for performance reasons, so we need to remove duplicates here. 34 // for performance reasons, so we need to remove duplicates here.
39 return selectors.sort().filter((selector, index, selectors) => 35 return selectors.sort().filter((selector, index, selectors) =>
40 { 36 {
41 return index == 0 || selector != selectors[index - 1]; 37 return index == 0 || selector != selectors[index - 1];
42 }); 38 });
43 } 39 }
44 function testResult(domain, expectedSelectors, criteria) 40 function testResult(domain, expectedSelectors, criteria)
kzar 2016/09/29 15:53:10 (These changes are due to rebasing.)
45 { 41 {
46 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors); 42 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors);
47 43
48 // Test without filter keys 44 // Test without filter keys
49 test.deepEqual( 45 test.deepEqual(
50 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), 46 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)),
51 normalizedExpectedSelectors 47 normalizedExpectedSelectors
52 ); 48 );
53 49
54 // With filter keys 50 // With filter keys
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 testResult("", ["dupe"]); 242 testResult("", ["dupe"]);
247 removeFilter("foo.com##dupe"); 243 removeFilter("foo.com##dupe");
248 testResult("", ["dupe"]); 244 testResult("", ["dupe"]);
249 removeFilter(",,##dupe"); 245 removeFilter(",,##dupe");
250 testResult("", ["dupe"]); 246 testResult("", ["dupe"]);
251 removeFilter("##dupe"); 247 removeFilter("##dupe");
252 testResult("", []); 248 testResult("", []);
253 249
254 test.done(); 250 test.done();
255 }; 251 };
OLDNEW
« no previous file with comments | « test/domainRestrictions.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld