OLD | NEW |
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) |
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 Loading... |
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 }; |
OLD | NEW |