4 <script src=
"../resources/js-test.js"></script>
6 <div id=
"container" tabindex=
"-1"></div>
8 <canvas id=
"canvas" tabindex=
"-1"></canvas>
10 <div id=
"console"></div>
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.");
14 if (window
.testRunner
&& window
.accessibilityController
) {
15 window
.testRunner
.dumpAsText();
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
);
21 window
.axElement
= accessibilityController
.focusedElement
;
22 window
.expectedButtonRole
= axElement
.role
;
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");
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');
33 var button
= document
.createElement('button');
34 canvas
.appendChild(button
);
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.
40 window
.axElement
= accessibilityController
.focusedElement
.childAtIndex(0);
42 window
.canvasButtonRole
= axElement
.role
;
43 shouldBe("canvasButtonRole", "expectedButtonRole");
45 // Now reparent the node to a container that's not a canvas.
46 var container
= document
.getElementById('container');
47 container
.appendChild(button
);
49 window
.axReparentedElement
= accessibilityController
.focusedElement
.childAtIndex(0);
52 // Ensure that the old accessibility object is detached by checking its role.
53 window
.detachedCanvasButtonRole
= axElement
.role
;
54 shouldBe("detachedCanvasButtonRole", "expectedDetachedRole");
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");