Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/browser/elemHideEmulation.js

Issue 29493648: Issue 5436 - Allow relative selectors in :-abp-has() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Remove unecessary changes Created Aug. 14, 2017, 2:30 p.m.
Right Patch Set: Updated with review feedback Created Aug. 16, 2017, 3:30 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « chrome/content/elemHideEmulation.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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 , expectation) 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 elems = {}; 383 let elems = {
384 elems.parent = document.getElementById("parent"); 384 parent: document.getElementById("parent"),
385 elems.middle = document.getElementById("middle"); 385 middle: document.getElementById("middle"),
386 elems.inside = document.getElementById("inside"); 386 inside: document.getElementById("inside"),
387 elems.sibling = document.getElementById("sibling"); 387 sibling: document.getElementById("sibling"),
388 elems.sibling2 = document.getElementById("sibling2"); 388 sibling2: document.getElementById("sibling2"),
389 elems.toHide = document.getElementById("tohide"); 389 toHide: document.getElementById("tohide")
Wladimir Palant 2017/08/16 08:17:16 Please assign a proper object literal: let elem
hub 2017/08/16 15:30:46 Done.
390 };
390 391
391 insertStyleRule(".inside {}"); 392 insertStyleRule(".inside {}");
392 393
393 applyElemHideEmulation( 394 applyElemHideEmulation(
394 [selector] 395 [selector]
395 ).then(() => 396 ).then(() =>
396 { 397 {
397 if (typeof expectation == "function") 398 for (let elem in expectations)
398 return expectation(elems); 399 if (elems[elem])
Wladimir Palant 2017/08/16 08:17:15 Handling the expectations here for two scenarios b
hub 2017/08/16 15:30:45 Done.
399 400 {
400 expectVisible(test, elems.parent); 401 if (expectations[elem])
401 expectVisible(test, elems.middle); 402 expectVisible(test, elems[elem]);
402 expectVisible(test, elems.inside); 403 else
403 expectVisible(test, elems.sibling); 404 expectHidden(test, elems[elem]);
404 expectVisible(test, elems.sibling2); 405 }
405 expectHidden(test, elems.toHide);
406 }).catch(unexpectedError.bind(test)).then(() => test.done()); 406 }).catch(unexpectedError.bind(test)).then(() => test.done());
407 } 407 }
408 408
409 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) 409 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test)
410 { 410 {
411 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);
412 }; 421 };
413 422
414 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) 423 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test)
415 { 424 {
425 let expectations = {
426 parent: true,
427 middile: true,
428 inside: true,
429 sibling: true,
430 sibling2: true,
431 toHide: false
432 };
416 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 433 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
417 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div"); 434 test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations);
418 }; 435 };
419 436
420 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test) 437 exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test)
421 { 438 {
439 let expectations = {
440 parent: true,
441 middile: true,
442 inside: true,
443 sibling: true,
444 sibling2: true,
445 toHide: true
446 };
422 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( 447 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
423 test, "div:-abp-has(> body div.inside) + div > div", (elems) => 448 test, "div:-abp-has(> body div.inside) + div > div", expectations);
424 {
425 expectVisible(test, elems.parent);
426 expectVisible(test, elems.middle);
427 expectVisible(test, elems.inside);
428 expectVisible(test, elems.sibling);
429 expectVisible(test, elems.sibling2);
430 expectVisible(test, elems.toHide);
431 });
432 }; 449 };
433 450
434 exports.testPseudoClassContains = function(test) 451 exports.testPseudoClassContains = function(test)
435 { 452 {
436 document.body.innerHTML = `<div id="parent"> 453 document.body.innerHTML = `<div id="parent">
437 <div id="middle"> 454 <div id="middle">
438 <div id="middle1"><div id="inside" class="inside"></div></div> 455 <div id="middle1"><div id="inside" class="inside"></div></div>
439 </div> 456 </div>
440 <div id="sibling"> 457 <div id="sibling">
441 <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
483 let child = createElementWithStyle("{}", parent); 500 let child = createElementWithStyle("{}", parent);
484 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); 501 insertStyleRule("body #" + parent.id + " > div { background-color: #000}");
485 applyElemHideEmulation( 502 applyElemHideEmulation(
486 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 503 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
487 ).then(() => 504 ).then(() =>
488 { 505 {
489 expectVisible(test, child); 506 expectVisible(test, child);
490 expectHidden(test, parent); 507 expectHidden(test, parent);
491 }).catch(unexpectedError.bind(test)).then(() => test.done()); 508 }).catch(unexpectedError.bind(test)).then(() => test.done());
492 }; 509 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld