dmazzoni@google.com | cfbd0dd | 2012-08-15 21:31:35 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML> |
| 2 | <html> |
| 3 | <body> |
mark.lam@apple.com | a931ab2 | 2013-09-08 01:18:24 +0000 | [diff] [blame] | 4 | <script src="../resources/js-test-pre.js"></script> |
dmazzoni@google.com | cfbd0dd | 2012-08-15 21:31:35 +0000 | [diff] [blame] | 5 | |
| 6 | <div id="container" tabindex="-1"></div> |
| 7 | |
| 8 | <canvas id="canvas" tabindex="-1"></canvas> |
| 9 | |
| 10 | <div id="console"></div> |
| 11 | <script> |
| 12 | description("This test makes sure that AccessibilityNodeObjects are properly detached when the node they point to is reparented to a location that allows them to have a renderer."); |
| 13 | |
| 14 | if (window.testRunner && window.accessibilityController) { |
| 15 | window.testRunner.dumpAsText(); |
| 16 | |
| 17 | // Create an ordinary button on the page, focus it and get its accessibility role. |
| 18 | var button = document.createElement('button'); |
| 19 | document.body.appendChild(button); |
| 20 | button.focus(); |
| 21 | window.axElement = accessibilityController.focusedElement; |
| 22 | window.expectedButtonRole = axElement.role; |
| 23 | |
| 24 | // Now remove the node from the tree and get the role of the detached accessibility object. |
| 25 | document.body.removeChild(button); |
| 26 | window.expectedDetachedRole = axElement.role; |
| 27 | shouldBeTrue("expectedButtonRole != expectedDetachedRole"); |
| 28 | |
| 29 | // This time create a button that's a child of a canvas element. It will be focusable but not rendered. |
| 30 | // In particular, this will create an AccessibilityNodeObject rather than an AccessibilityRenderObject. |
| 31 | var canvas = document.getElementById('canvas'); |
| 32 | (function() { |
| 33 | var button = document.createElement('button'); |
| 34 | canvas.appendChild(button); |
| 35 | |
| 36 | // Note: focusing the button and using that to get its accessibility object creates an extra |
| 37 | // reference to the button and it won't get deleted when we want it to. So instead we focus the |
| 38 | // canvas and get its first child. |
| 39 | canvas.focus(); |
| 40 | window.axElement = accessibilityController.focusedElement.childAtIndex(0); |
| 41 | |
| 42 | window.canvasButtonRole = axElement.role; |
| 43 | shouldBe("canvasButtonRole", "expectedButtonRole"); |
| 44 | |
| 45 | // Now reparent the node to a container that's not a canvas. |
| 46 | var container = document.getElementById('container'); |
| 47 | container.appendChild(button); |
| 48 | container.focus(); |
| 49 | window.axReparentedElement = accessibilityController.focusedElement.childAtIndex(0); |
| 50 | })(); |
| 51 | |
| 52 | // Ensure that the old accessibility object is detached by checking its role. |
| 53 | window.detachedCanvasButtonRole = axElement.role; |
| 54 | shouldBe("detachedCanvasButtonRole", "expectedDetachedRole"); |
| 55 | |
| 56 | // Ensure that the new accessibility object for the now-reparented node has the correct role. |
| 57 | window.reparentedButtonRole = axReparentedElement.role; |
| 58 | shouldBe("reparentedButtonRole", "expectedButtonRole"); |
| 59 | } |
| 60 | |
| 61 | </script> |
| 62 | |
mark.lam@apple.com | a931ab2 | 2013-09-08 01:18:24 +0000 | [diff] [blame] | 63 | <script src="../resources/js-test-post.js"></script> |
dmazzoni@google.com | cfbd0dd | 2012-08-15 21:31:35 +0000 | [diff] [blame] | 64 | </body> |
| 65 | </html> |