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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 ["div:-abp-has(div) + div > div"] | 360 ["div:-abp-has(div) + div > div"] |
361 ).then(() => | 361 ).then(() => |
362 { | 362 { |
363 expectVisible(test, parent); | 363 expectVisible(test, parent); |
364 expectVisible(test, middle); | 364 expectVisible(test, middle); |
365 expectVisible(test, sibling); | 365 expectVisible(test, sibling); |
366 expectHidden(test, toHide); | 366 expectHidden(test, toHide); |
367 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 367 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
368 }; | 368 }; |
369 | 369 |
370 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
) | 370 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
, expectations) |
371 { | 371 { |
372 document.body.innerHTML = `<div id="parent"> | 372 document.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">to hide</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 parent = document.getElementById("parent"); | 383 let elems = { |
384 let middle = document.getElementById("middle"); | 384 parent: document.getElementById("parent"), |
385 let inside = document.getElementById("inside"); | 385 middle: document.getElementById("middle"), |
386 let sibling = document.getElementById("sibling"); | 386 inside: document.getElementById("inside"), |
387 let sibling2 = document.getElementById("sibling2"); | 387 sibling: document.getElementById("sibling"), |
388 let toHide = document.getElementById("tohide"); | 388 sibling2: document.getElementById("sibling2"), |
| 389 toHide: document.getElementById("tohide") |
| 390 }; |
389 | 391 |
390 insertStyleRule(".inside {}"); | 392 insertStyleRule(".inside {}"); |
391 | 393 |
392 applyElemHideEmulation( | 394 applyElemHideEmulation( |
393 [selector] | 395 [selector] |
394 ).then(() => | 396 ).then(() => |
395 { | 397 { |
396 expectVisible(test, parent); | 398 for (let elem in expectations) |
397 expectVisible(test, middle); | 399 if (elems[elem]) |
398 expectVisible(test, inside); | 400 { |
399 expectVisible(test, sibling); | 401 if (expectations[elem]) |
400 expectVisible(test, sibling2); | 402 expectVisible(test, elems[elem]); |
401 expectHidden(test, toHide); | 403 else |
| 404 expectHidden(test, elems[elem]); |
| 405 } |
402 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 406 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
403 } | 407 } |
404 | 408 |
405 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) | 409 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) |
406 { | 410 { |
407 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(:
-abp-has(div.inside)) + div > div"); | 411 let expectations = { |
| 412 parent: true, |
| 413 middile: true, |
| 414 inside: true, |
| 415 sibling: true, |
| 416 sibling2: true, |
| 417 toHide: false |
| 418 }; |
| 419 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 420 test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations); |
| 421 }; |
| 422 |
| 423 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) |
| 424 { |
| 425 let expectations = { |
| 426 parent: true, |
| 427 middile: true, |
| 428 inside: true, |
| 429 sibling: true, |
| 430 sibling2: true, |
| 431 toHide: false |
| 432 }; |
| 433 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 434 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); |
| 435 }; |
| 436 |
| 437 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test) |
| 438 { |
| 439 let expectations = { |
| 440 parent: true, |
| 441 middile: true, |
| 442 inside: true, |
| 443 sibling: true, |
| 444 sibling2: true, |
| 445 toHide: true |
| 446 }; |
| 447 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
| 448 test, "div:-abp-has(> body div.inside) + div > div", expectations); |
408 }; | 449 }; |
409 | 450 |
410 exports.testPseudoClassContains = function(test) | 451 exports.testPseudoClassContains = function(test) |
411 { | 452 { |
412 document.body.innerHTML = `<div id="parent"> | 453 document.body.innerHTML = `<div id="parent"> |
413 <div id="middle"> | 454 <div id="middle"> |
414 <div id="middle1"><div id="inside" class="inside"></div></div> | 455 <div id="middle1"><div id="inside" class="inside"></div></div> |
415 </div> | 456 </div> |
416 <div id="sibling"> | 457 <div id="sibling"> |
417 <div id="tohide">to hide</div> | 458 <div id="tohide">to hide</div> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 let child = createElementWithStyle("{}", parent); | 500 let child = createElementWithStyle("{}", parent); |
460 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); | 501 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
461 applyElemHideEmulation( | 502 applyElemHideEmulation( |
462 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 503 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
463 ).then(() => | 504 ).then(() => |
464 { | 505 { |
465 expectVisible(test, child); | 506 expectVisible(test, child); |
466 expectHidden(test, parent); | 507 expectHidden(test, parent); |
467 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 508 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
468 }; | 509 }; |
OLD | NEW |