4 <script src=
"../resources/js-test.js"></script>
6 <canvas id=
"canvas" tabindex=
"-1"></canvas>
8 <div id=
"console"></div>
10 description("This test makes sure that AccessibilityNodeObjects are properly detached when the node they point to is deleted.");
12 if (window
.testRunner
&& window
.accessibilityController
) {
13 window
.testRunner
.dumpAsText();
15 // Create an ordinary button on the page, focus it and get its accessibility role.
16 var button
= document
.createElement('button');
17 document
.body
.appendChild(button
);
19 window
.axElement
= accessibilityController
.focusedElement
;
20 window
.expectedButtonRole
= axElement
.role
;
22 // Now remove the node from the tree and get the role of the detached accessibility object.
23 document
.body
.removeChild(button
);
24 window
.expectedDetachedRole
= axElement
.role
;
25 shouldBeTrue("expectedButtonRole != expectedDetachedRole");
27 // This time create a button that's a child of a canvas element. It will be focusable but not rendered.
28 // In particular, this will create an AccessibilityNodeObject rather than an AccessibilityRenderObject.
29 var canvas
= document
.getElementById('canvas');
31 var button
= document
.createElement('button');
32 canvas
.appendChild(button
);
34 // Note: focusing the button and using that to get its accessibility object creates an extra
35 // reference to the button and it won't get deleted when we want it to. So instead we focus the
36 // canvas and get its first child.
38 window
.axElement
= accessibilityController
.focusedElement
.childAtIndex(0);
40 window
.canvasButtonRole
= axElement
.role
;
41 shouldBe("canvasButtonRole", "expectedButtonRole");
43 // Now delete the node.
44 canvas
.removeChild(button
);
47 // Explicitly run garbage collection now; since there are no more references to the button,
48 // the node will be destroyed.
51 // Ensure that the accessibility object is detached by checking its role.
52 window
.detachedCanvasButtonRole
= axElement
.role
;
53 shouldBe("detachedCanvasButtonRole", "expectedDetachedRole");