blob: d3ec2761068c688eccadfff484060f779e2c9cd5 [file] [log] [blame]
<script src="../resources/js-test.js"></script>
<div id="container" tabindex="-1"></div>
<canvas id="canvas" tabindex="-1"></canvas>
<div id="console"></div>
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.");
if (window.testRunner && window.accessibilityController) {
// Create an ordinary button on the page, focus it and get its accessibility role.
var button = document.createElement('button');
window.axElement = accessibilityController.focusedElement;
window.expectedButtonRole = axElement.role;
// Now remove the node from the tree and get the role of the detached accessibility object.
window.expectedDetachedRole = axElement.role;
shouldBeTrue("expectedButtonRole != expectedDetachedRole");
// This time create a button that's a child of a canvas element. It will be focusable but not rendered.
// In particular, this will create an AccessibilityNodeObject rather than an AccessibilityRenderObject.
var canvas = document.getElementById('canvas');
(function() {
var button = document.createElement('button');
// Note: focusing the button and using that to get its accessibility object creates an extra
// reference to the button and it won't get deleted when we want it to. So instead we focus the
// canvas and get its first child.
window.axElement = accessibilityController.focusedElement.childAtIndex(0);
window.canvasButtonRole = axElement.role;
shouldBe("canvasButtonRole", "expectedButtonRole");
// Now reparent the node to a container that's not a canvas.
var container = document.getElementById('container');
window.axReparentedElement = accessibilityController.focusedElement.childAtIndex(0);
// Ensure that the old accessibility object is detached by checking its role.
window.detachedCanvasButtonRole = axElement.role;
shouldBe("detachedCanvasButtonRole", "expectedDetachedRole");
// Ensure that the new accessibility object for the now-reparented node has the correct role.
window.reparentedButtonRole = axReparentedElement.role;
shouldBe("reparentedButtonRole", "expectedButtonRole");