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-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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 }; | 45 }; |
46 | 46 |
47 function timeout(delay) | 47 function timeout(delay) |
48 { | 48 { |
49 return new Promise((resolve, reject) => | 49 return new Promise((resolve, reject) => |
50 { | 50 { |
51 window.setTimeout(resolve, delay); | 51 window.setTimeout(resolve, delay); |
52 }); | 52 }); |
53 } | 53 } |
54 | 54 |
55 function unexpectedError(error) | 55 function unexpectedError(test, error) |
56 { | 56 { |
57 console.error(error); | 57 console.error(error); |
58 this.ok(false, "Unexpected error: " + error); | 58 test.ok(false, "Unexpected error: " + error); |
59 } | 59 } |
60 | 60 |
61 function expectHidden(test, element, id) | 61 function expectHidden(test, element, id) |
62 { | 62 { |
63 let withId = ""; | 63 let withId = ""; |
64 if (typeof id != "undefined") | 64 if (typeof id != "undefined") |
65 withId = ` with ID '${id}'`; | 65 withId = ` with ID '${id}'`; |
66 | 66 |
67 test.equal( | 67 test.equal( |
68 window.getComputedStyle(element).display, "none", | 68 window.getComputedStyle(element).display, "none", |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Insert a <div> with a unique id and a CSS rule | 141 // Insert a <div> with a unique id and a CSS rule |
142 // for the the selector matching the id. | 142 // for the the selector matching the id. |
143 function createElementWithStyle(styleBlock, parent) | 143 function createElementWithStyle(styleBlock, parent) |
144 { | 144 { |
145 let element = createElement(parent); | 145 let element = createElement(parent); |
146 insertStyleRule("#" + element.id + " " + styleBlock); | 146 insertStyleRule("#" + element.id + " " + styleBlock); |
147 return element; | 147 return element; |
148 } | 148 } |
149 | 149 |
150 // Create a new ElemHideEmulation instance with @selectors. | 150 // Create a new ElemHideEmulation instance with @selectors. |
151 function applyElemHideEmulation(selectors) | 151 async function applyElemHideEmulation(test, selectors) |
152 { | 152 { |
153 return Promise.resolve().then(() => | 153 await Promise.resolve(); |
| 154 |
| 155 try |
154 { | 156 { |
155 let elemHideEmulation = new ElemHideEmulation( | 157 let elemHideEmulation = new ElemHideEmulation( |
156 elems => | 158 elems => |
157 { | 159 { |
158 for (let elem of elems) | 160 for (let elem of elems) |
159 elem.style.display = "none"; | 161 elem.style.display = "none"; |
160 } | 162 } |
161 ); | 163 ); |
162 | 164 |
163 elemHideEmulation.document = testDocument; | 165 elemHideEmulation.document = testDocument; |
164 elemHideEmulation.MIN_INVOCATION_INTERVAL = REFRESH_INTERVAL / 2; | 166 elemHideEmulation.MIN_INVOCATION_INTERVAL = REFRESH_INTERVAL / 2; |
165 elemHideEmulation.apply(selectors.map( | 167 elemHideEmulation.apply(selectors.map( |
166 selector => ({selector, text: selector}) | 168 selector => ({selector, text: selector}) |
167 )); | 169 )); |
| 170 |
168 return elemHideEmulation; | 171 return elemHideEmulation; |
169 }); | 172 } |
| 173 catch (error) |
| 174 { |
| 175 unexpectedError(test, error); |
| 176 } |
170 } | 177 } |
171 | 178 |
172 exports.testVerbatimPropertySelector = function(test) | 179 exports.testVerbatimPropertySelector = async function(test) |
173 { | 180 { |
174 let toHide = createElementWithStyle("{background-color: #000}"); | 181 let toHide = createElementWithStyle("{background-color: #000}"); |
175 applyElemHideEmulation( | 182 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"]; |
176 [":-abp-properties(background-color: rgb(0, 0, 0))"] | 183 |
177 ).then(() => | 184 if (await applyElemHideEmulation(test, selectors)) |
178 { | 185 expectHidden(test, toHide); |
179 expectHidden(test, toHide); | 186 |
180 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 187 test.done(); |
181 }; | 188 }; |
182 | 189 |
183 exports.testVerbatimPropertySelectorWithPrefix = function(test) | 190 exports.testVerbatimPropertySelectorWithPrefix = async function(test) |
184 { | 191 { |
185 let parent = createElementWithStyle("{background-color: #000}"); | 192 let parent = createElementWithStyle("{background-color: #000}"); |
186 let toHide = createElementWithStyle("{background-color: #000}", parent); | 193 let toHide = createElementWithStyle("{background-color: #000}", parent); |
187 applyElemHideEmulation( | 194 |
188 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] | 195 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]; |
189 ).then(() => | 196 |
190 { | 197 if (await applyElemHideEmulation(test, selectors)) |
191 expectVisible(test, parent); | 198 { |
192 expectHidden(test, toHide); | 199 expectVisible(test, parent); |
193 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 200 expectHidden(test, toHide); |
194 }; | 201 } |
195 | 202 |
196 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) | 203 test.done(); |
| 204 }; |
| 205 |
| 206 exports.testVerbatimPropertySelectorWithPrefixNoMatch = async function(test) |
197 { | 207 { |
198 let parent = createElementWithStyle("{background-color: #000}"); | 208 let parent = createElementWithStyle("{background-color: #000}"); |
199 let toHide = createElementWithStyle("{background-color: #fff}", parent); | 209 let toHide = createElementWithStyle("{background-color: #fff}", parent); |
200 applyElemHideEmulation( | 210 |
201 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] | 211 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]; |
202 ).then(() => | 212 |
203 { | 213 if (await applyElemHideEmulation(test, selectors)) |
204 expectVisible(test, parent); | 214 { |
205 expectVisible(test, toHide); | 215 expectVisible(test, parent); |
206 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 216 expectVisible(test, toHide); |
207 }; | 217 } |
208 | 218 |
209 exports.testVerbatimPropertySelectorWithSuffix = function(test) | 219 test.done(); |
| 220 }; |
| 221 |
| 222 exports.testVerbatimPropertySelectorWithSuffix = async function(test) |
210 { | 223 { |
211 let parent = createElementWithStyle("{background-color: #000}"); | 224 let parent = createElementWithStyle("{background-color: #000}"); |
212 let toHide = createElementWithStyle("{background-color: #000}", parent); | 225 let toHide = createElementWithStyle("{background-color: #000}", parent); |
213 applyElemHideEmulation( | 226 |
214 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] | 227 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0)) > div"]; |
215 ).then(() => | 228 |
216 { | 229 if (await applyElemHideEmulation(test, selectors)) |
217 expectVisible(test, parent); | 230 { |
218 expectHidden(test, toHide); | 231 expectVisible(test, parent); |
219 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 232 expectHidden(test, toHide); |
220 }; | 233 } |
221 | 234 |
222 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) | 235 test.done(); |
| 236 }; |
| 237 |
| 238 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = async function(t
est) |
223 { | 239 { |
224 let parent = createElementWithStyle("{background-color: #000}"); | 240 let parent = createElementWithStyle("{background-color: #000}"); |
225 let middle = createElementWithStyle("{background-color: #000}", parent); | 241 let middle = createElementWithStyle("{background-color: #000}", parent); |
226 let toHide = createElementWithStyle("{background-color: #000}", middle); | 242 let toHide = createElementWithStyle("{background-color: #000}", middle); |
227 applyElemHideEmulation( | 243 |
228 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] | 244 let selectors = ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div
"]; |
229 ).then(() => | 245 |
| 246 if (await applyElemHideEmulation(test, selectors)) |
230 { | 247 { |
231 expectVisible(test, parent); | 248 expectVisible(test, parent); |
232 expectVisible(test, middle); | 249 expectVisible(test, middle); |
233 expectHidden(test, toHide); | 250 expectHidden(test, toHide); |
234 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 251 } |
| 252 |
| 253 test.done(); |
235 }; | 254 }; |
236 | 255 |
237 // Add the style. Then add the element for that style. | 256 // Add the style. Then add the element for that style. |
238 // This should retrigger the filtering and hide it. | 257 // This should retrigger the filtering and hide it. |
239 exports.testPropertyPseudoSelectorAddStyleAndElement = function(test) | 258 exports.testPropertyPseudoSelectorAddStyleAndElement = async function(test) |
240 { | 259 { |
241 let styleElement; | 260 let styleElement; |
242 let toHide; | 261 let toHide; |
243 applyElemHideEmulation( | 262 |
244 [":-abp-properties(background-color: rgb(0, 0, 0))"] | 263 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"]; |
245 ).then(() => | 264 |
| 265 if (await applyElemHideEmulation(test, selectors)) |
246 { | 266 { |
247 styleElement = testDocument.createElement("style"); | 267 styleElement = testDocument.createElement("style"); |
248 testDocument.head.appendChild(styleElement); | 268 testDocument.head.appendChild(styleElement); |
249 styleElement.sheet.insertRule("#toHide {background-color: #000}"); | 269 styleElement.sheet.insertRule("#toHide {background-color: #000}"); |
250 return timeout(REFRESH_INTERVAL); | 270 await timeout(REFRESH_INTERVAL); |
251 }).then(() => | 271 |
252 { | |
253 toHide = createElement(); | 272 toHide = createElement(); |
254 toHide.id = "toHide"; | 273 toHide.id = "toHide"; |
255 expectVisible(test, toHide); | 274 expectVisible(test, toHide); |
256 return timeout(REFRESH_INTERVAL); | 275 await timeout(REFRESH_INTERVAL); |
257 }).then(() => | 276 |
258 { | 277 expectHidden(test, toHide); |
259 expectHidden(test, toHide); | 278 } |
260 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 279 |
261 }; | 280 test.done(); |
262 | 281 }; |
263 exports.testPropertySelectorWithWildcard = function(test) | 282 |
264 { | 283 exports.testPropertySelectorWithWildcard = async function(test) |
265 let toHide = createElementWithStyle("{background-color: #000}"); | 284 { |
266 applyElemHideEmulation( | 285 let toHide = createElementWithStyle("{background-color: #000}"); |
267 [":-abp-properties(*color: rgb(0, 0, 0))"] | 286 let selectors = [":-abp-properties(*color: rgb(0, 0, 0))"]; |
268 ).then(() => | 287 |
269 { | 288 if (await applyElemHideEmulation(test, selectors)) |
270 expectHidden(test, toHide); | 289 expectHidden(test, toHide); |
271 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 290 |
272 }; | 291 test.done(); |
273 | 292 }; |
274 exports.testPropertySelectorWithRegularExpression = function(test) | 293 |
275 { | 294 exports.testPropertySelectorWithRegularExpression = async function(test) |
276 let toHide = createElementWithStyle("{background-color: #000}"); | 295 { |
277 applyElemHideEmulation( | 296 let toHide = createElementWithStyle("{background-color: #000}"); |
278 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] | 297 let selectors = [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"]; |
279 ).then(() => | 298 |
280 { | 299 if (await applyElemHideEmulation(test, selectors)) |
281 expectHidden(test, toHide); | 300 expectHidden(test, toHide); |
282 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 301 |
283 }; | 302 test.done(); |
284 | 303 }; |
285 exports.testPropertySelectorWithEscapedBrace = function(test) | 304 |
286 { | 305 exports.testPropertySelectorWithEscapedBrace = async function(test) |
287 let toHide = createElementWithStyle("{background-color: #000}"); | 306 { |
288 applyElemHideEmulation( | 307 let toHide = createElementWithStyle("{background-color: #000}"); |
289 [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\)/)"] | 308 let selectors = [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\)
/)"]; |
290 ).then(() => | 309 |
291 { | 310 if (await applyElemHideEmulation(test, selectors)) |
292 expectHidden(test, toHide); | 311 expectHidden(test, toHide); |
293 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 312 |
294 }; | 313 test.done(); |
295 | 314 }; |
296 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) | 315 |
297 { | 316 exports.testPropertySelectorWithImproperlyEscapedBrace = async function(test) |
298 let toHide = createElementWithStyle("{background-color: #000}"); | 317 { |
299 applyElemHideEmulation( | 318 let toHide = createElementWithStyle("{background-color: #000}"); |
300 [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/)"] | 319 let selectors = [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/)
"]; |
301 ).then(() => | 320 |
302 { | 321 if (await applyElemHideEmulation(test, selectors)) |
303 expectVisible(test, toHide); | 322 expectVisible(test, toHide); |
304 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 323 |
305 }; | 324 test.done(); |
306 | 325 }; |
307 exports.testDynamicallyChangedProperty = function(test) | 326 |
| 327 exports.testDynamicallyChangedProperty = async function(test) |
308 { | 328 { |
309 let toHide = createElementWithStyle("{}"); | 329 let toHide = createElementWithStyle("{}"); |
310 applyElemHideEmulation( | 330 let selectors = [":-abp-properties(background-color: rgb(0, 0, 0))"]; |
311 [":-abp-properties(background-color: rgb(0, 0, 0))"] | 331 |
312 ).then(() => | 332 if (await applyElemHideEmulation(test, selectors)) |
313 { | 333 { |
314 expectVisible(test, toHide); | 334 expectVisible(test, toHide); |
315 insertStyleRule("#" + toHide.id + " {background-color: #000}"); | 335 insertStyleRule("#" + toHide.id + " {background-color: #000}"); |
316 | 336 |
317 return timeout(0); | 337 await timeout(0); |
318 }).then(() => | 338 |
319 { | |
320 // Re-evaluation will only happen after a delay | 339 // Re-evaluation will only happen after a delay |
321 expectVisible(test, toHide); | 340 expectVisible(test, toHide); |
322 return timeout(REFRESH_INTERVAL); | 341 await timeout(REFRESH_INTERVAL); |
323 }).then(() => | 342 |
324 { | 343 expectHidden(test, toHide); |
325 expectHidden(test, toHide); | 344 } |
326 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 345 |
327 }; | 346 test.done(); |
328 | 347 }; |
329 exports.testPseudoClassWithPropBeforeSelector = function(test) | 348 |
| 349 exports.testPseudoClassWithPropBeforeSelector = async function(test) |
330 { | 350 { |
331 let parent = createElementWithStyle("{}"); | 351 let parent = createElementWithStyle("{}"); |
332 let child = createElementWithStyle("{background-color: #000}", parent); | 352 let child = createElementWithStyle("{background-color: #000}", parent); |
| 353 |
| 354 let selectors = ["div:-abp-properties(content: \"publicite\")"]; |
| 355 |
333 insertStyleRule(`#${child.id}::before {content: "publicite"}`); | 356 insertStyleRule(`#${child.id}::before {content: "publicite"}`); |
334 | 357 |
335 applyElemHideEmulation( | 358 if (await applyElemHideEmulation(test, selectors)) |
336 ["div:-abp-properties(content: \"publicite\")"] | |
337 ).then(() => | |
338 { | 359 { |
339 expectHidden(test, child); | 360 expectHidden(test, child); |
340 expectVisible(test, parent); | 361 expectVisible(test, parent); |
341 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 362 } |
342 }; | 363 |
343 | 364 test.done(); |
344 exports.testPseudoClassHasSelector = function(test) | 365 }; |
| 366 |
| 367 exports.testPseudoClassHasSelector = async function(test) |
345 { | 368 { |
346 let toHide = createElementWithStyle("{}"); | 369 let toHide = createElementWithStyle("{}"); |
347 applyElemHideEmulation( | 370 |
348 ["div:-abp-has(div)"] | 371 if (await applyElemHideEmulation(test, ["div:-abp-has(div)"])) |
349 ).then(() => | 372 expectVisible(test, toHide); |
350 { | 373 |
351 expectVisible(test, toHide); | 374 test.done(); |
352 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 375 }; |
353 }; | 376 |
354 | 377 exports.testPseudoClassHasSelectorWithPrefix = async function(test) |
355 exports.testPseudoClassHasSelectorWithPrefix = function(test) | |
356 { | 378 { |
357 let parent = createElementWithStyle("{}"); | 379 let parent = createElementWithStyle("{}"); |
358 let child = createElementWithStyle("{}", parent); | 380 let child = createElementWithStyle("{}", parent); |
359 applyElemHideEmulation( | 381 |
360 ["div:-abp-has(div)"] | 382 if (await applyElemHideEmulation(test, ["div:-abp-has(div)"])) |
361 ).then(() => | |
362 { | 383 { |
363 expectHidden(test, parent); | 384 expectHidden(test, parent); |
364 expectVisible(test, child); | 385 expectVisible(test, child); |
365 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 386 } |
366 }; | 387 |
367 | 388 test.done(); |
368 exports.testPseudoClassHasSelectorWithSuffix = function(test) | 389 }; |
| 390 |
| 391 exports.testPseudoClassHasSelectorWithSuffix = async function(test) |
369 { | 392 { |
370 let parent = createElementWithStyle("{}"); | 393 let parent = createElementWithStyle("{}"); |
371 let middle = createElementWithStyle("{}", parent); | 394 let middle = createElementWithStyle("{}", parent); |
372 let child = createElementWithStyle("{}", middle); | 395 let child = createElementWithStyle("{}", middle); |
373 applyElemHideEmulation( | 396 |
374 ["div:-abp-has(div) > div"] | 397 if (await applyElemHideEmulation(test, ["div:-abp-has(div) > div"])) |
375 ).then(() => | |
376 { | 398 { |
377 expectVisible(test, parent); | 399 expectVisible(test, parent); |
378 expectHidden(test, middle); | 400 expectHidden(test, middle); |
379 expectHidden(test, child); | 401 expectHidden(test, child); |
380 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 402 } |
381 }; | 403 |
382 | 404 test.done(); |
383 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) | 405 }; |
| 406 |
| 407 exports.testPseudoClassHasSelectorWithSuffixSibling = async function(test) |
384 { | 408 { |
385 let parent = createElementWithStyle("{}"); | 409 let parent = createElementWithStyle("{}"); |
386 let middle = createElementWithStyle("{}", parent); | 410 let middle = createElementWithStyle("{}", parent); |
387 let toHide = createElementWithStyle("{}"); | 411 let toHide = createElementWithStyle("{}"); |
388 applyElemHideEmulation( | 412 |
389 ["div:-abp-has(div) + div"] | 413 if (await applyElemHideEmulation(test, ["div:-abp-has(div) + div"])) |
390 ).then(() => | |
391 { | 414 { |
392 expectVisible(test, parent); | 415 expectVisible(test, parent); |
393 expectVisible(test, middle); | 416 expectVisible(test, middle); |
394 expectHidden(test, toHide); | 417 expectHidden(test, toHide); |
395 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 418 } |
396 }; | 419 |
397 | 420 test.done(); |
398 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) | 421 }; |
| 422 |
| 423 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = async function(test) |
399 { | 424 { |
400 // <div> | 425 // <div> |
401 // <div></div> | 426 // <div></div> |
402 // <div> | 427 // <div> |
403 // <div>to hide</div> | 428 // <div>to hide</div> |
404 // </div> | 429 // </div> |
405 // </div> | 430 // </div> |
406 let parent = createElementWithStyle("{}"); | 431 let parent = createElementWithStyle("{}"); |
407 let middle = createElementWithStyle("{}", parent); | 432 let middle = createElementWithStyle("{}", parent); |
408 let sibling = createElementWithStyle("{}"); | 433 let sibling = createElementWithStyle("{}"); |
409 let toHide = createElementWithStyle("{}", sibling); | 434 let toHide = createElementWithStyle("{}", sibling); |
410 applyElemHideEmulation( | 435 |
411 ["div:-abp-has(div) + div > div"] | 436 if (await applyElemHideEmulation(test, ["div:-abp-has(div) + div > div"])) |
412 ).then(() => | |
413 { | 437 { |
414 expectVisible(test, parent); | 438 expectVisible(test, parent); |
415 expectVisible(test, middle); | 439 expectVisible(test, middle); |
416 expectVisible(test, sibling); | 440 expectVisible(test, sibling); |
417 expectHidden(test, toHide); | 441 expectHidden(test, toHide); |
418 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 442 } |
| 443 |
| 444 test.done(); |
419 }; | 445 }; |
420 | 446 |
421 function compareExpectations(test, elems, expectations) | 447 function compareExpectations(test, elems, expectations) |
422 { | 448 { |
423 for (let elem in expectations) | 449 for (let elem in expectations) |
424 { | 450 { |
425 if (elems[elem]) | 451 if (elems[elem]) |
426 { | 452 { |
427 if (expectations[elem]) | 453 if (expectations[elem]) |
428 expectVisible(test, elems[elem], elem); | 454 expectVisible(test, elems[elem], elem); |
429 else | 455 else |
430 expectHidden(test, elems[elem], elem); | 456 expectHidden(test, elems[elem], elem); |
431 } | 457 } |
432 } | 458 } |
433 } | 459 } |
434 | 460 |
435 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
, expectations) | 461 async function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, se
lector, expectations) |
436 { | 462 { |
437 testDocument.body.innerHTML = `<div id="parent"> | 463 testDocument.body.innerHTML = `<div id="parent"> |
438 <div id="middle"> | 464 <div id="middle"> |
439 <div id="middle1"><div id="inside" class="inside"></div></div> | 465 <div id="middle1"><div id="inside" class="inside"></div></div> |
440 </div> | 466 </div> |
441 <div id="sibling"> | 467 <div id="sibling"> |
442 <div id="tohide"><span>to hide</span></div> | 468 <div id="tohide"><span>to hide</span></div> |
443 </div> | 469 </div> |
444 <div id="sibling2"> | 470 <div id="sibling2"> |
445 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 471 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
446 </div> | 472 </div> |
447 </div>`; | 473 </div>`; |
448 let elems = { | 474 let elems = { |
449 parent: testDocument.getElementById("parent"), | 475 parent: testDocument.getElementById("parent"), |
450 middle: testDocument.getElementById("middle"), | 476 middle: testDocument.getElementById("middle"), |
451 inside: testDocument.getElementById("inside"), | 477 inside: testDocument.getElementById("inside"), |
452 sibling: testDocument.getElementById("sibling"), | 478 sibling: testDocument.getElementById("sibling"), |
453 sibling2: testDocument.getElementById("sibling2"), | 479 sibling2: testDocument.getElementById("sibling2"), |
454 toHide: testDocument.getElementById("tohide") | 480 toHide: testDocument.getElementById("tohide") |
455 }; | 481 }; |
456 | 482 |
457 insertStyleRule(".inside {}"); | 483 insertStyleRule(".inside {}"); |
458 | 484 |
459 applyElemHideEmulation( | 485 if (await applyElemHideEmulation(test, [selector])) |
460 [selector] | |
461 ).then(() => | |
462 { | |
463 compareExpectations(test, elems, expectations); | 486 compareExpectations(test, elems, expectations); |
464 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 487 |
| 488 test.done(); |
465 } | 489 } |
466 | 490 |
467 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) | 491 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = async function(t
est) |
468 { | 492 { |
469 let expectations = { | 493 let expectations = { |
470 parent: true, | 494 parent: true, |
471 middile: true, | 495 middile: true, |
472 inside: true, | 496 inside: true, |
473 sibling: true, | 497 sibling: true, |
474 sibling2: true, | 498 sibling2: true, |
475 toHide: false | 499 toHide: false |
476 }; | 500 }; |
477 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 501 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
478 test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations); | 502 test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations); |
479 }; | 503 }; |
480 | 504 |
481 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) | 505 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = async function(
test) |
482 { | 506 { |
483 let expectations = { | 507 let expectations = { |
484 parent: true, | 508 parent: true, |
485 middile: true, | 509 middile: true, |
486 inside: true, | 510 inside: true, |
487 sibling: true, | 511 sibling: true, |
488 sibling2: true, | 512 sibling2: true, |
489 toHide: false | 513 toHide: false |
490 }; | 514 }; |
491 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 515 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
492 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); | 516 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); |
493 }; | 517 }; |
494 | 518 |
495 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = function(test) | 519 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = async function(
test) |
496 { | 520 { |
497 let expectations = { | 521 let expectations = { |
498 parent: true, | 522 parent: true, |
499 middile: true, | 523 middile: true, |
500 inside: true, | 524 inside: true, |
501 sibling: true, | 525 sibling: true, |
502 sibling2: true, | 526 sibling2: true, |
503 toHide: false | 527 toHide: false |
504 }; | 528 }; |
505 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 529 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
506 test, "div:-abp-has(> div:-abp-has(div.inside)) + div > div", expectations); | 530 test, "div:-abp-has(> div:-abp-has(div.inside)) + div > div", expectations); |
507 }; | 531 }; |
508 | 532 |
509 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test) | 533 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = async function(test) |
510 { | 534 { |
511 let expectations = { | 535 let expectations = { |
512 parent: true, | 536 parent: true, |
513 middile: true, | 537 middile: true, |
514 inside: true, | 538 inside: true, |
515 sibling: true, | 539 sibling: true, |
516 sibling2: true, | 540 sibling2: true, |
517 toHide: true | 541 toHide: true |
518 }; | 542 }; |
519 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 543 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
520 test, "div:-abp-has(> body div.inside) + div > div", expectations); | 544 test, "div:-abp-has(> body div.inside) + div > div", expectations); |
521 }; | 545 }; |
522 | 546 |
523 exports.testPseudoClassHasSelectorWithSuffixSiblingContains = function(test) | 547 exports.testPseudoClassHasSelectorWithSuffixSiblingContains = async function(tes
t) |
524 { | 548 { |
525 let expectations = { | 549 let expectations = { |
526 parent: true, | 550 parent: true, |
527 middile: true, | 551 middile: true, |
528 inside: true, | 552 inside: true, |
529 sibling: true, | 553 sibling: true, |
530 sibling2: true, | 554 sibling2: true, |
531 toHide: true | 555 toHide: true |
532 }; | 556 }; |
533 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 557 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
534 test, "div:-abp-has(> span:-abp-contains(Advertisment))", expectations); | 558 test, "div:-abp-has(> span:-abp-contains(Advertisment))", expectations); |
535 }; | 559 }; |
536 | 560 |
537 function runTestPseudoClassContains(test, selector, expectations) | 561 async function runTestPseudoClassContains(test, selector, expectations) |
538 { | 562 { |
539 testDocument.body.innerHTML = `<div id="parent"> | 563 testDocument.body.innerHTML = `<div id="parent"> |
540 <div id="middle"> | 564 <div id="middle"> |
541 <div id="middle1"><div id="inside" class="inside"></div></div> | 565 <div id="middle1"><div id="inside" class="inside"></div></div> |
542 </div> | 566 </div> |
543 <div id="sibling"> | 567 <div id="sibling"> |
544 <div id="tohide">to hide \ud83d\ude42!</div> | 568 <div id="tohide">to hide \ud83d\ude42!</div> |
545 </div> | 569 </div> |
546 <div id="sibling2"> | 570 <div id="sibling2"> |
547 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div> | 571 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div> |
548 </div> | 572 </div> |
549 </div>`; | 573 </div>`; |
550 let elems = { | 574 let elems = { |
551 parent: testDocument.getElementById("parent"), | 575 parent: testDocument.getElementById("parent"), |
552 middle: testDocument.getElementById("middle"), | 576 middle: testDocument.getElementById("middle"), |
553 inside: testDocument.getElementById("inside"), | 577 inside: testDocument.getElementById("inside"), |
554 sibling: testDocument.getElementById("sibling"), | 578 sibling: testDocument.getElementById("sibling"), |
555 sibling2: testDocument.getElementById("sibling2"), | 579 sibling2: testDocument.getElementById("sibling2"), |
556 toHide: testDocument.getElementById("tohide") | 580 toHide: testDocument.getElementById("tohide") |
557 }; | 581 }; |
558 | 582 |
559 applyElemHideEmulation( | 583 if (await applyElemHideEmulation(test, [selector])) |
560 [selector] | 584 compareExpectations(test, elems, expectations); |
561 ).then( | 585 |
562 () => compareExpectations(test, elems, expectations) | 586 test.done(); |
563 ).catch(unexpectedError.bind(test)).then(() => test.done()); | |
564 } | 587 } |
565 | 588 |
566 exports.testPseudoClassContainsText = function(test) | 589 exports.testPseudoClassContainsText = async function(test) |
567 { | 590 { |
568 let expectations = { | 591 let expectations = { |
569 parent: true, | 592 parent: true, |
570 middle: true, | 593 middle: true, |
571 inside: true, | 594 inside: true, |
572 sibling: false, | 595 sibling: false, |
573 sibling2: true, | 596 sibling2: true, |
574 toHide: true | 597 toHide: true |
575 }; | 598 }; |
576 runTestPseudoClassContains( | 599 runTestPseudoClassContains( |
577 test, "#parent div:-abp-contains(to hide)", expectations); | 600 test, "#parent div:-abp-contains(to hide)", expectations); |
578 }; | 601 }; |
579 | 602 |
580 exports.testPseudoClassContainsRegexp = function(test) | 603 exports.testPseudoClassContainsRegexp = async function(test) |
581 { | 604 { |
582 let expectations = { | 605 let expectations = { |
583 parent: true, | 606 parent: true, |
584 middle: true, | 607 middle: true, |
585 inside: true, | 608 inside: true, |
586 sibling: false, | 609 sibling: false, |
587 sibling2: true, | 610 sibling2: true, |
588 toHide: true | 611 toHide: true |
589 }; | 612 }; |
590 runTestPseudoClassContains( | 613 runTestPseudoClassContains( |
591 test, "#parent div:-abp-contains(/to\\shide/)", expectations); | 614 test, "#parent div:-abp-contains(/to\\shide/)", expectations); |
592 }; | 615 }; |
593 | 616 |
594 exports.testPseudoClassContainsRegexpIFlag = function(test) | 617 exports.testPseudoClassContainsRegexpIFlag = async function(test) |
595 { | 618 { |
596 let expectations = { | 619 let expectations = { |
597 parent: true, | 620 parent: true, |
598 middle: true, | 621 middle: true, |
599 inside: true, | 622 inside: true, |
600 sibling: false, | 623 sibling: false, |
601 sibling2: true, | 624 sibling2: true, |
602 toHide: true | 625 toHide: true |
603 }; | 626 }; |
604 runTestPseudoClassContains( | 627 runTestPseudoClassContains( |
605 test, "#parent div:-abp-contains(/to\\sHide/i)", expectations); | 628 test, "#parent div:-abp-contains(/to\\sHide/i)", expectations); |
606 }; | 629 }; |
607 | 630 |
608 exports.testPseudoClassContainsRegexpUFlag = function(test) | 631 exports.testPseudoClassContainsRegexpUFlag = async function(test) |
609 { | 632 { |
610 let expectations = { | 633 let expectations = { |
611 parent: true, | 634 parent: true, |
612 middle: true, | 635 middle: true, |
613 inside: true, | 636 inside: true, |
614 sibling: false, | 637 sibling: false, |
615 sibling2: true, | 638 sibling2: true, |
616 toHide: true | 639 toHide: true |
617 }; | 640 }; |
618 runTestPseudoClassContains( | 641 runTestPseudoClassContains( |
619 test, "#parent div:-abp-contains(/to\\shide\\s.!/u)", expectations); | 642 test, "#parent div:-abp-contains(/to\\shide\\s.!/u)", expectations); |
620 }; | 643 }; |
621 | 644 |
622 exports.testPseudoClassContainsWildcardNoMatch = function(test) | 645 exports.testPseudoClassContainsWildcardNoMatch = async function(test) |
623 { | 646 { |
624 let expectations = { | 647 let expectations = { |
625 parent: true, | 648 parent: true, |
626 middle: true, | 649 middle: true, |
627 inside: true, | 650 inside: true, |
628 sibling: true, | 651 sibling: true, |
629 sibling2: true, | 652 sibling2: true, |
630 toHide: true | 653 toHide: true |
631 }; | 654 }; |
632 // this filter shouldn't match anything as "*" has no meaning. | 655 // this filter shouldn't match anything as "*" has no meaning. |
633 runTestPseudoClassContains( | 656 runTestPseudoClassContains( |
634 test, "#parent div:-abp-contains(to *hide)", expectations); | 657 test, "#parent div:-abp-contains(to *hide)", expectations); |
635 }; | 658 }; |
636 | 659 |
637 exports.testPseudoClassContainsWildcardMatch = function(test) | 660 exports.testPseudoClassContainsWildcardMatch = async function(test) |
638 { | 661 { |
639 let expectations = { | 662 let expectations = { |
640 parent: true, | 663 parent: true, |
641 middle: true, | 664 middle: true, |
642 inside: true, | 665 inside: true, |
643 sibling: true, | 666 sibling: true, |
644 sibling2: false, | 667 sibling2: false, |
645 toHide: true | 668 toHide: true |
646 }; | 669 }; |
647 runTestPseudoClassContains( | 670 runTestPseudoClassContains( |
648 test, "#parent div:-abp-contains(Ad*)", expectations); | 671 test, "#parent div:-abp-contains(Ad*)", expectations); |
649 }; | 672 }; |
650 | 673 |
651 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 674 exports.testPseudoClassHasSelectorWithPropSelector = async function(test) |
652 { | 675 { |
653 let parent = createElementWithStyle("{}"); | 676 let parent = createElementWithStyle("{}"); |
654 let child = createElementWithStyle("{background-color: #000}", parent); | 677 let child = createElementWithStyle("{background-color: #000}", parent); |
655 applyElemHideEmulation( | 678 |
656 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 679 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)
))"]; |
657 ).then(() => | 680 |
658 { | 681 if (await applyElemHideEmulation(test, selectors)) |
659 expectVisible(test, child); | 682 { |
660 expectHidden(test, parent); | 683 expectVisible(test, child); |
661 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 684 expectHidden(test, parent); |
662 }; | 685 } |
663 | 686 |
664 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test) | 687 test.done(); |
| 688 }; |
| 689 |
| 690 exports.testPseudoClassHasSelectorWithPropSelector2 = async function(test) |
665 { | 691 { |
666 let parent = createElementWithStyle("{}"); | 692 let parent = createElementWithStyle("{}"); |
667 let child = createElementWithStyle("{}", parent); | 693 let child = createElementWithStyle("{}", parent); |
| 694 |
| 695 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)
))"]; |
| 696 |
668 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); | 697 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
669 applyElemHideEmulation( | 698 |
670 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 699 if (await applyElemHideEmulation(test, selectors)) |
671 ).then(() => | 700 { |
672 { | 701 expectVisible(test, child); |
673 expectVisible(test, child); | 702 expectHidden(test, parent); |
674 expectHidden(test, parent); | 703 } |
675 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 704 |
676 }; | 705 test.done(); |
677 | 706 }; |
678 exports.testDomUpdatesStyle = function(test) | 707 |
| 708 exports.testDomUpdatesStyle = async function(test) |
679 { | 709 { |
680 let parent = createElementWithStyle("{}"); | 710 let parent = createElementWithStyle("{}"); |
681 let child = createElementWithStyle("{}", parent); | 711 let child = createElementWithStyle("{}", parent); |
682 applyElemHideEmulation( | 712 |
683 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 713 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)
))"]; |
684 ).then(() => | 714 |
| 715 if (await applyElemHideEmulation(test, selectors)) |
685 { | 716 { |
686 expectVisible(test, child); | 717 expectVisible(test, child); |
687 expectVisible(test, parent); | 718 expectVisible(test, parent); |
688 | 719 |
689 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); | 720 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
690 return timeout(0); | 721 await timeout(0); |
691 }).then(() => | 722 |
692 { | 723 expectVisible(test, child); |
693 expectVisible(test, child); | 724 expectVisible(test, parent); |
694 expectVisible(test, parent); | 725 await timeout(REFRESH_INTERVAL); |
695 return timeout(REFRESH_INTERVAL); | 726 |
696 }).then(() => | 727 expectVisible(test, child); |
697 { | 728 expectHidden(test, parent); |
698 expectVisible(test, child); | 729 } |
699 expectHidden(test, parent); | 730 |
700 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 731 test.done(); |
701 }; | 732 }; |
702 | 733 |
703 exports.testDomUpdatesContent = function(test) | 734 exports.testDomUpdatesContent = async function(test) |
704 { | 735 { |
705 let parent = createElementWithStyle("{}"); | 736 let parent = createElementWithStyle("{}"); |
706 let child = createElementWithStyle("{}", parent); | 737 let child = createElementWithStyle("{}", parent); |
707 applyElemHideEmulation( | 738 |
708 ["div > div:-abp-contains(hide me)"] | 739 if (await applyElemHideEmulation(test, ["div > div:-abp-contains(hide me)"])) |
709 ).then(() => | |
710 { | 740 { |
711 expectVisible(test, parent); | 741 expectVisible(test, parent); |
712 expectVisible(test, child); | 742 expectVisible(test, child); |
713 | 743 |
714 child.textContent = "hide me"; | 744 child.textContent = "hide me"; |
715 return timeout(0); | 745 await timeout(0); |
716 }).then(() => | 746 |
717 { | 747 expectVisible(test, parent); |
718 expectVisible(test, parent); | 748 expectVisible(test, child); |
719 expectVisible(test, child); | 749 await timeout(REFRESH_INTERVAL); |
720 return timeout(REFRESH_INTERVAL); | 750 |
721 }).then(() => | |
722 { | |
723 expectVisible(test, parent); | 751 expectVisible(test, parent); |
724 expectHidden(test, child); | 752 expectHidden(test, child); |
725 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 753 } |
726 }; | 754 |
727 | 755 test.done(); |
728 exports.testDomUpdatesNewElement = function(test) | 756 }; |
| 757 |
| 758 exports.testDomUpdatesNewElement = async function(test) |
729 { | 759 { |
730 let parent = createElementWithStyle("{}"); | 760 let parent = createElementWithStyle("{}"); |
731 let child = createElementWithStyle("{ background-color: #000}", parent); | 761 let child = createElementWithStyle("{ background-color: #000}", parent); |
732 let sibling; | 762 let sibling; |
733 let child2; | 763 let child2; |
734 applyElemHideEmulation( | 764 |
735 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 765 let selectors = ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)
))"]; |
736 ).then(() => | 766 |
| 767 if (await applyElemHideEmulation(test, selectors)) |
737 { | 768 { |
738 expectHidden(test, parent); | 769 expectHidden(test, parent); |
739 expectVisible(test, child); | 770 expectVisible(test, child); |
740 | 771 |
741 sibling = createElementWithStyle("{}"); | 772 sibling = createElementWithStyle("{}"); |
742 return timeout(0); | 773 await timeout(0); |
743 }).then(() => | 774 |
744 { | |
745 expectHidden(test, parent); | 775 expectHidden(test, parent); |
746 expectVisible(test, child); | 776 expectVisible(test, child); |
747 expectVisible(test, sibling); | 777 expectVisible(test, sibling); |
748 | 778 |
749 return timeout(REFRESH_INTERVAL); | 779 await timeout(REFRESH_INTERVAL); |
750 }).then(() => | 780 |
751 { | |
752 expectHidden(test, parent); | 781 expectHidden(test, parent); |
753 expectVisible(test, child); | 782 expectVisible(test, child); |
754 expectVisible(test, sibling); | 783 expectVisible(test, sibling); |
755 | 784 |
756 child2 = createElementWithStyle("{ background-color: #000}", | 785 child2 = createElementWithStyle("{ background-color: #000}", |
757 sibling); | 786 sibling); |
758 return timeout(0); | 787 await timeout(0); |
759 }).then(() => | 788 |
760 { | |
761 expectVisible(test, child2); | 789 expectVisible(test, child2); |
762 return timeout(REFRESH_INTERVAL); | 790 await timeout(REFRESH_INTERVAL); |
763 }).then(() => | 791 |
764 { | |
765 expectHidden(test, parent); | 792 expectHidden(test, parent); |
766 expectVisible(test, child); | 793 expectVisible(test, child); |
767 expectHidden(test, sibling); | 794 expectHidden(test, sibling); |
768 expectVisible(test, child2); | 795 expectVisible(test, child2); |
769 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 796 } |
770 }; | 797 |
771 | 798 test.done(); |
772 exports.testPseudoClassPropertiesOnStyleSheetLoad = function(test) | 799 }; |
| 800 |
| 801 exports.testPseudoClassPropertiesOnStyleSheetLoad = async function(test) |
773 { | 802 { |
774 let parent = createElement(); | 803 let parent = createElement(); |
775 let child = createElement(parent); | 804 let child = createElement(parent); |
776 applyElemHideEmulation( | 805 |
777 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 806 let selectors = [ |
778 "div:-abp-contains(hide me)", | 807 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
779 "div:-abp-has(> div.hideMe)"] | 808 "div:-abp-contains(hide me)", |
780 ).then(() => timeout(REFRESH_INTERVAL) | 809 "div:-abp-has(> div.hideMe)" |
781 ).then(() => | 810 ]; |
782 { | 811 |
| 812 if (await applyElemHideEmulation(test, selectors)) |
| 813 { |
| 814 await timeout(REFRESH_INTERVAL); |
| 815 |
783 expectVisible(test, parent); | 816 expectVisible(test, parent); |
784 expectVisible(test, child); | 817 expectVisible(test, child); |
785 | 818 |
786 // Load a style sheet that targets the parent element. This should run only | 819 // Load a style sheet that targets the parent element. This should run only |
787 // the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern. | 820 // the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern. |
788 insertStyleRule("#" + parent.id + " {background-color: #000}"); | 821 insertStyleRule("#" + parent.id + " {background-color: #000}"); |
789 | 822 |
790 return timeout(REFRESH_INTERVAL); | 823 await timeout(REFRESH_INTERVAL); |
791 }).then(() => | 824 |
792 { | 825 expectHidden(test, parent); |
793 expectHidden(test, parent); | 826 expectVisible(test, child); |
794 expectVisible(test, child); | 827 } |
795 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 828 |
796 }; | 829 test.done(); |
797 | 830 }; |
798 exports.testPlainAttributeOnDomMutation = function(test) | 831 |
| 832 exports.testPlainAttributeOnDomMutation = async function(test) |
799 { | 833 { |
800 let parent = createElement(); | 834 let parent = createElement(); |
801 let child = createElement(parent); | 835 let child = createElement(parent); |
802 applyElemHideEmulation( | 836 |
803 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 837 let selectors = [ |
804 "div[data-hide-me]", | 838 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
805 "div:-abp-contains(hide me)", | 839 "div[data-hide-me]", |
806 "div:-abp-has(> div.hideMe)"] | 840 "div:-abp-contains(hide me)", |
807 ).then(() => timeout(REFRESH_INTERVAL) | 841 "div:-abp-has(> div.hideMe)" |
808 ).then(() => | 842 ]; |
809 { | 843 |
| 844 if (await applyElemHideEmulation(test, selectors)) |
| 845 { |
| 846 await timeout(REFRESH_INTERVAL); |
| 847 |
810 expectVisible(test, parent); | 848 expectVisible(test, parent); |
811 expectVisible(test, child); | 849 expectVisible(test, child); |
812 | 850 |
813 // Set the "data-hide-me" attribute on the child element. | 851 // Set the "data-hide-me" attribute on the child element. |
814 // | 852 // |
815 // Note: Since the "div[data-hide-me]" pattern has already been processed | 853 // Note: Since the "div[data-hide-me]" pattern has already been processed |
816 // and the selector added to the document's style sheet, this will in fact | 854 // and the selector added to the document's style sheet, this will in fact |
817 // not do anything at our end, but the browser will just match the selector | 855 // not do anything at our end, but the browser will just match the selector |
818 // and hide the element. | 856 // and hide the element. |
819 child.setAttribute("data-hide-me", ""); | 857 child.setAttribute("data-hide-me", ""); |
820 | 858 |
821 return timeout(REFRESH_INTERVAL); | 859 await timeout(REFRESH_INTERVAL); |
822 }).then(() => | 860 |
823 { | |
824 expectVisible(test, parent); | 861 expectVisible(test, parent); |
825 expectHidden(test, child); | 862 expectHidden(test, child); |
826 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 863 } |
827 }; | 864 |
828 | 865 test.done(); |
829 exports.testPseudoClassContainsOnDomMutation = function(test) | 866 }; |
| 867 |
| 868 exports.testPseudoClassContainsOnDomMutation = async function(test) |
830 { | 869 { |
831 let parent = createElement(); | 870 let parent = createElement(); |
832 let child = createElement(parent); | 871 let child = createElement(parent); |
833 | 872 |
| 873 let selectors = [ |
| 874 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
| 875 "div[data-hide-me]", |
| 876 "div:-abp-contains(hide me)", |
| 877 "div:-abp-has(> div.hideMe)" |
| 878 ]; |
| 879 |
834 child.innerText = "do nothing"; | 880 child.innerText = "do nothing"; |
835 | 881 |
836 applyElemHideEmulation( | 882 if (await applyElemHideEmulation(test, selectors)) |
837 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 883 { |
838 "div[data-hide-me]", | 884 await timeout(REFRESH_INTERVAL); |
839 "div:-abp-contains(hide me)", | 885 |
840 "div:-abp-has(> div.hideMe)"] | |
841 ).then(() => timeout(REFRESH_INTERVAL) | |
842 ).then(() => | |
843 { | |
844 expectVisible(test, parent); | 886 expectVisible(test, parent); |
845 expectVisible(test, child); | 887 expectVisible(test, child); |
846 | 888 |
847 // Set the child element's text to "hide me". This should run only the | 889 // Set the child element's text to "hide me". This should run only the |
848 // "div:-abp-contains(hide me)" pattern. | 890 // "div:-abp-contains(hide me)" pattern. |
849 // | 891 // |
850 // Note: We need to set Node.innerText here in order to trigger the | 892 // Note: We need to set Node.innerText here in order to trigger the |
851 // "characterData" DOM mutation on Chromium. If we set Node.textContent | 893 // "characterData" DOM mutation on Chromium. If we set Node.textContent |
852 // instead, it triggers the "childList" DOM mutation instead. | 894 // instead, it triggers the "childList" DOM mutation instead. |
853 child.innerText = "hide me"; | 895 child.innerText = "hide me"; |
854 | 896 |
855 return timeout(REFRESH_INTERVAL); | 897 await timeout(REFRESH_INTERVAL); |
856 }).then(() => | 898 |
857 { | 899 expectHidden(test, parent); |
858 expectHidden(test, parent); | 900 expectVisible(test, child); |
859 expectVisible(test, child); | 901 } |
860 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 902 |
861 }; | 903 test.done(); |
862 | 904 }; |
863 exports.testPseudoClassHasOnDomMutation = function(test) | 905 |
| 906 exports.testPseudoClassHasOnDomMutation = async function(test) |
864 { | 907 { |
865 let parent = createElement(); | 908 let parent = createElement(); |
866 let child = null; | 909 let child = null; |
867 applyElemHideEmulation( | 910 |
868 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 911 let selectors = [ |
869 "div[data-hide-me]", | 912 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
870 "div:-abp-contains(hide me)", | 913 "div[data-hide-me]", |
871 "div:-abp-has(> div)"] | 914 "div:-abp-contains(hide me)", |
872 ).then(() => timeout(REFRESH_INTERVAL) | 915 "div:-abp-has(> div)" |
873 ).then(() => | 916 ]; |
874 { | 917 |
| 918 if (await applyElemHideEmulation(test, selectors)) |
| 919 { |
| 920 await timeout(REFRESH_INTERVAL); |
| 921 |
875 expectVisible(test, parent); | 922 expectVisible(test, parent); |
876 | 923 |
877 // Add the child element. This should run all the DOM-dependent patterns | 924 // Add the child element. This should run all the DOM-dependent patterns |
878 // ("div:-abp-contains(hide me)" and "div:-abp-has(> div)"). | 925 // ("div:-abp-contains(hide me)" and "div:-abp-has(> div)"). |
879 child = createElement(parent); | 926 child = createElement(parent); |
880 | 927 |
881 return timeout(REFRESH_INTERVAL); | 928 await timeout(REFRESH_INTERVAL); |
882 }).then(() => | 929 |
883 { | 930 expectHidden(test, parent); |
884 expectHidden(test, parent); | 931 expectVisible(test, child); |
885 expectVisible(test, child); | 932 } |
886 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 933 |
887 }; | 934 test.done(); |
888 | 935 }; |
889 exports.testPseudoClassHasWithClassOnDomMutation = function(test) | 936 |
| 937 exports.testPseudoClassHasWithClassOnDomMutation = async function(test) |
890 { | 938 { |
891 let parent = createElement(); | 939 let parent = createElement(); |
892 let child = createElement(parent); | 940 let child = createElement(parent); |
893 applyElemHideEmulation( | 941 |
894 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 942 let selectors = [ |
895 "div[data-hide-me]", | 943 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
896 "div:-abp-contains(hide me)", | 944 "div[data-hide-me]", |
897 "div:-abp-has(> div.hideMe)"] | 945 "div:-abp-contains(hide me)", |
898 ).then(() => timeout(REFRESH_INTERVAL) | 946 "div:-abp-has(> div.hideMe)" |
899 ).then(() => | 947 ]; |
900 { | 948 |
| 949 if (await applyElemHideEmulation(test, selectors)) |
| 950 { |
| 951 await timeout(REFRESH_INTERVAL); |
| 952 |
901 expectVisible(test, parent); | 953 expectVisible(test, parent); |
902 expectVisible(test, child); | 954 expectVisible(test, child); |
903 | 955 |
904 // Set the child element's class to "hideMe". This should run only the | 956 // Set the child element's class to "hideMe". This should run only the |
905 // "div:-abp-has(> div.hideMe)" pattern. | 957 // "div:-abp-has(> div.hideMe)" pattern. |
906 child.className = "hideMe"; | 958 child.className = "hideMe"; |
907 | 959 |
908 return timeout(REFRESH_INTERVAL); | 960 await timeout(REFRESH_INTERVAL); |
909 }).then(() => | 961 |
910 { | 962 expectHidden(test, parent); |
911 expectHidden(test, parent); | 963 expectVisible(test, child); |
912 expectVisible(test, child); | 964 } |
913 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 965 |
914 }; | 966 test.done(); |
915 | 967 }; |
916 exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = function(test) | 968 |
| 969 exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = async function(
test) |
917 { | 970 { |
918 let parent = createElement(); | 971 let parent = createElement(); |
919 let child = createElement(parent); | 972 let child = createElement(parent); |
920 | 973 |
| 974 let selectors = [ |
| 975 "div:-abp-properties(background-color: rgb(0, 0, 0))", |
| 976 "div[data-hide-me]", |
| 977 "div:-abp-contains(hide me)", |
| 978 "div:-abp-has(> div:-abp-contains(hide me))" |
| 979 ]; |
| 980 |
921 child.innerText = "do nothing"; | 981 child.innerText = "do nothing"; |
922 | 982 |
923 applyElemHideEmulation( | 983 if (await applyElemHideEmulation(test, selectors)) |
924 ["div:-abp-properties(background-color: rgb(0, 0, 0))", | 984 { |
925 "div[data-hide-me]", | 985 await timeout(REFRESH_INTERVAL); |
926 "div:-abp-contains(hide me)", | 986 |
927 "div:-abp-has(> div:-abp-contains(hide me))"] | |
928 ).then(() => timeout(REFRESH_INTERVAL) | |
929 ).then(() => | |
930 { | |
931 expectVisible(test, parent); | 987 expectVisible(test, parent); |
932 expectVisible(test, child); | 988 expectVisible(test, child); |
933 | 989 |
934 // Set the child element's text to "hide me". This should run only the | 990 // Set the child element's text to "hide me". This should run only the |
935 // "div:-abp-contains(hide me)" and | 991 // "div:-abp-contains(hide me)" and |
936 // "div:-abp-has(> div:-abp-contains(hide me))" patterns. | 992 // "div:-abp-has(> div:-abp-contains(hide me))" patterns. |
937 child.innerText = "hide me"; | 993 child.innerText = "hide me"; |
938 | 994 |
939 return timeout(REFRESH_INTERVAL); | 995 await timeout(REFRESH_INTERVAL); |
940 }).then(() => | 996 |
941 { | |
942 // Note: Even though it runs both the :-abp-contains() patterns, it only | 997 // Note: Even though it runs both the :-abp-contains() patterns, it only |
943 // hides the parent element because of revision d7d51d29aa34. | 998 // hides the parent element because of revision d7d51d29aa34. |
944 expectHidden(test, parent); | 999 expectHidden(test, parent); |
945 expectVisible(test, child); | 1000 expectVisible(test, child); |
946 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 1001 } |
947 }; | 1002 |
948 | 1003 test.done(); |
949 exports.testOnlyRelevantElementsProcessed = function(test) | 1004 }; |
| 1005 |
| 1006 exports.testOnlyRelevantElementsProcessed = async function(test) |
950 { | 1007 { |
951 // <body> | 1008 // <body> |
952 // <div id="n1"> | 1009 // <div id="n1"> |
953 // <p id="n1_1"></p> | 1010 // <p id="n1_1"></p> |
954 // <p id="n1_2"></p> | 1011 // <p id="n1_2"></p> |
955 // <p id="n1_4">Hello</p> | 1012 // <p id="n1_4">Hello</p> |
956 // </div> | 1013 // </div> |
957 // <div id="n2"> | 1014 // <div id="n2"> |
958 // <p id="n2_1"></p> | 1015 // <p id="n2_1"></p> |
959 // <p id="n2_2"></p> | 1016 // <p id="n2_2"></p> |
(...skipping 10 matching lines...) Expand all Loading... |
970 // <p id="n4_4">Hello</p> | 1027 // <p id="n4_4">Hello</p> |
971 // </div> | 1028 // </div> |
972 // </body> | 1029 // </body> |
973 for (let i of [1, 2, 3, 4]) | 1030 for (let i of [1, 2, 3, 4]) |
974 { | 1031 { |
975 let n = createElement(null, "div", `n${i}`); | 1032 let n = createElement(null, "div", `n${i}`); |
976 for (let [j, text] of [[1], [2], [4, "Hello"]]) | 1033 for (let [j, text] of [[1], [2], [4, "Hello"]]) |
977 createElement(n, "p", `n${i}_${j}`, text); | 1034 createElement(n, "p", `n${i}_${j}`, text); |
978 } | 1035 } |
979 | 1036 |
980 applyElemHideEmulation( | 1037 let selectors = [ |
981 ["p:-abp-contains(Hello)", | 1038 "p:-abp-contains(Hello)", |
982 "div:-abp-contains(Try me!)", | 1039 "div:-abp-contains(Try me!)", |
983 "div:-abp-has(p:-abp-contains(This is good))"] | 1040 "div:-abp-has(p:-abp-contains(This is good))" |
984 ).then(() => timeout(REFRESH_INTERVAL) | 1041 ]; |
985 ).then(() => | 1042 |
| 1043 if (await applyElemHideEmulation(test, selectors)) |
986 { | 1044 { |
| 1045 await timeout(REFRESH_INTERVAL); |
| 1046 |
987 // This is only a sanity check to make sure everything else is working | 1047 // This is only a sanity check to make sure everything else is working |
988 // before we do the actual test. | 1048 // before we do the actual test. |
989 for (let i of [1, 2, 3, 4]) | 1049 for (let i of [1, 2, 3, 4]) |
990 { | 1050 { |
991 for (let j of [1, 2, 4]) | 1051 for (let j of [1, 2, 4]) |
992 { | 1052 { |
993 let id = `n${i}_${j}`; | 1053 let id = `n${i}_${j}`; |
994 if (j == 4) | 1054 if (j == 4) |
995 expectHidden(test, testDocument.getElementById(id), id); | 1055 expectHidden(test, testDocument.getElementById(id), id); |
996 else | 1056 else |
997 expectVisible(test, testDocument.getElementById(id), id); | 1057 expectVisible(test, testDocument.getElementById(id), id); |
998 } | 1058 } |
999 } | 1059 } |
1000 | 1060 |
1001 // All <div> and <p> elements should be processed initially. | 1061 // All <div> and <p> elements should be processed initially. |
1002 for (let element of [...testDocument.getElementsByTagName("div"), | 1062 for (let element of [...testDocument.getElementsByTagName("div"), |
1003 ...testDocument.getElementsByTagName("p")]) | 1063 ...testDocument.getElementsByTagName("p")]) |
1004 { | 1064 { |
1005 expectProcessed(test, element, element.id); | 1065 expectProcessed(test, element, element.id); |
1006 } | 1066 } |
1007 | 1067 |
1008 // Modify the text in <p id="n4_1"> | 1068 // Modify the text in <p id="n4_1"> |
1009 testDocument.getElementById("n4_1").innerText = "Try me!"; | 1069 testDocument.getElementById("n4_1").innerText = "Try me!"; |
1010 | 1070 |
1011 return timeout(REFRESH_INTERVAL); | 1071 await timeout(REFRESH_INTERVAL); |
1012 }).then(() => | 1072 |
1013 { | |
1014 // When an element's text is modified, only the element or one of its | 1073 // When an element's text is modified, only the element or one of its |
1015 // ancestors matching any selector is processed for :-abp-has() and | 1074 // ancestors matching any selector is processed for :-abp-has() and |
1016 // :-abp-contains() | 1075 // :-abp-contains() |
1017 for (let element of [...testDocument.getElementsByTagName("div"), | 1076 for (let element of [...testDocument.getElementsByTagName("div"), |
1018 ...testDocument.getElementsByTagName("p")]) | 1077 ...testDocument.getElementsByTagName("p")]) |
1019 { | 1078 { |
1020 if (element.id == "n4" || element.id == "n4_1") | 1079 if (element.id == "n4" || element.id == "n4_1") |
1021 expectProcessed(test, element, element.id); | 1080 expectProcessed(test, element, element.id); |
1022 else | 1081 else |
1023 expectNotProcessed(test, element, element.id); | 1082 expectNotProcessed(test, element, element.id); |
1024 } | 1083 } |
1025 | 1084 |
1026 // Create a new <p id="n2_3"> element with no text. | 1085 // Create a new <p id="n2_3"> element with no text. |
1027 createElement(testDocument.getElementById("n2"), "p", "n2_3"); | 1086 createElement(testDocument.getElementById("n2"), "p", "n2_3"); |
1028 | 1087 |
1029 return timeout(REFRESH_INTERVAL); | 1088 await timeout(REFRESH_INTERVAL); |
1030 }).then(() => | 1089 |
1031 { | |
1032 // When a new element is added, only the element or one of its ancestors | 1090 // When a new element is added, only the element or one of its ancestors |
1033 // matching any selector is processed for :-abp-has() and :-abp-contains() | 1091 // matching any selector is processed for :-abp-has() and :-abp-contains() |
1034 for (let element of [...testDocument.getElementsByTagName("div"), | 1092 for (let element of [...testDocument.getElementsByTagName("div"), |
1035 ...testDocument.getElementsByTagName("p")]) | 1093 ...testDocument.getElementsByTagName("p")]) |
1036 { | 1094 { |
1037 if (element.id == "n2" || element.id == "n2_3") | 1095 if (element.id == "n2" || element.id == "n2_3") |
1038 expectProcessed(test, element, element.id); | 1096 expectProcessed(test, element, element.id); |
1039 else | 1097 else |
1040 expectNotProcessed(test, element, element.id); | 1098 expectNotProcessed(test, element, element.id); |
1041 } | 1099 } |
1042 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 1100 } |
| 1101 |
| 1102 test.done(); |
1043 }; | 1103 }; |
OLD | NEW |