| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../../resources/js-test.js"></script> | |
| 3 <script src="resources/shadow-dom.js"></script> | |
| 4 <style> | |
| 5 div { | |
| 6 background-color: white; | |
| 7 } | |
| 8 | |
| 9 div#shadow-host:focus { | |
| 10 background-color: green; | |
| 11 } | |
| 12 </style> | |
| 13 <body> | |
| 14 <div id="sandbox"></div> | |
| 15 </body> | |
| 16 <script> | |
| 17 function buildSingleShadowTree(delegatesFocus) { | |
| 18 var sandbox = document.querySelector('#sandbox'); | |
| 19 sandbox.innerHTML = ''; | |
| 20 sandbox.appendChild( | |
| 21 createDOM('div', {}, | |
| 22 createDOM('input', {'id': 'outer-input'}), | |
| 23 createDOM('div', {'id': 'shadow-host'}, | |
| 24 createDOM('input', {'id': 'lightdom-input'}), | |
| 25 attachShadow( | |
| 26 {'mode': 'open', 'delegatesFocus': delegatesFocus}, | |
| 27 createDOM('slot'), | |
| 28 createDOM('input', {'id': 'inner-input'}))))); | |
| 29 | |
| 30 sandbox.offsetTop; | |
| 31 } | |
| 32 | |
| 33 function testSingleShadow() { | |
| 34 debug('(1/6) Testing how :focus matches on shadow host with delegatesFocus=f
alse.'); | |
| 35 buildSingleShadowTree(false); | |
| 36 | |
| 37 var host = document.querySelector('#shadow-host'); | |
| 38 var lightdomInput = document.querySelector('#lightdom-input'); | |
| 39 var innerInput = getNodeInComposedTree('shadow-host/inner-input'); | |
| 40 var outerInput = document.querySelector('#outer-input'); | |
| 41 | |
| 42 outerInput.focus(); | |
| 43 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 44 lightdomInput.focus(); | |
| 45 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 46 innerInput.focus(); | |
| 47 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 48 host.focus(); // host will not get focus as it is not focusable. | |
| 49 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 50 | |
| 51 debug('(2/6) Testing how :focus matches on shadow host with tabindex=-1, del
egatesFocus=false.'); | |
| 52 host.tabIndex = -1; | |
| 53 outerInput.focus(); | |
| 54 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 55 lightdomInput.focus(); | |
| 56 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 57 innerInput.focus(); | |
| 58 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 59 host.focus(); | |
| 60 backgroundColorShouldBe('shadow-host', 'rgb(0, 128, 0)'); | |
| 61 | |
| 62 debug('(3/6) Testing how :focus matches on shadow host with tabindex=0, dele
gatesFocus=false.'); | |
| 63 host.tabIndex = 0; | |
| 64 outerInput.focus(); | |
| 65 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 66 lightdomInput.focus(); | |
| 67 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 68 innerInput.focus(); | |
| 69 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 70 host.focus(); | |
| 71 backgroundColorShouldBe('shadow-host', 'rgb(0, 128, 0)'); | |
| 72 | |
| 73 | |
| 74 debug('(4/6) Testing how :focus matches on shadow host with delegatesFocus=t
rue.'); | |
| 75 buildSingleShadowTree(true); | |
| 76 | |
| 77 var host = document.querySelector('#shadow-host'); | |
| 78 var lightdomInput = document.querySelector('#lightdom-input'); | |
| 79 var innerInput = getNodeInComposedTree('shadow-host/inner-input'); | |
| 80 var outerInput = document.querySelector('#outer-input'); | |
| 81 | |
| 82 outerInput.focus(); | |
| 83 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 84 lightdomInput.focus(); | |
| 85 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 86 innerInput.focus(); | |
| 87 backgroundColorShouldBe('shadow-host', 'rgb(0, 128, 0)'); | |
| 88 host.focus(); | |
| 89 backgroundColorShouldBe('shadow-host', 'rgb(0, 128, 0)'); | |
| 90 | |
| 91 debug('(5/6) Testing how :focus matches on shadow host with tabindex=-1, del
egatesFocus=true.'); | |
| 92 host.tabIndex = -1; | |
| 93 outerInput.focus(); | |
| 94 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 95 lightdomInput.focus(); | |
| 96 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 97 innerInput.focus(); | |
| 98 backgroundColorShouldBe('shadow-host', 'rgb(0, 128, 0)'); | |
| 99 host.focus(); | |
| 100 backgroundColorShouldBe('shadow-host', 'rgb(0, 128, 0)'); | |
| 101 | |
| 102 debug('(6/6) Testing how :focus matches on shadow host with tabindex=0, dele
gatesFocus=true.'); | |
| 103 host.tabIndex = 0; | |
| 104 outerInput.focus(); | |
| 105 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 106 lightdomInput.focus(); | |
| 107 backgroundColorShouldBe('shadow-host', 'rgb(255, 255, 255)'); | |
| 108 innerInput.focus(); | |
| 109 backgroundColorShouldBe('shadow-host', 'rgb(0, 128, 0)'); | |
| 110 host.focus(); | |
| 111 backgroundColorShouldBe('shadow-host', 'rgb(0, 128, 0)'); | |
| 112 } | |
| 113 | |
| 114 testSingleShadow(); | |
| 115 </script> | |
| OLD | NEW |