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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 {Filter} = sandboxedRequire("../lib/filterClasses") | 30 {Filter} = sandboxedRequire("../lib/filterClasses") |
31 ); | 31 ); |
32 | 32 |
33 callback(); | 33 callback(); |
34 }; | 34 }; |
35 | 35 |
36 function normalizeSelectors(selectors) | 36 function normalizeSelectors(selectors) |
37 { | 37 { |
38 // getSelectorsForDomain is currently allowed to return duplicate selectors | 38 // getSelectorsForDomain is currently allowed to return duplicate selectors |
39 // for performance reasons, so we need to remove duplicates here. | 39 // for performance reasons, so we need to remove duplicates here. |
40 return selectors.sort().filter((selector, index, selectors) => | 40 return selectors.sort().filter((selector, index, sortedSelectors) => |
41 { | 41 { |
42 return index == 0 || selector != selectors[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 |
51 test.deepEqual( | 51 test.deepEqual( |
52 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), | 52 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 testResult(test, "foo.com", [], ElemHide.ALL_MATCHING); | 208 testResult(test, "foo.com", [], ElemHide.ALL_MATCHING); |
209 testResult(test, "foo.com", []); | 209 testResult(test, "foo.com", []); |
210 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); | 210 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); |
211 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL); | 211 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL); |
212 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING); | 212 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING); |
213 testResult(test, "bar.com", ["hello"]); | 213 testResult(test, "bar.com", ["hello"]); |
214 removeFilter("foo.com#@#hello"); | 214 removeFilter("foo.com#@#hello"); |
215 testResult(test, "foo.com", [], ElemHide.SPECIFIC_ONLY); | 215 testResult(test, "foo.com", [], ElemHide.SPECIFIC_ONLY); |
216 // Note: We don't take care to track conditional selectors which became | 216 // Note: We don't take care to track conditional selectors which became |
217 // unconditional when a filter was removed. This was too expensive. | 217 // unconditional when a filter was removed. This was too expensive. |
218 //testResult(test, "foo.com", [], ElemHide.NO_UNCONDITIONAL); | 218 // testResult(test, "foo.com", [], ElemHide.NO_UNCONDITIONAL); |
219 testResult(test, "foo.com", ["hello"], ElemHide.ALL_MATCHING); | 219 testResult(test, "foo.com", ["hello"], ElemHide.ALL_MATCHING); |
220 testResult(test, "foo.com", ["hello"]); | 220 testResult(test, "foo.com", ["hello"]); |
221 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); | 221 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); |
222 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL); | 222 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL); |
223 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING); | 223 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING); |
224 testResult(test, "bar.com", ["hello"]); | 224 testResult(test, "bar.com", ["hello"]); |
225 removeFilter("##hello"); | 225 removeFilter("##hello"); |
226 testResult(test, "foo.com", []); | 226 testResult(test, "foo.com", []); |
227 testResult(test, "bar.com", []); | 227 testResult(test, "bar.com", []); |
228 | 228 |
(...skipping 17 matching lines...) Expand all Loading... |
246 }; | 246 }; |
247 | 247 |
248 exports.testZeroFilterKey = function(test) | 248 exports.testZeroFilterKey = function(test) |
249 { | 249 { |
250 ElemHide.add(Filter.fromText("##test")); | 250 ElemHide.add(Filter.fromText("##test")); |
251 ElemHide.add(Filter.fromText("foo.com#@#test")); | 251 ElemHide.add(Filter.fromText("foo.com#@#test")); |
252 testResult(test, "foo.com", []); | 252 testResult(test, "foo.com", []); |
253 testResult(test, "bar.com", ["test"]); | 253 testResult(test, "bar.com", ["test"]); |
254 test.done(); | 254 test.done(); |
255 }; | 255 }; |
OLD | NEW |