LEFT | RIGHT |
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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 } | 367 } |
368 } | 368 } |
369 | 369 |
370 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
, expectations) | 370 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
, expectations) |
371 { | 371 { |
372 testDocument.body.innerHTML = `<div id="parent"> | 372 testDocument.body.innerHTML = `<div id="parent"> |
373 <div id="middle"> | 373 <div id="middle"> |
374 <div id="middle1"><div id="inside" class="inside"></div></div> | 374 <div id="middle1"><div id="inside" class="inside"></div></div> |
375 </div> | 375 </div> |
376 <div id="sibling"> | 376 <div id="sibling"> |
377 <div id="tohide">to hide</div> | 377 <div id="tohide"><span>to hide</span></div> |
378 </div> | 378 </div> |
379 <div id="sibling2"> | 379 <div id="sibling2"> |
380 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 380 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
381 </div> | 381 </div> |
382 </div>`; | 382 </div>`; |
383 let elems = { | 383 let elems = { |
384 parent: testDocument.getElementById("parent"), | 384 parent: testDocument.getElementById("parent"), |
385 middle: testDocument.getElementById("middle"), | 385 middle: testDocument.getElementById("middle"), |
386 inside: testDocument.getElementById("inside"), | 386 inside: testDocument.getElementById("inside"), |
387 sibling: testDocument.getElementById("sibling"), | 387 sibling: testDocument.getElementById("sibling"), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 middile: true, | 420 middile: true, |
421 inside: true, | 421 inside: true, |
422 sibling: true, | 422 sibling: true, |
423 sibling2: true, | 423 sibling2: true, |
424 toHide: false | 424 toHide: false |
425 }; | 425 }; |
426 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 426 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
427 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); | 427 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); |
428 }; | 428 }; |
429 | 429 |
| 430 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = function(test) |
| 431 { |
| 432 let expectations = { |
| 433 parent: true, |
| 434 middile: true, |
| 435 inside: true, |
| 436 sibling: true, |
| 437 sibling2: true, |
| 438 toHide: false |
| 439 }; |
| 440 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 441 test, "div:-abp-has(> div:-abp-has(div.inside)) + div > div", expectations); |
| 442 }; |
| 443 |
430 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test) | 444 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test) |
431 { | 445 { |
432 let expectations = { | 446 let expectations = { |
433 parent: true, | 447 parent: true, |
434 middile: true, | 448 middile: true, |
435 inside: true, | 449 inside: true, |
436 sibling: true, | 450 sibling: true, |
437 sibling2: true, | 451 sibling2: true, |
438 toHide: true | 452 toHide: true |
439 }; | 453 }; |
440 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 454 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
441 test, "div:-abp-has(> body div.inside) + div > div", expectations); | 455 test, "div:-abp-has(> body div.inside) + div > div", expectations); |
442 }; | 456 }; |
443 | 457 |
444 function runTestPseudClassContains(test, selector, expectations) | 458 exports.testPseudoClassHasSelectorWithSuffixSiblingContains = function(test) |
| 459 { |
| 460 let expectations = { |
| 461 parent: true, |
| 462 middile: true, |
| 463 inside: true, |
| 464 sibling: true, |
| 465 sibling2: true, |
| 466 toHide: true |
| 467 }; |
| 468 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 469 test, "div:-abp-has(> span:-abp-contains(Advertisment))", expectations); |
| 470 }; |
| 471 |
| 472 function runTestPseudoClassContains(test, selector, expectations) |
445 { | 473 { |
446 testDocument.body.innerHTML = `<div id="parent"> | 474 testDocument.body.innerHTML = `<div id="parent"> |
447 <div id="middle"> | 475 <div id="middle"> |
448 <div id="middle1"><div id="inside" class="inside"></div></div> | 476 <div id="middle1"><div id="inside" class="inside"></div></div> |
449 </div> | 477 </div> |
450 <div id="sibling"> | 478 <div id="sibling"> |
451 <div id="tohide">to hide</div> | 479 <div id="tohide">to hide</div> |
452 </div> | 480 </div> |
453 <div id="sibling2"> | 481 <div id="sibling2"> |
454 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 482 <div id="sibling21"><div id="sibling211" class="inside">Ad*</div></div> |
455 </div> | 483 </div> |
456 </div>`; | 484 </div>`; |
457 let elems = { | 485 let elems = { |
458 parent: testDocument.getElementById("parent"), | 486 parent: testDocument.getElementById("parent"), |
459 middle: testDocument.getElementById("middle"), | 487 middle: testDocument.getElementById("middle"), |
460 inside: testDocument.getElementById("inside"), | 488 inside: testDocument.getElementById("inside"), |
461 sibling: testDocument.getElementById("sibling"), | 489 sibling: testDocument.getElementById("sibling"), |
462 sibling2: testDocument.getElementById("sibling2"), | 490 sibling2: testDocument.getElementById("sibling2"), |
463 toHide: testDocument.getElementById("tohide") | 491 toHide: testDocument.getElementById("tohide") |
464 }; | 492 }; |
465 | 493 |
466 applyElemHideEmulation( | 494 applyElemHideEmulation( |
467 [selector] | 495 [selector] |
468 ).then( | 496 ).then( |
469 () => compareExpectations(test, elems, expectations) | 497 () => compareExpectations(test, elems, expectations) |
470 ).catch(unexpectedError.bind(test)).then(() => test.done()); | 498 ).catch(unexpectedError.bind(test)).then(() => test.done()); |
471 } | 499 } |
472 | 500 |
473 exports.testPseudoClassContainsText = function(test) | 501 exports.testPseudoClassContainsText = function(test) |
474 { | 502 { |
475 let expectations = { | 503 let expectations = { |
476 parent: true, | 504 parent: true, |
477 middle: true, | 505 middle: true, |
478 inside: true, | 506 inside: true, |
479 sibling: false, | 507 sibling: false, |
480 sibling2: true, | 508 sibling2: true, |
481 toHide: false | 509 toHide: false |
482 }; | 510 }; |
483 runTestPseudClassContains( | 511 runTestPseudoClassContains( |
484 test, "#parent div:-abp-contains(to hide)", expectations); | 512 test, "#parent div:-abp-contains(to hide)", expectations); |
485 }; | 513 }; |
486 | 514 |
487 exports.testPseudoClassContainsRegexp = function(test) | 515 exports.testPseudoClassContainsRegexp = function(test) |
488 { | 516 { |
489 let expectations = { | 517 let expectations = { |
490 parent: true, | 518 parent: true, |
491 middle: true, | 519 middle: true, |
492 inside: true, | 520 inside: true, |
493 sibling: false, | 521 sibling: false, |
494 sibling2: true, | 522 sibling2: true, |
495 toHide: false | 523 toHide: false |
496 }; | 524 }; |
497 runTestPseudClassContains( | 525 runTestPseudoClassContains( |
498 test, "#parent div:-abp-contains(/to\\shide/)", expectations); | 526 test, "#parent div:-abp-contains(/to\\shide/)", expectations); |
| 527 }; |
| 528 |
| 529 exports.testPseudoClassContainsRegexpIFlag = function(test) |
| 530 { |
| 531 let expectations = { |
| 532 parent: true, |
| 533 middle: true, |
| 534 inside: true, |
| 535 sibling: false, |
| 536 sibling2: true, |
| 537 toHide: false |
| 538 }; |
| 539 runTestPseudoClassContains( |
| 540 test, "#parent div:-abp-contains(/to\\sHide/i)", expectations); |
| 541 }; |
| 542 |
| 543 exports.testPseudoClassContainsWildcardNoMatch = function(test) |
| 544 { |
| 545 let expectations = { |
| 546 parent: true, |
| 547 middle: true, |
| 548 inside: true, |
| 549 sibling: true, |
| 550 sibling2: true, |
| 551 toHide: true |
| 552 }; |
| 553 // this filter shouldn't match anything as "*" has no meaning. |
| 554 runTestPseudoClassContains( |
| 555 test, "#parent div:-abp-contains(to *hide)", expectations); |
| 556 }; |
| 557 |
| 558 exports.testPseudoClassContainsWildcardMatch = function(test) |
| 559 { |
| 560 let expectations = { |
| 561 parent: true, |
| 562 middle: true, |
| 563 inside: true, |
| 564 sibling: true, |
| 565 sibling2: false, |
| 566 toHide: true |
| 567 }; |
| 568 runTestPseudoClassContains( |
| 569 test, "#parent div:-abp-contains(Ad*)", expectations); |
499 }; | 570 }; |
500 | 571 |
501 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 572 exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
502 { | 573 { |
503 let parent = createElementWithStyle("{}"); | 574 let parent = createElementWithStyle("{}"); |
504 let child = createElementWithStyle("{background-color: #000}", parent); | 575 let child = createElementWithStyle("{background-color: #000}", parent); |
505 applyElemHideEmulation( | 576 applyElemHideEmulation( |
506 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 577 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
507 ).then(() => | 578 ).then(() => |
508 { | 579 { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 expectVisible(test, child2); | 682 expectVisible(test, child2); |
612 return timeout(REFRESH_INTERVAL); | 683 return timeout(REFRESH_INTERVAL); |
613 }).then(() => | 684 }).then(() => |
614 { | 685 { |
615 expectHidden(test, parent); | 686 expectHidden(test, parent); |
616 expectVisible(test, child); | 687 expectVisible(test, child); |
617 expectHidden(test, sibling); | 688 expectHidden(test, sibling); |
618 expectVisible(test, child2); | 689 expectVisible(test, child2); |
619 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 690 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
620 }; | 691 }; |
LEFT | RIGHT |