| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../../resources/js-test.js"></script> | |
| 3 <style> | |
| 4 div#host:focus { display: none; } | |
| 5 </style> | |
| 6 <div id="sandbox"></div> | |
| 7 <div id="host"></div> | |
| 8 <script> | |
| 9 description('Check if shadow host with display:none CSS rule for :focus works.
crbug.com/482830'); | |
| 10 | |
| 11 var host; | |
| 12 var root; | |
| 13 var input; | |
| 14 | |
| 15 function setupShadowDOM(delegatesFocus) { | |
| 16 sandbox.innerHTML = ''; | |
| 17 host = sandbox.appendChild(document.createElement('div')); | |
| 18 host.id = 'host'; | |
| 19 | |
| 20 root = host.attachShadow({ 'mode': 'open', 'delegatesFocus': delegatesFocus
}); | |
| 21 input = document.createElement('input'); | |
| 22 root.appendChild(input); | |
| 23 | |
| 24 host.tabIndex = 0; | |
| 25 } | |
| 26 | |
| 27 function testFocusShadowHost() { | |
| 28 debug('when shadow host itself is focused, it should match display:none, los
e focus then becomes display:block again.'); | |
| 29 setupShadowDOM(false); | |
| 30 return new Promise( | |
| 31 function(resolve) { | |
| 32 host.focus(); | |
| 33 shouldBeEqualToString('window.getComputedStyle(host).display', 'none
'); | |
| 34 shouldBe('document.activeElement', 'host'); | |
| 35 shouldBeNull('root.activeElement'); | |
| 36 | |
| 37 function onBlur() { | |
| 38 shouldBeEqualToString('window.getComputedStyle(host).display', '
block'); | |
| 39 shouldBe('document.activeElement', 'document.body'); | |
| 40 shouldBeNull('root.activeElement'); | |
| 41 host.removeEventListener('blur', onBlur); | |
| 42 resolve(); | |
| 43 } | |
| 44 host.addEventListener('blur', onBlur); | |
| 45 }); | |
| 46 } | |
| 47 | |
| 48 function testFocusInsideShadowRoot() { | |
| 49 debug('when shadow host with delegatesFocus=true has focused element inside
the shadow, it should also match display:none, then lose focus and become displa
y:block again.'); | |
| 50 setupShadowDOM(true); | |
| 51 return new Promise( | |
| 52 function(resolve) { | |
| 53 input.focus(); | |
| 54 shouldBeEqualToString('window.getComputedStyle(host).display', 'none
'); | |
| 55 shouldBe('document.activeElement', 'host'); | |
| 56 shouldBe('root.activeElement', 'input'); | |
| 57 | |
| 58 function onBlur() { | |
| 59 shouldBeEqualToString('window.getComputedStyle(host).display', '
block'); | |
| 60 shouldBe('document.activeElement', 'document.body'); | |
| 61 shouldBeNull('root.activeElement'); | |
| 62 input.removeEventListener('blur', onBlur); | |
| 63 resolve(); | |
| 64 } | |
| 65 input.addEventListener('blur', onBlur); | |
| 66 }); | |
| 67 } | |
| 68 | |
| 69 if (window.testRunner) { | |
| 70 testFocusShadowHost().then(testFocusInsideShadowRoot).then(function(){ testR
unner.notifyDone(); }); | |
| 71 testRunner.waitUntilDone(); | |
| 72 } | |
| 73 </script> | |
| OLD | NEW |