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