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 23 matching lines...) Expand all Loading... |
34 | 34 |
35 function normalizeSelectors(selectors) | 35 function normalizeSelectors(selectors) |
36 { | 36 { |
37 // getSelectorsForDomain is currently allowed to return duplicate selectors | 37 // getSelectorsForDomain is currently allowed to return duplicate selectors |
38 // for performance reasons, so we need to remove duplicates here. | 38 // for performance reasons, so we need to remove duplicates here. |
39 return selectors.sort().filter((selector, index, selectors) => | 39 return selectors.sort().filter((selector, index, selectors) => |
40 { | 40 { |
41 return index == 0 || selector != selectors[index - 1]; | 41 return index == 0 || selector != selectors[index - 1]; |
42 }); | 42 }); |
43 } | 43 } |
44 function selectorsEqual(domain, expectedSelectors, specificOnly) | 44 function selectorsEqual(domain, expectedSelectors, specificOnly, |
| 45 noUnconditional, provideFilterKeys) |
45 { | 46 { |
46 test.deepEqual( | 47 test.deepEqual( |
47 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)), | 48 normalizeSelectors(ElemHide.getSelectorsForDomain( |
| 49 domain, specificOnly, noUnconditional, provideFilterKeys |
| 50 )), |
48 normalizeSelectors(expectedSelectors) | 51 normalizeSelectors(expectedSelectors) |
49 ); | 52 ); |
50 } | 53 } |
51 | 54 |
52 selectorsEqual("", []); | 55 selectorsEqual("", []); |
53 | 56 |
54 addFilter("~foo.example.com,example.com##foo"); | 57 addFilter("~foo.example.com,example.com##foo"); |
55 selectorsEqual("barfoo.example.com", ["foo"]); | 58 selectorsEqual("barfoo.example.com", ["foo"]); |
56 selectorsEqual("bar.foo.example.com", []); | 59 selectorsEqual("bar.foo.example.com", []); |
57 selectorsEqual("foo.example.com", []); | 60 selectorsEqual("foo.example.com", []); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 selectorsEqual("example.com", ["foo"]); | 155 selectorsEqual("example.com", ["foo"]); |
153 selectorsEqual("com", []); | 156 selectorsEqual("com", []); |
154 selectorsEqual("", []); | 157 selectorsEqual("", []); |
155 removeFilter("example.org##foo"); | 158 removeFilter("example.org##foo"); |
156 | 159 |
157 addFilter("~example.com##foo"); | 160 addFilter("~example.com##foo"); |
158 selectorsEqual("foo.example.com", []); | 161 selectorsEqual("foo.example.com", []); |
159 selectorsEqual("example.com", ["foo"]); | 162 selectorsEqual("example.com", ["foo"]); |
160 selectorsEqual("com", ["foo"]); | 163 selectorsEqual("com", ["foo"]); |
161 selectorsEqual("", ["foo"]); | 164 selectorsEqual("", ["foo"]); |
162 removeFilter("example.org##foo"); | 165 removeFilter("~example.org##foo"); |
| 166 |
| 167 // Test specificOnly and noUnconditional |
| 168 addFilter("~example.com##foo"); |
| 169 selectorsEqual("foo.com", [], true, false); |
| 170 selectorsEqual("foo.com", ["foo"], false, true); |
| 171 addFilter("foo.com##foo"); |
| 172 selectorsEqual("foo.com", ["foo"], true, false); |
| 173 selectorsEqual("foo.com", ["foo"], false, true); |
| 174 removeFilter("foo.com##foo"); |
| 175 removeFilter("~example.org##foo"); |
| 176 |
| 177 // Test provideFilterKeys |
| 178 addFilter("~foo.com##nope"); |
| 179 addFilter("##foo"); |
| 180 addFilter("##bar"); |
| 181 addFilter("##hello"); |
| 182 addFilter("##world"); |
| 183 let selectorsWithKeys = ElemHide.getSelectorsForDomain("foo.com", false, |
| 184 false, true); |
| 185 let selectors = selectorsWithKeys[0]; |
| 186 let filterKeys = selectorsWithKeys[1]; |
| 187 test.deepEqual(filterKeys.map(k => ElemHide.getFilterByKey(k).selector), |
| 188 selectors); |
| 189 test.deepEqual(normalizeSelectors(selectors), |
| 190 normalizeSelectors(["bar", "foo", "hello", "world"])); |
| 191 removeFilter("##world"); |
| 192 removeFilter("##hello"); |
| 193 removeFilter("##bar"); |
| 194 removeFilter("##foo"); |
| 195 removeFilter("~foo.com##nope"); |
163 | 196 |
164 test.done(); | 197 test.done(); |
165 }; | 198 }; |
OLD | NEW |