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-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 |
(...skipping 29 matching lines...) Expand all Loading... |
40 return selectors.sort().filter((selector, index, sortedSelectors) => | 40 return selectors.sort().filter((selector, index, sortedSelectors) => |
41 { | 41 { |
42 return index == 0 || selector != sortedSelectors[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 | |
51 test.deepEqual( | 50 test.deepEqual( |
52 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), | 51 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), |
53 normalizedExpectedSelectors | 52 normalizedExpectedSelectors |
54 ); | 53 ); |
55 | |
56 // With filter keys | |
57 let [selectors, filterKeys] = ElemHide.getSelectorsForDomain(domain, criteria, | |
58 true); | |
59 test.deepEqual(filterKeys.map(k => ElemHide.getFilterByKey(k).selector), | |
60 selectors); | |
61 test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors); | |
62 } | 54 } |
63 | 55 |
64 exports.testGetSelectorsForDomain = function(test) | 56 exports.testGetSelectorsForDomain = function(test) |
65 { | 57 { |
66 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); | 58 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); |
67 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); | 59 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); |
68 | 60 |
69 testResult(test, "", []); | 61 testResult(test, "", []); |
70 | 62 |
71 addFilter("~foo.example.com,example.com##foo"); | 63 addFilter("~foo.example.com,example.com##foo"); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 }; | 238 }; |
247 | 239 |
248 exports.testZeroFilterKey = function(test) | 240 exports.testZeroFilterKey = function(test) |
249 { | 241 { |
250 ElemHide.add(Filter.fromText("##test")); | 242 ElemHide.add(Filter.fromText("##test")); |
251 ElemHide.add(Filter.fromText("foo.com#@#test")); | 243 ElemHide.add(Filter.fromText("foo.com#@#test")); |
252 testResult(test, "foo.com", []); | 244 testResult(test, "foo.com", []); |
253 testResult(test, "bar.com", ["test"]); | 245 testResult(test, "bar.com", ["test"]); |
254 test.done(); | 246 test.done(); |
255 }; | 247 }; |
OLD | NEW |