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