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

Side by Side Diff: test/elemHideEmulation.js

Issue 29783618: Issue 6665 - Split out element hiding exceptions into their own module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add lib/elemHideExceptions.js Created Aug. 7, 2018, 2:18 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/elemHide.js ('k') | test/filterListener.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-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 ElemHideEmulationFilter = null; 22 let ElemHideEmulationFilter = null;
23 let ElemHideEmulation = null; 23 let ElemHideEmulation = null;
24 let ElemHide = null; 24 let ElemHideExceptions = null;
25 let Filter = null; 25 let Filter = null;
26 26
27 exports.setUp = function(callback) 27 exports.setUp = function(callback)
28 { 28 {
29 let sandboxedRequire = createSandbox(); 29 let sandboxedRequire = createSandbox();
30 ( 30 (
31 {Filter, 31 {Filter,
32 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"), 32 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"),
33 {ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"), 33 {ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"),
34 {ElemHide} = sandboxedRequire("../lib/elemHide") 34 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions")
35 ); 35 );
36 36
37 callback(); 37 callback();
38 }; 38 };
39 39
40 exports.testDomainRestrictions = function(test) 40 exports.testDomainRestrictions = function(test)
41 { 41 {
42 function testSelectorMatches(description, filters, domain, expectedMatches) 42 function testSelectorMatches(description, filters, domain, expectedMatches)
43 { 43 {
44 for (let filter of filters) 44 for (let filter of filters)
45 { 45 {
46 filter = Filter.fromText(filter); 46 filter = Filter.fromText(filter);
47 if (filter instanceof ElemHideEmulationFilter) 47 if (filter instanceof ElemHideEmulationFilter)
48 ElemHideEmulation.add(filter); 48 ElemHideEmulation.add(filter);
49 else 49 else
50 ElemHide.add(filter); 50 ElemHideExceptions.add(filter);
51 } 51 }
52 52
53 let matches = ElemHideEmulation.getRulesForDomain(domain) 53 let matches = ElemHideEmulation.getRulesForDomain(domain)
54 .map(filter => filter.text); 54 .map(filter => filter.text);
55 test.deepEqual(matches.sort(), expectedMatches.sort(), description); 55 test.deepEqual(matches.sort(), expectedMatches.sort(), description);
56 56
57 ElemHideEmulation.clear(); 57 ElemHideEmulation.clear();
58 ElemHide.clear(); 58 ElemHideExceptions.clear();
59 } 59 }
60 60
61 testSelectorMatches( 61 testSelectorMatches(
62 "Ignore generic filters", 62 "Ignore generic filters",
63 [ 63 [
64 "#?#:-abp-properties(foo)", "example.com#?#:-abp-properties(foo)", 64 "#?#:-abp-properties(foo)", "example.com#?#:-abp-properties(foo)",
65 "~example.com#?#:-abp-properties(foo)" 65 "~example.com#?#:-abp-properties(foo)"
66 ], 66 ],
67 "example.com", 67 "example.com",
68 ["example.com#?#:-abp-properties(foo)"] 68 ["example.com#?#:-abp-properties(foo)"]
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 ElemHideEmulation.clear(); 140 ElemHideEmulation.clear();
141 compareRules( 141 compareRules(
142 "Return no filters after clearing", 142 "Return no filters after clearing",
143 "www.example.com", 143 "www.example.com",
144 [] 144 []
145 ); 145 );
146 146
147 test.done(); 147 test.done();
148 }; 148 };
OLDNEW
« no previous file with comments | « test/elemHide.js ('k') | test/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld