| 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"><span>to hide</span></div> | 377 <div id="tohide"><span>to hide</span></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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 middile: true, | 462 middile: true, |
| 456 inside: true, | 463 inside: true, |
| 457 sibling: true, | 464 sibling: true, |
| 458 sibling2: true, | 465 sibling2: true, |
| 459 toHide: true | 466 toHide: true |
| 460 }; | 467 }; |
| 461 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( | 468 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 462 test, "div:-abp-has(> span:-abp-contains(Advertisment))", expectations); | 469 test, "div:-abp-has(> span:-abp-contains(Advertisment))", expectations); |
| 463 }; | 470 }; |
| 464 | 471 |
| 465 exports.testPseudoClassContains = function(test) | 472 function runTestPseudoClassContains(test, selector, expectations) |
| 466 { | 473 { |
| 467 testDocument.body.innerHTML = `<div id="parent"> | 474 testDocument.body.innerHTML = `<div id="parent"> |
| 468 <div id="middle"> | 475 <div id="middle"> |
| 469 <div id="middle1"><div id="inside" class="inside"></div></div> | 476 <div id="middle1"><div id="inside" class="inside"></div></div> |
| 470 </div> | 477 </div> |
| 471 <div id="sibling"> | 478 <div id="sibling"> |
| 472 <div id="tohide">to hide</div> | 479 <div id="tohide">to hide</div> |
| 473 </div> | 480 </div> |
| 474 <div id="sibling2"> | 481 <div id="sibling2"> |
| 475 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 482 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
| 476 </div> | 483 </div> |
| 477 </div>`; | 484 </div>`; |
| 478 let parent = testDocument.getElementById("parent"); | 485 let elems = { |
| 479 let middle = testDocument.getElementById("middle"); | 486 parent: testDocument.getElementById("parent"), |
| 480 let inside = testDocument.getElementById("inside"); | 487 middle: testDocument.getElementById("middle"), |
| 481 let sibling = testDocument.getElementById("sibling"); | 488 inside: testDocument.getElementById("inside"), |
| 482 let sibling2 = testDocument.getElementById("sibling2"); | 489 sibling: testDocument.getElementById("sibling"), |
| 483 let toHide = testDocument.getElementById("tohide"); | 490 sibling2: testDocument.getElementById("sibling2"), |
| 491 toHide: testDocument.getElementById("tohide") |
| 492 }; |
| 484 | 493 |
| 485 applyElemHideEmulation( | 494 applyElemHideEmulation( |
| 486 ["#parent div:-abp-contains(to hide)"] | 495 [selector] |
| 487 ).then(() => | 496 ).then( |
| 488 { | 497 () => compareExpectations(test, elems, expectations) |
| 489 expectVisible(test, parent); | 498 ).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 490 expectVisible(test, middle); | 499 } |
| 491 expectVisible(test, inside); | 500 |
| 492 expectHidden(test, sibling); | 501 exports.testPseudoClassContainsText = function(test) |
| 493 expectVisible(test, sibling2); | 502 { |
| 494 expectHidden(test, toHide); | 503 let expectations = { |
| 495 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 504 parent: true, |
| 505 middle: true, |
| 506 inside: true, |
| 507 sibling: false, |
| 508 sibling2: true, |
| 509 toHide: false |
| 510 }; |
| 511 runTestPseudoClassContains( |
| 512 test, "#parent div:-abp-contains(to hide)", expectations); |
| 513 }; |
| 514 |
| 515 exports.testPseudoClassContainsRegexp = function(test) |
| 516 { |
| 517 let expectations = { |
| 518 parent: true, |
| 519 middle: true, |
| 520 inside: true, |
| 521 sibling: false, |
| 522 sibling2: true, |
| 523 toHide: false |
| 524 }; |
| 525 runTestPseudoClassContains( |
| 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); |
| 496 }; | 541 }; |
| 497 | 542 |
| 498 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 543 exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
| 499 { | 544 { |
| 500 let parent = createElementWithStyle("{}"); | 545 let parent = createElementWithStyle("{}"); |
| 501 let child = createElementWithStyle("{background-color: #000}", parent); | 546 let child = createElementWithStyle("{background-color: #000}", parent); |
| 502 applyElemHideEmulation( | 547 applyElemHideEmulation( |
| 503 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 548 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
| 504 ).then(() => | 549 ).then(() => |
| 505 { | 550 { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 expectVisible(test, child2); | 653 expectVisible(test, child2); |
| 609 return timeout(REFRESH_INTERVAL); | 654 return timeout(REFRESH_INTERVAL); |
| 610 }).then(() => | 655 }).then(() => |
| 611 { | 656 { |
| 612 expectHidden(test, parent); | 657 expectHidden(test, parent); |
| 613 expectVisible(test, child); | 658 expectVisible(test, child); |
| 614 expectHidden(test, sibling); | 659 expectHidden(test, sibling); |
| 615 expectVisible(test, child2); | 660 expectVisible(test, child2); |
| 616 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 661 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 617 }; | 662 }; |
| OLD | NEW |