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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 ["div:-abp-has(div) + div > div"] | 346 ["div:-abp-has(div) + div > div"] |
347 ).then(() => | 347 ).then(() => |
348 { | 348 { |
349 expectVisible(test, parent); | 349 expectVisible(test, parent); |
350 expectVisible(test, middle); | 350 expectVisible(test, middle); |
351 expectVisible(test, sibling); | 351 expectVisible(test, sibling); |
352 expectHidden(test, toHide); | 352 expectHidden(test, toHide); |
353 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 353 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
354 }; | 354 }; |
355 | 355 |
356 function compareExpectations(test, elems, expectations) | |
357 { | |
358 for (let elem in expectations) | |
359 { | |
360 if (elems[elem]) | |
361 { | |
362 if (expectations[elem]) | |
363 expectVisible(test, elems[elem]); | |
364 else | |
365 expectHidden(test, elems[elem]); | |
366 } | |
367 } | |
368 } | |
369 | |
356 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector , expectations) | 370 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector , expectations) |
357 { | 371 { |
358 testDocument.body.innerHTML = `<div id="parent"> | 372 testDocument.body.innerHTML = `<div id="parent"> |
359 <div id="middle"> | 373 <div id="middle"> |
360 <div id="middle1"><div id="inside" class="inside"></div></div> | 374 <div id="middle1"><div id="inside" class="inside"></div></div> |
361 </div> | 375 </div> |
362 <div id="sibling"> | 376 <div id="sibling"> |
363 <div id="tohide">to hide</div> | 377 <div id="tohide">to hide</div> |
364 </div> | 378 </div> |
365 <div id="sibling2"> | 379 <div id="sibling2"> |
366 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 380 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
367 </div> | 381 </div> |
368 </div>`; | 382 </div>`; |
369 let elems = { | 383 let elems = { |
370 parent: testDocument.getElementById("parent"), | 384 parent: testDocument.getElementById("parent"), |
371 middle: testDocument.getElementById("middle"), | 385 middle: testDocument.getElementById("middle"), |
372 inside: testDocument.getElementById("inside"), | 386 inside: testDocument.getElementById("inside"), |
373 sibling: testDocument.getElementById("sibling"), | 387 sibling: testDocument.getElementById("sibling"), |
374 sibling2: testDocument.getElementById("sibling2"), | 388 sibling2: testDocument.getElementById("sibling2"), |
375 toHide: testDocument.getElementById("tohide") | 389 toHide: testDocument.getElementById("tohide") |
376 }; | 390 }; |
377 | 391 |
378 insertStyleRule(".inside {}"); | 392 insertStyleRule(".inside {}"); |
379 | 393 |
380 applyElemHideEmulation( | 394 applyElemHideEmulation( |
381 [selector] | 395 [selector] |
382 ).then(() => | 396 ).then(() => |
383 { | 397 { |
384 for (let elem in expectations) | 398 compareExpectations(test, elems, expectations); |
385 if (elems[elem]) | |
386 { | |
387 if (expectations[elem]) | |
388 expectVisible(test, elems[elem]); | |
389 else | |
390 expectHidden(test, elems[elem]); | |
391 } | |
392 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 399 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
393 } | 400 } |
394 | 401 |
395 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) | 402 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) |
396 { | 403 { |
397 let expectations = { | 404 let expectations = { |
398 parent: true, | 405 parent: true, |
399 middile: true, | 406 middile: true, |
400 inside: true, | 407 inside: true, |
401 sibling: true, | 408 sibling: true, |
(...skipping 25 matching lines...) Expand all Loading... | |
427 middile: true, | 434 middile: true, |
428 inside: true, | 435 inside: true, |
429 sibling: true, | 436 sibling: true, |
430 sibling2: true, | 437 sibling2: true, |
431 toHide: true | 438 toHide: true |
432 }; | 439 }; |
433 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 440 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
434 test, "div:-abp-has(> body div.inside) + div > div", expectations); | 441 test, "div:-abp-has(> body div.inside) + div > div", expectations); |
435 }; | 442 }; |
436 | 443 |
437 exports.testPseudoClassContains = function(test) | 444 function runTestPseudClassContains(test, selector, expectations) |
kzar
2018/01/08 15:29:35
Nit: Typo "Pseudo"
hub
2018/01/08 16:29:51
Done.
| |
438 { | 445 { |
439 testDocument.body.innerHTML = `<div id="parent"> | 446 testDocument.body.innerHTML = `<div id="parent"> |
440 <div id="middle"> | 447 <div id="middle"> |
441 <div id="middle1"><div id="inside" class="inside"></div></div> | 448 <div id="middle1"><div id="inside" class="inside"></div></div> |
442 </div> | 449 </div> |
443 <div id="sibling"> | 450 <div id="sibling"> |
444 <div id="tohide">to hide</div> | 451 <div id="tohide">to hide</div> |
445 </div> | 452 </div> |
446 <div id="sibling2"> | 453 <div id="sibling2"> |
447 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 454 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
448 </div> | 455 </div> |
449 </div>`; | 456 </div>`; |
450 let parent = testDocument.getElementById("parent"); | 457 let elems = { |
451 let middle = testDocument.getElementById("middle"); | 458 parent: testDocument.getElementById("parent"), |
452 let inside = testDocument.getElementById("inside"); | 459 middle: testDocument.getElementById("middle"), |
453 let sibling = testDocument.getElementById("sibling"); | 460 inside: testDocument.getElementById("inside"), |
454 let sibling2 = testDocument.getElementById("sibling2"); | 461 sibling: testDocument.getElementById("sibling"), |
455 let toHide = testDocument.getElementById("tohide"); | 462 sibling2: testDocument.getElementById("sibling2"), |
463 toHide: testDocument.getElementById("tohide") | |
464 }; | |
456 | 465 |
457 applyElemHideEmulation( | 466 applyElemHideEmulation( |
458 ["#parent div:-abp-contains(to hide)"] | 467 [selector] |
459 ).then(() => | 468 ).then( |
460 { | 469 () => compareExpectations(test, elems, expectations) |
461 expectVisible(test, parent); | 470 ).catch(unexpectedError.bind(test)).then(() => test.done()); |
462 expectVisible(test, middle); | 471 } |
463 expectVisible(test, inside); | 472 |
464 expectHidden(test, sibling); | 473 exports.testPseudoClassContainsText = function(test) |
465 expectVisible(test, sibling2); | 474 { |
466 expectHidden(test, toHide); | 475 let expectations = { |
467 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 476 parent: true, |
477 middle: true, | |
478 inside: true, | |
479 sibling: false, | |
480 sibling2: true, | |
481 toHide: false | |
482 }; | |
483 runTestPseudClassContains( | |
484 test, "#parent div:-abp-contains(to hide)", expectations); | |
485 }; | |
486 | |
487 exports.testPseudoClassContainsRegexp = function(test) | |
488 { | |
489 let expectations = { | |
490 parent: true, | |
491 middle: true, | |
492 inside: true, | |
493 sibling: false, | |
494 sibling2: true, | |
495 toHide: false | |
496 }; | |
497 runTestPseudClassContains( | |
498 test, "#parent div:-abp-contains(/to\\shide/)", expectations); | |
468 }; | 499 }; |
469 | 500 |
470 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 501 exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
471 { | 502 { |
472 let parent = createElementWithStyle("{}"); | 503 let parent = createElementWithStyle("{}"); |
473 let child = createElementWithStyle("{background-color: #000}", parent); | 504 let child = createElementWithStyle("{background-color: #000}", parent); |
474 applyElemHideEmulation( | 505 applyElemHideEmulation( |
475 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 506 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
476 ).then(() => | 507 ).then(() => |
477 { | 508 { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 expectVisible(test, child2); | 611 expectVisible(test, child2); |
581 return timeout(REFRESH_INTERVAL); | 612 return timeout(REFRESH_INTERVAL); |
582 }).then(() => | 613 }).then(() => |
583 { | 614 { |
584 expectHidden(test, parent); | 615 expectHidden(test, parent); |
585 expectVisible(test, child); | 616 expectVisible(test, child); |
586 expectHidden(test, sibling); | 617 expectHidden(test, sibling); |
587 expectVisible(test, child2); | 618 expectVisible(test, child2); |
588 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 619 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
589 }; | 620 }; |
OLD | NEW |