OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../../../resources/js-test.js"></script> |
| 5 </head> |
| 6 <body id="body" tabindex="1"> |
| 7 <button id="focusable">Outside of inert container</button> |
| 8 <button inert id="inert">Inert button</button> |
| 9 <div inert id="container"> |
| 10 <input id="text" type="text"> |
| 11 <input id="datetime" type="datetime"> |
| 12 <input id="color" type="color"> |
| 13 <select id="select"> |
| 14 <optgroup id="optgroup"> |
| 15 <option id="option">Option</option> |
| 16 </optgroup> |
| 17 </select> |
| 18 <div id="contenteditable-div" contenteditable>I'm editable</div> |
| 19 <span id="tabindex-span" tabindex="0">I'm tabindexed.</div> |
| 20 <embed id="embed" type="application/x-blink-test-plugin" width=100 height=10
0></embed> |
| 21 <a id="anchor" href="">Link</a> |
| 22 </div> |
| 23 <script> |
| 24 description('Test that inert nodes are not focusable. The test passses if only t
he ' + |
| 25 'button outside of the inert container is focusable.'); |
| 26 |
| 27 function testFocus(element, expectFocus) { |
| 28 focusedElement = null; |
| 29 element.addEventListener('focus', function() { focusedElement = element; },
false); |
| 30 element.focus(); |
| 31 expected = expectFocus ? "true" : "false" |
| 32 theElement = element; |
| 33 shouldBe('"' + element.id + '"; focusedElement === theElement', expected); |
| 34 } |
| 35 |
| 36 function testTree(element, expectFocus, excludeCurrent) { |
| 37 if (element.nodeType == Node.ELEMENT_NODE && !excludeCurrent) |
| 38 testFocus(element, expectFocus); |
| 39 if (element.tagName === "SELECT") |
| 40 return; |
| 41 var childNodes = element.childNodes; |
| 42 for (var i = 0; i < childNodes.length; i++) |
| 43 testTree(childNodes[i], expectFocus); |
| 44 } |
| 45 |
| 46 // Normal case: focusable |
| 47 testFocus(document.getElementById('focusable'), true); |
| 48 |
| 49 // Inert directly on element: non-focusable |
| 50 testFocus(document.getElementById('inert'), false); |
| 51 |
| 52 // Inert also inherits into descendant content |
| 53 testTree(document.getElementById('container'), false); |
| 54 |
| 55 // Can get inert via property |
| 56 shouldBe('"Inert not set explicitly is false"; document.getElementById("focusabl
e").inert === false', 'true'); |
| 57 shouldBe('"Inert set explicitly is true"; document.getElementById("inert").inert
=== true', 'true'); |
| 58 shouldBe('"Inert set on container is true"; document.getElementById("container")
.inert === true', 'true'); |
| 59 |
| 60 // Elements inside of inert subtrees return false when getting 'inert' |
| 61 shouldBe('"Elements inside of inert subtrees return false when getting inert"; d
ocument.getElementById("text").inert=== false', 'true'); |
| 62 |
| 63 // Setting inert via property correctly modifies inert state |
| 64 document.getElementById('focusable').inert = true; |
| 65 testFocus(document.getElementById('focusable'), false); |
| 66 document.getElementById('inert').inert = false; |
| 67 testFocus(document.getElementById('inert'), true); |
| 68 document.getElementById('container').inert = false; |
| 69 testTree(document.getElementById('container'), true, true); |
| 70 |
| 71 </script> |
| 72 </body> |
| 73 </html> |
OLD | NEW |