Left: | ||
Right: |
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 GLOBAL.Ci = { }; | 20 GLOBAL.Ci = {}; |
Wladimir Palant
2016/05/23 13:23:02
Nit: We usually write that as {}, without any spac
kzar
2016/05/23 13:47:52
Done.
| |
21 GLOBAL.Cu = { | 21 GLOBAL.Cu = { |
22 import: function() { } | 22 import: function() |
Wladimir Palant
2016/05/23 13:23:02
Nit: eslint doesn't like that, should have proper
kzar
2016/05/23 13:47:52
Done.
| |
23 { | |
24 } | |
23 }; | 25 }; |
24 | 26 |
25 let {ElemHide} = require("elemHide"); | 27 let {ElemHide} = require("elemHide"); |
26 let {Filter} = require("filterClasses"); | 28 let {Filter} = require("filterClasses"); |
27 | 29 |
28 exports.testGetSelectorsForDomain = function(test) | 30 exports.testGetSelectorsForDomain = function(test) |
29 { | 31 { |
30 function fromText(f) | 32 function fromText(f) |
31 { | 33 { |
32 return (filterText) => ElemHide[f](Filter.fromText(filterText)); | 34 return (filterText) => f(Filter.fromText(filterText)); |
33 } | 35 } |
34 let addFilter = fromText("add"); | 36 let addFilter = fromText(ElemHide.add); |
35 let removeFilter = fromText("remove"); | 37 let removeFilter = fromText(ElemHide.remove); |
Wladimir Palant
2016/05/23 13:23:02
Nit: I'd rather pass in the actual function: ElemH
kzar
2016/05/23 13:47:52
Done.
| |
36 | 38 |
37 function selectorsEqual(domain, selectors, specificOnly) | 39 function normalizeSelectors(selectors) |
38 { | 40 { |
39 test.deepEqual(ElemHide.getSelectorsForDomain(domain, specificOnly).sort(), | 41 // getSelectorsForDomain is currently allowed to return duplicate selectors |
kzar
2016/05/23 11:46:50
Different implementations produce the selectors in
Wladimir Palant
2016/05/23 13:23:02
Yes, I was about to comment on this but you alread
| |
40 selectors.sort()); | 42 // for performance reasons, so we need to remove duplicates here. |
43 return selectors.sort().filter((selector, index, selectors) => | |
44 { | |
45 return index == 0 || selector != selectors[index - 1]; | |
46 }); | |
47 } | |
48 function selectorsEqual(domain, expectedSelectors, specificOnly) | |
49 { | |
50 test.deepEqual( | |
51 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)), | |
52 normalizeSelectors(expectedSelectors) | |
53 ); | |
41 } | 54 } |
42 | 55 |
43 selectorsEqual("", []); | 56 selectorsEqual("", []); |
44 | 57 |
45 addFilter("~foo.example.com,example.com##foo"); | 58 addFilter("~foo.example.com,example.com##foo"); |
59 selectorsEqual("barfoo.example.com", ["foo"]); | |
60 selectorsEqual("bar.foo.example.com", []); | |
46 selectorsEqual("foo.example.com", []); | 61 selectorsEqual("foo.example.com", []); |
47 selectorsEqual("example.com", ["foo"]); | 62 selectorsEqual("example.com", ["foo"]); |
Wladimir Palant
2016/05/23 13:23:01
How about testing bar.example.com as well, to see
kzar
2016/05/23 13:47:52
Done.
| |
48 selectorsEqual("com", []); | 63 selectorsEqual("com", []); |
49 selectorsEqual("", []); | 64 selectorsEqual("", []); |
50 | 65 |
51 addFilter("foo.example.com##turnip"); | 66 addFilter("foo.example.com##turnip"); |
52 selectorsEqual("foo.example.com", ["turnip"]); | 67 selectorsEqual("foo.example.com", ["turnip"]); |
53 selectorsEqual("example.com", ["foo"]); | 68 selectorsEqual("example.com", ["foo"]); |
54 selectorsEqual("com", []); | 69 selectorsEqual("com", []); |
55 selectorsEqual("", []); | 70 selectorsEqual("", []); |
56 | 71 |
57 addFilter("example.com#@#foo"); | 72 addFilter("example.com#@#foo"); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 removeFilter("com##bar"); | 126 removeFilter("com##bar"); |
112 selectorsEqual("foo.example.com", ["turnip"]); | 127 selectorsEqual("foo.example.com", ["turnip"]); |
113 selectorsEqual("example.com", []); | 128 selectorsEqual("example.com", []); |
114 selectorsEqual("com", []); | 129 selectorsEqual("com", []); |
115 selectorsEqual("", []); | 130 selectorsEqual("", []); |
116 | 131 |
117 removeFilter("foo.example.com##turnip"); | 132 removeFilter("foo.example.com##turnip"); |
118 selectorsEqual("foo.example.com", []); | 133 selectorsEqual("foo.example.com", []); |
119 selectorsEqual("example.com", []); | 134 selectorsEqual("example.com", []); |
120 selectorsEqual("com", []); | 135 selectorsEqual("com", []); |
121 selectorsEqual("", []); | 136 selectorsEqual("", []); |
Wladimir Palant
2016/05/23 13:23:01
This does a very thorough job testing interaction
kzar
2016/05/23 13:47:52
Done.
| |
122 | 137 |
123 // As a consession for performance we don't handle the case of more than one | |
124 // identical rule being added, then one of them removed. Ideally the final | |
125 // result here would be ["dupe"] instead of []. | |
Wladimir Palant
2016/05/23 13:23:02
This has nothing to do with performance - ElemHide
kzar
2016/05/23 13:47:52
Acknowledged.
| |
126 addFilter("example.com##dupe"); | 138 addFilter("example.com##dupe"); |
127 addFilter("example.com##dupe"); | 139 addFilter("example.com##dupe"); |
128 selectorsEqual("example.com", ["dupe"]); | 140 selectorsEqual("example.com", ["dupe"]); |
129 removeFilter("example.com##dupe"); | 141 removeFilter("example.com##dupe"); |
130 selectorsEqual("example.com", []); | 142 selectorsEqual("example.com", []); |
143 removeFilter("example.com##dupe"); | |
144 | |
145 addFilter("~foo.example.com,example.com##foo"); | |
146 | |
147 addFilter("##foo"); | |
148 selectorsEqual("foo.example.com", ["foo"]); | |
149 selectorsEqual("example.com", ["foo"]); | |
150 selectorsEqual("com", ["foo"]); | |
151 selectorsEqual("", ["foo"]); | |
152 removeFilter("##foo"); | |
153 | |
154 addFilter("example.org##foo"); | |
155 selectorsEqual("foo.example.com", []); | |
156 selectorsEqual("example.com", ["foo"]); | |
157 selectorsEqual("com", []); | |
158 selectorsEqual("", []); | |
159 removeFilter("example.org##foo"); | |
160 | |
161 addFilter("~example.com##foo"); | |
162 selectorsEqual("foo.example.com", []); | |
163 selectorsEqual("example.com", ["foo"]); | |
164 selectorsEqual("com", ["foo"]); | |
165 selectorsEqual("", ["foo"]); | |
166 removeFilter("example.org##foo"); | |
131 | 167 |
132 test.done(); | 168 test.done(); |
133 }; | 169 }; |
LEFT | RIGHT |