Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2016 Eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
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/>. | |
16 */ | |
17 | |
18 "use strict"; | |
19 | |
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 = { | |
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 | |
25 let {ElemHide} = require("elemHide"); | |
26 let {Filter} = require("filterClasses"); | |
27 | |
28 exports.testGetSelectorsForDomain = function(test) | |
29 { | |
30 function fromText(f) | |
31 { | |
32 return (filterText) => ElemHide[f](Filter.fromText(filterText)); | |
33 } | |
34 let addFilter = fromText("add"); | |
35 let removeFilter = fromText("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 | |
37 function selectorsEqual(domain, selectors, specificOnly) | |
38 { | |
39 test.deepEqual(ElemHide.getSelectorsForDomain(domain, specificOnly).sort(), | |
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()); | |
41 } | |
42 | |
43 selectorsEqual("", []); | |
44 | |
45 addFilter("~foo.example.com,example.com##foo"); | |
46 selectorsEqual("foo.example.com", []); | |
47 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", []); | |
49 selectorsEqual("", []); | |
50 | |
51 addFilter("foo.example.com##turnip"); | |
52 selectorsEqual("foo.example.com", ["turnip"]); | |
53 selectorsEqual("example.com", ["foo"]); | |
54 selectorsEqual("com", []); | |
55 selectorsEqual("", []); | |
56 | |
57 addFilter("example.com#@#foo"); | |
58 selectorsEqual("foo.example.com", ["turnip"]); | |
59 selectorsEqual("example.com", []); | |
60 selectorsEqual("com", []); | |
61 selectorsEqual("", []); | |
62 | |
63 addFilter("com##bar"); | |
64 selectorsEqual("foo.example.com", ["turnip", "bar"]); | |
65 selectorsEqual("example.com", ["bar"]); | |
66 selectorsEqual("com", ["bar"]); | |
67 selectorsEqual("", []); | |
68 | |
69 addFilter("example.com#@#bar"); | |
70 selectorsEqual("foo.example.com", ["turnip"]); | |
71 selectorsEqual("example.com", []); | |
72 selectorsEqual("com", ["bar"]); | |
73 selectorsEqual("", []); | |
74 | |
75 removeFilter("example.com#@#foo"); | |
76 selectorsEqual("foo.example.com", ["turnip"]); | |
77 selectorsEqual("example.com", ["foo"]); | |
78 selectorsEqual("com", ["bar"]); | |
79 selectorsEqual("", []); | |
80 | |
81 removeFilter("example.com#@#bar"); | |
82 selectorsEqual("foo.example.com", ["turnip", "bar"]); | |
83 selectorsEqual("example.com", ["foo", "bar"]); | |
84 selectorsEqual("com", ["bar"]); | |
85 selectorsEqual("", []); | |
86 | |
87 addFilter("##generic"); | |
88 selectorsEqual("foo.example.com", ["turnip", "bar", "generic"]); | |
89 selectorsEqual("example.com", ["foo", "bar", "generic"]); | |
90 selectorsEqual("com", ["bar", "generic"]); | |
91 selectorsEqual("", ["generic"]); | |
92 selectorsEqual("foo.example.com", ["turnip", "bar"], true); | |
93 selectorsEqual("example.com", ["foo", "bar"], true); | |
94 selectorsEqual("com", ["bar"], true); | |
95 selectorsEqual("", [], true); | |
96 removeFilter("##generic"); | |
97 | |
98 addFilter("~adblockplus.org##example"); | |
99 selectorsEqual("adblockplus.org", []); | |
100 selectorsEqual("", ["example"]); | |
101 selectorsEqual("foo.example.com", ["turnip", "bar", "example"]); | |
102 selectorsEqual("foo.example.com", ["turnip", "bar"], true); | |
103 removeFilter("~adblockplus.org##example"); | |
104 | |
105 removeFilter("~foo.example.com,example.com##foo"); | |
106 selectorsEqual("foo.example.com", ["turnip", "bar"]); | |
107 selectorsEqual("example.com", ["bar"]); | |
108 selectorsEqual("com", ["bar"]); | |
109 selectorsEqual("", []); | |
110 | |
111 removeFilter("com##bar"); | |
112 selectorsEqual("foo.example.com", ["turnip"]); | |
113 selectorsEqual("example.com", []); | |
114 selectorsEqual("com", []); | |
115 selectorsEqual("", []); | |
116 | |
117 removeFilter("foo.example.com##turnip"); | |
118 selectorsEqual("foo.example.com", []); | |
119 selectorsEqual("example.com", []); | |
120 selectorsEqual("com", []); | |
121 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 | |
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"); | |
127 addFilter("example.com##dupe"); | |
128 selectorsEqual("example.com", ["dupe"]); | |
129 removeFilter("example.com##dupe"); | |
130 selectorsEqual("example.com", []); | |
131 | |
132 test.done(); | |
133 }; | |
OLD | NEW |