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