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

Delta Between Two Patch Sets: test/elemHide.js

Issue 29349187: Issue 4167 - getSelectorsForDomain criteria + keys (Closed)
Left Patch Set: Improved tests, fixed bugs spotted in the process Created Sept. 20, 2016, 2:17 p.m.
Right Patch Set: Improved comments Created Sept. 27, 2016, 1:52 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/elemHide.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 ); 52 );
53 53
54 // With filter keys 54 // With filter keys
55 let [selectors, filterKeys] = ElemHide.getSelectorsForDomain(domain, criteri a, 55 let [selectors, filterKeys] = ElemHide.getSelectorsForDomain(domain, criteri a,
56 true); 56 true);
57 test.deepEqual(filterKeys.map(k => ElemHide.getFilterByKey(k).selector), 57 test.deepEqual(filterKeys.map(k => ElemHide.getFilterByKey(k).selector),
58 selectors); 58 selectors);
59 test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors); 59 test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors);
60 } 60 }
61 61
62 let allSelectors = 0;
63 let noUnconditional = 1;
64 let specificOnly = 2;
65
66 testResult("", []); 62 testResult("", []);
67 63
68 addFilter("~foo.example.com,example.com##foo"); 64 addFilter("~foo.example.com,example.com##foo");
69 testResult("barfoo.example.com", ["foo"]); 65 testResult("barfoo.example.com", ["foo"]);
70 testResult("bar.foo.example.com", []); 66 testResult("bar.foo.example.com", []);
71 testResult("foo.example.com", []); 67 testResult("foo.example.com", []);
72 testResult("example.com", ["foo"]); 68 testResult("example.com", ["foo"]);
73 testResult("com", []); 69 testResult("com", []);
74 testResult("", []); 70 testResult("", []);
75 71
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 testResult("foo.example.com", ["turnip", "bar"]); 103 testResult("foo.example.com", ["turnip", "bar"]);
108 testResult("example.com", ["foo", "bar"]); 104 testResult("example.com", ["foo", "bar"]);
109 testResult("com", ["bar"]); 105 testResult("com", ["bar"]);
110 testResult("", []); 106 testResult("", []);
111 107
112 addFilter("##generic"); 108 addFilter("##generic");
113 testResult("foo.example.com", ["turnip", "bar", "generic"]); 109 testResult("foo.example.com", ["turnip", "bar", "generic"]);
114 testResult("example.com", ["foo", "bar", "generic"]); 110 testResult("example.com", ["foo", "bar", "generic"]);
115 testResult("com", ["bar", "generic"]); 111 testResult("com", ["bar", "generic"]);
116 testResult("", ["generic"]); 112 testResult("", ["generic"]);
117 testResult("foo.example.com", ["turnip", "bar"], specificOnly); 113 testResult("foo.example.com", ["turnip", "bar"], ElemHide.SPECIFIC_ONLY);
118 testResult("example.com", ["foo", "bar"], specificOnly); 114 testResult("example.com", ["foo", "bar"], ElemHide.SPECIFIC_ONLY);
119 testResult("com", ["bar"], specificOnly); 115 testResult("com", ["bar"], ElemHide.SPECIFIC_ONLY);
120 testResult("", [], specificOnly); 116 testResult("", [], ElemHide.SPECIFIC_ONLY);
121 removeFilter("##generic"); 117 removeFilter("##generic");
122 118
123 addFilter("~adblockplus.org##example"); 119 addFilter("~adblockplus.org##example");
124 testResult("adblockplus.org", []); 120 testResult("adblockplus.org", []);
125 testResult("", ["example"]); 121 testResult("", ["example"]);
126 testResult("foo.example.com", ["turnip", "bar", "example"]); 122 testResult("foo.example.com", ["turnip", "bar", "example"]);
127 testResult("foo.example.com", ["turnip", "bar"], specificOnly); 123 testResult("foo.example.com", ["turnip", "bar"], ElemHide.SPECIFIC_ONLY);
128 removeFilter("~adblockplus.org##example"); 124 removeFilter("~adblockplus.org##example");
129 125
130 removeFilter("~foo.example.com,example.com##foo"); 126 removeFilter("~foo.example.com,example.com##foo");
131 testResult("foo.example.com", ["turnip", "bar"]); 127 testResult("foo.example.com", ["turnip", "bar"]);
132 testResult("example.com", ["bar"]); 128 testResult("example.com", ["bar"]);
133 testResult("com", ["bar"]); 129 testResult("com", ["bar"]);
134 testResult("", []); 130 testResult("", []);
135 131
136 removeFilter("com##bar"); 132 removeFilter("com##bar");
137 testResult("foo.example.com", ["turnip"]); 133 testResult("foo.example.com", ["turnip"]);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 testResult("com", ["foo"]); 170 testResult("com", ["foo"]);
175 testResult("", ["foo"]); 171 testResult("", ["foo"]);
176 removeFilter("~example.com##foo"); 172 removeFilter("~example.com##foo");
177 173
178 removeFilter("~foo.example.com,example.com##foo"); 174 removeFilter("~foo.example.com,example.com##foo");
179 175
180 // Test criteria 176 // Test criteria
181 addFilter("##hello"); 177 addFilter("##hello");
182 addFilter("~example.com##world"); 178 addFilter("~example.com##world");
183 addFilter("foo.com##specific"); 179 addFilter("foo.com##specific");
184 testResult("foo.com", ["specific"], specificOnly); 180 testResult("foo.com", ["specific"], ElemHide.SPECIFIC_ONLY);
185 testResult("foo.com", ["specific", "world"], noUnconditional); 181 testResult("foo.com", ["specific", "world"], ElemHide.NO_UNCONDITIONAL);
186 testResult("foo.com", ["hello", "specific", "world"], allSelectors); 182 testResult("foo.com", ["hello", "specific", "world"], ElemHide.ALL_MATCHING);
187 testResult("foo.com", ["hello", "specific", "world"]); 183 testResult("foo.com", ["hello", "specific", "world"]);
188 removeFilter("foo.com##specific"); 184 removeFilter("foo.com##specific");
189 removeFilter("~example.com##world"); 185 removeFilter("~example.com##world");
190 removeFilter("##hello"); 186 removeFilter("##hello");
191 187 testResult("foo.com", []);
192 // Advanced criteria test 188
189 addFilter("##hello");
190 testResult("foo.com", [], ElemHide.SPECIFIC_ONLY);
191 testResult("foo.com", [], ElemHide.NO_UNCONDITIONAL);
192 testResult("foo.com", ["hello"], ElemHide.ALL_MATCHING);
193 testResult("foo.com", ["hello"]);
194 testResult("bar.com", [], ElemHide.SPECIFIC_ONLY);
195 testResult("bar.com", [], ElemHide.NO_UNCONDITIONAL);
196 testResult("bar.com", ["hello"], ElemHide.ALL_MATCHING);
197 testResult("bar.com", ["hello"]);
198 addFilter("foo.com#@#hello");
199 testResult("foo.com", [], ElemHide.SPECIFIC_ONLY);
200 testResult("foo.com", [], ElemHide.NO_UNCONDITIONAL);
201 testResult("foo.com", [], ElemHide.ALL_MATCHING);
202 testResult("foo.com", []);
203 testResult("bar.com", [], ElemHide.SPECIFIC_ONLY);
204 testResult("bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL);
205 testResult("bar.com", ["hello"], ElemHide.ALL_MATCHING);
206 testResult("bar.com", ["hello"]);
207 removeFilter("foo.com#@#hello");
208 testResult("foo.com", [], ElemHide.SPECIFIC_ONLY);
209 // Note: We don't take care to track conditional selectors which became
210 // unconditional when a filter was removed. This was too expensive.
211 //testResult("foo.com", [], ElemHide.NO_UNCONDITIONAL);
212 testResult("foo.com", ["hello"], ElemHide.ALL_MATCHING);
213 testResult("foo.com", ["hello"]);
214 testResult("bar.com", [], ElemHide.SPECIFIC_ONLY);
215 testResult("bar.com", ["hello"], ElemHide.NO_UNCONDITIONAL);
216 testResult("bar.com", ["hello"], ElemHide.ALL_MATCHING);
217 testResult("bar.com", ["hello"]);
218 removeFilter("##hello");
219 testResult("foo.com", []);
220 testResult("bar.com", []);
221
193 addFilter("##hello"); 222 addFilter("##hello");
194 addFilter("foo.com##hello"); 223 addFilter("foo.com##hello");
195 testResult("foo.com", ["hello"]); 224 testResult("foo.com", ["hello"]);
196 removeFilter("foo.com##hello"); 225 removeFilter("foo.com##hello");
197 testResult("foo.com", ["hello"]); 226 testResult("foo.com", ["hello"]);
198 removeFilter("##hello"); 227 removeFilter("##hello");
228 testResult("foo.com", []);
229
230 addFilter("##hello");
231 addFilter("foo.com##hello");
232 testResult("foo.com", ["hello"]);
233 removeFilter("##hello");
234 testResult("foo.com", ["hello"]);
235 removeFilter("foo.com##hello");
236 testResult("foo.com", []);
199 237
200 // Advanced filter keys test 238 // Advanced filter keys test
201 testResult("", []); 239 testResult("", []);
202 addFilter("##dupe"); 240 addFilter("##dupe");
203 addFilter(",,##dupe"); 241 addFilter(",,##dupe");
204 addFilter(",,,##dupe"); 242 addFilter(",,,##dupe");
243 addFilter("foo.com##dupe");
205 testResult("", ["dupe"]); 244 testResult("", ["dupe"]);
206 removeFilter(",,,##dupe"); 245 removeFilter(",,,##dupe");
246 testResult("", ["dupe"]);
247 removeFilter("foo.com##dupe");
207 testResult("", ["dupe"]); 248 testResult("", ["dupe"]);
208 removeFilter(",,##dupe"); 249 removeFilter(",,##dupe");
209 testResult("", ["dupe"]); 250 testResult("", ["dupe"]);
210 removeFilter("##dupe"); 251 removeFilter("##dupe");
211 testResult("", []); 252 testResult("", []);
212 253
213 test.done(); 254 test.done();
214 }; 255 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld