Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/elemHide.js

Issue 29782589: Issue 6669 - Remove unused ElemHide.NO_UNCONDITIONAL constant (Closed)
Patch Set: Created May 15, 2018, 12:19 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 25 matching lines...) Expand all
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, 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, specificOnly)
47 { 47 {
48 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors); 48 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors);
49 49
50 test.deepEqual( 50 test.deepEqual(
51 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)), 51 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)),
52 normalizedExpectedSelectors 52 normalizedExpectedSelectors
53 ); 53 );
54 } 54 }
55 55
56 exports.testGetSelectorsForDomain = function(test) 56 exports.testGetSelectorsForDomain = function(test)
57 { 57 {
58 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); 58 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText));
59 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); 59 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText));
60 60
61 testResult(test, "", []); 61 testResult(test, "", []);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 testResult(test, "foo.example.com", ["turnip", "bar"]); 102 testResult(test, "foo.example.com", ["turnip", "bar"]);
103 testResult(test, "example.com", ["foo", "bar"]); 103 testResult(test, "example.com", ["foo", "bar"]);
104 testResult(test, "com", ["bar"]); 104 testResult(test, "com", ["bar"]);
105 testResult(test, "", []); 105 testResult(test, "", []);
106 106
107 addFilter("##generic"); 107 addFilter("##generic");
108 testResult(test, "foo.example.com", ["turnip", "bar", "generic"]); 108 testResult(test, "foo.example.com", ["turnip", "bar", "generic"]);
109 testResult(test, "example.com", ["foo", "bar", "generic"]); 109 testResult(test, "example.com", ["foo", "bar", "generic"]);
110 testResult(test, "com", ["bar", "generic"]); 110 testResult(test, "com", ["bar", "generic"]);
111 testResult(test, "", ["generic"]); 111 testResult(test, "", ["generic"]);
112 testResult(test, "foo.example.com", ["turnip", "bar"], ElemHide.SPECIFIC_ONLY) ; 112 testResult(test, "foo.example.com", ["turnip", "bar"], true);
113 testResult(test, "example.com", ["foo", "bar"], ElemHide.SPECIFIC_ONLY); 113 testResult(test, "example.com", ["foo", "bar"], true);
114 testResult(test, "com", ["bar"], ElemHide.SPECIFIC_ONLY); 114 testResult(test, "com", ["bar"], true);
115 testResult(test, "", [], ElemHide.SPECIFIC_ONLY); 115 testResult(test, "", [], true);
116 removeFilter("##generic"); 116 removeFilter("##generic");
117 117
118 addFilter("~adblockplus.org##example"); 118 addFilter("~adblockplus.org##example");
119 testResult(test, "adblockplus.org", []); 119 testResult(test, "adblockplus.org", []);
120 testResult(test, "", ["example"]); 120 testResult(test, "", ["example"]);
121 testResult(test, "foo.example.com", ["turnip", "bar", "example"]); 121 testResult(test, "foo.example.com", ["turnip", "bar", "example"]);
122 testResult(test, "foo.example.com", ["turnip", "bar"], ElemHide.SPECIFIC_ONLY) ; 122 testResult(test, "foo.example.com", ["turnip", "bar"], true);
123 removeFilter("~adblockplus.org##example"); 123 removeFilter("~adblockplus.org##example");
124 124
125 removeFilter("~foo.example.com,example.com##foo"); 125 removeFilter("~foo.example.com,example.com##foo");
126 testResult(test, "foo.example.com", ["turnip", "bar"]); 126 testResult(test, "foo.example.com", ["turnip", "bar"]);
127 testResult(test, "example.com", ["bar"]); 127 testResult(test, "example.com", ["bar"]);
128 testResult(test, "com", ["bar"]); 128 testResult(test, "com", ["bar"]);
129 testResult(test, "", []); 129 testResult(test, "", []);
130 130
131 removeFilter("com##bar"); 131 removeFilter("com##bar");
132 testResult(test, "foo.example.com", ["turnip"]); 132 testResult(test, "foo.example.com", ["turnip"]);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 testResult(test, "com", ["foo"]); 169 testResult(test, "com", ["foo"]);
170 testResult(test, "", ["foo"]); 170 testResult(test, "", ["foo"]);
171 removeFilter("~example.com##foo"); 171 removeFilter("~example.com##foo");
172 172
173 removeFilter("~foo.example.com,example.com##foo"); 173 removeFilter("~foo.example.com,example.com##foo");
174 174
175 // Test criteria 175 // Test criteria
176 addFilter("##hello"); 176 addFilter("##hello");
177 addFilter("~example.com##world"); 177 addFilter("~example.com##world");
178 addFilter("foo.com##specific"); 178 addFilter("foo.com##specific");
179 testResult(test, "foo.com", ["specific"], ElemHide.SPECIFIC_ONLY); 179 testResult(test, "foo.com", ["specific"], true);
180 testResult(test, "foo.com", ["specific", "world"], ElemHide.NO_UNCONDITIONAL); 180 testResult(test, "foo.com", ["hello", "specific", "world"], false);
181 testResult(test, "foo.com", ["hello", "specific", "world"], ElemHide.ALL_MATCH ING);
182 testResult(test, "foo.com", ["hello", "specific", "world"]); 181 testResult(test, "foo.com", ["hello", "specific", "world"]);
183 removeFilter("foo.com##specific"); 182 removeFilter("foo.com##specific");
184 removeFilter("~example.com##world"); 183 removeFilter("~example.com##world");
185 removeFilter("##hello"); 184 removeFilter("##hello");
186 testResult(test, "foo.com", []); 185 testResult(test, "foo.com", []);
187 186
188 addFilter("##hello"); 187 addFilter("##hello");
189 testResult(test, "foo.com", [], ElemHide.SPECIFIC_ONLY); 188 testResult(test, "foo.com", [], true);
190 testResult(test, "foo.com", [], ElemHide.NO_UNCONDITIONAL); 189 testResult(test, "foo.com", ["hello"], false);
191 testResult(test, "foo.com", ["hello"], ElemHide.ALL_MATCHING);
192 testResult(test, "foo.com", ["hello"]); 190 testResult(test, "foo.com", ["hello"]);
193 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); 191 testResult(test, "bar.com", [], true);
194 testResult(test, "bar.com", [], ElemHide.NO_UNCONDITIONAL); 192 testResult(test, "bar.com", ["hello"], false);
195 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING);
196 testResult(test, "bar.com", ["hello"]); 193 testResult(test, "bar.com", ["hello"]);
197 addFilter("foo.com#@#hello"); 194 addFilter("foo.com#@#hello");
198 testResult(test, "foo.com", [], ElemHide.SPECIFIC_ONLY); 195 testResult(test, "foo.com", [], true);
199 testResult(test, "foo.com", [], ElemHide.NO_UNCONDITIONAL); 196 testResult(test, "foo.com", [], false);
200 testResult(test, "foo.com", [], ElemHide.ALL_MATCHING);
201 testResult(test, "foo.com", []); 197 testResult(test, "foo.com", []);
202 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); 198 testResult(test, "bar.com", [], true);
203 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL); 199 testResult(test, "bar.com", ["hello"], false);
204 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING);
205 testResult(test, "bar.com", ["hello"]); 200 testResult(test, "bar.com", ["hello"]);
206 removeFilter("foo.com#@#hello"); 201 removeFilter("foo.com#@#hello");
207 testResult(test, "foo.com", [], ElemHide.SPECIFIC_ONLY); 202 testResult(test, "foo.com", [], true);
208 // Note: We don't take care to track conditional selectors which became 203 // Note: We don't take care to track conditional selectors which became
209 // unconditional when a filter was removed. This was too expensive. 204 // unconditional when a filter was removed. This was too expensive.
210 // testResult(test, "foo.com", [], ElemHide.NO_UNCONDITIONAL); 205 testResult(test, "foo.com", ["hello"], false);
211 testResult(test, "foo.com", ["hello"], ElemHide.ALL_MATCHING);
212 testResult(test, "foo.com", ["hello"]); 206 testResult(test, "foo.com", ["hello"]);
213 testResult(test, "bar.com", [], ElemHide.SPECIFIC_ONLY); 207 testResult(test, "bar.com", [], true);
214 testResult(test, "bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL); 208 testResult(test, "bar.com", ["hello"], false);
215 testResult(test, "bar.com", ["hello"], ElemHide.ALL_MATCHING);
216 testResult(test, "bar.com", ["hello"]); 209 testResult(test, "bar.com", ["hello"]);
217 removeFilter("##hello"); 210 removeFilter("##hello");
218 testResult(test, "foo.com", []); 211 testResult(test, "foo.com", []);
219 testResult(test, "bar.com", []); 212 testResult(test, "bar.com", []);
220 213
221 addFilter("##hello"); 214 addFilter("##hello");
222 addFilter("foo.com##hello"); 215 addFilter("foo.com##hello");
223 testResult(test, "foo.com", ["hello"]); 216 testResult(test, "foo.com", ["hello"]);
224 removeFilter("foo.com##hello"); 217 removeFilter("foo.com##hello");
225 testResult(test, "foo.com", ["hello"]); 218 testResult(test, "foo.com", ["hello"]);
(...skipping 12 matching lines...) Expand all
238 }; 231 };
239 232
240 exports.testZeroFilterKey = function(test) 233 exports.testZeroFilterKey = function(test)
241 { 234 {
242 ElemHide.add(Filter.fromText("##test")); 235 ElemHide.add(Filter.fromText("##test"));
243 ElemHide.add(Filter.fromText("foo.com#@#test")); 236 ElemHide.add(Filter.fromText("foo.com#@#test"));
244 testResult(test, "foo.com", []); 237 testResult(test, "foo.com", []);
245 testResult(test, "bar.com", ["test"]); 238 testResult(test, "bar.com", ["test"]);
246 test.done(); 239 test.done();
247 }; 240 };
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld