Left: | ||
Right: |
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 | 50 // Test without filter keys |
Manish Jethani
2018/04/20 21:08:29
We should remove this comment.
kzar
2018/04/23 10:23:37
Done.
| |
51 test.deepEqual( | 51 test.deepEqual( |
52 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), | 52 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), |
53 normalizedExpectedSelectors | 53 normalizedExpectedSelectors |
54 ); | 54 ); |
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 } | 55 } |
63 | 56 |
64 exports.testGetSelectorsForDomain = function(test) | 57 exports.testGetSelectorsForDomain = function(test) |
65 { | 58 { |
66 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); | 59 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); |
67 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); | 60 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); |
68 | 61 |
69 testResult(test, "", []); | 62 testResult(test, "", []); |
70 | 63 |
71 addFilter("~foo.example.com,example.com##foo"); | 64 addFilter("~foo.example.com,example.com##foo"); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 }; | 239 }; |
247 | 240 |
248 exports.testZeroFilterKey = function(test) | 241 exports.testZeroFilterKey = function(test) |
249 { | 242 { |
250 ElemHide.add(Filter.fromText("##test")); | 243 ElemHide.add(Filter.fromText("##test")); |
251 ElemHide.add(Filter.fromText("foo.com#@#test")); | 244 ElemHide.add(Filter.fromText("foo.com#@#test")); |
252 testResult(test, "foo.com", []); | 245 testResult(test, "foo.com", []); |
253 testResult(test, "bar.com", ["test"]); | 246 testResult(test, "bar.com", ["test"]); |
254 test.done(); | 247 test.done(); |
255 }; | 248 }; |
OLD | NEW |