LEFT | RIGHT |
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 let {createSandbox} = require("./_common"); |
21 let sandboxedRequire = createSandbox(); | 21 |
22 | 22 let ElemHide = null; |
23 let {ElemHide} = sandboxedRequire("elemHide"); | 23 let Filter = null; |
24 let {Filter} = sandboxedRequire("filterClasses"); | 24 |
| 25 exports.setUp = function(callback) |
| 26 { |
| 27 let sandboxedRequire = createSandbox(); |
| 28 ( |
| 29 {ElemHide} = sandboxedRequire("../lib/elemHide"), |
| 30 {Filter} = sandboxedRequire("../lib/filterClasses") |
| 31 ); |
| 32 |
| 33 callback(); |
| 34 }; |
25 | 35 |
26 exports.testGetSelectorsForDomain = function(test) | 36 exports.testGetSelectorsForDomain = function(test) |
27 { | 37 { |
28 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); | 38 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); |
29 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); | 39 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); |
30 | 40 |
31 function normalizeSelectors(selectors) | 41 function normalizeSelectors(selectors) |
32 { | 42 { |
33 // getSelectorsForDomain is currently allowed to return duplicate selectors | 43 // getSelectorsForDomain is currently allowed to return duplicate selectors |
34 // for performance reasons, so we need to remove duplicates here. | 44 // for performance reasons, so we need to remove duplicates here. |
35 return selectors.sort().filter((selector, index, selectors) => | 45 return selectors.sort().filter((selector, index, selectors) => |
36 { | 46 { |
37 return index == 0 || selector != selectors[index - 1]; | 47 return index == 0 || selector != selectors[index - 1]; |
38 }); | 48 }); |
39 } | 49 } |
40 function testResult(domain, expectedSelectors, criteria) | 50 function testResult(domain, expectedSelectors, criteria) |
41 { | 51 { |
42 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors); | 52 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors); |
43 | 53 |
44 // Test without filter keys | 54 // Test without filter keys |
45 test.deepEqual( | 55 test.deepEqual( |
46 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), | 56 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), |
47 normalizedExpectedSelectors | 57 normalizedExpectedSelectors |
48 ); | 58 ); |
49 | 59 |
50 // With filter keys | 60 // With filter keys |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 testResult("", ["dupe"]); | 252 testResult("", ["dupe"]); |
243 removeFilter("foo.com##dupe"); | 253 removeFilter("foo.com##dupe"); |
244 testResult("", ["dupe"]); | 254 testResult("", ["dupe"]); |
245 removeFilter(",,##dupe"); | 255 removeFilter(",,##dupe"); |
246 testResult("", ["dupe"]); | 256 testResult("", ["dupe"]); |
247 removeFilter("##dupe"); | 257 removeFilter("##dupe"); |
248 testResult("", []); | 258 testResult("", []); |
249 | 259 |
250 test.done(); | 260 test.done(); |
251 }; | 261 }; |
LEFT | RIGHT |