Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / accessibility / accessibility-node-memory-management.html
blobd8462d3251d9b594f2acbfe85b89ad20c282b366
1 <!DOCTYPE HTML>
2 <html>
3 <body>
4 <script src="../resources/js-test.js"></script>
6 <canvas id="canvas" tabindex="-1"></canvas>
8 <div id="console"></div>
9 <script>
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);
18 button.focus();
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');
30 (function() {
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.
37 canvas.focus();
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);
45 })();
47 // Explicitly run garbage collection now; since there are no more references to the button,
48 // the node will be destroyed.
49 gc();
51 // Ensure that the accessibility object is detached by checking its role.
52 window.detachedCanvasButtonRole = axElement.role;
53 shouldBe("detachedCanvasButtonRole", "expectedDetachedRole");
56 </script>
58 </body>
59 </html>