gecko/accessible/tests/mochitest/test_bug420863.html

139 lines
4.4 KiB
HTML

<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=420863
-->
<head>
<title>Table indexes chrome tests</title>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript">
var gAccService = null;
var gTdClickAttr = false;
var gTdClickEventHandler = false;
var gClickHandler = null;
var gID = "";
var gNode = null;
var gAcc = null;
function doTest()
{
const nsIAccessibleRetrieval =
Components.interfaces.nsIAccessibleRetrieval;
gAccService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(nsIAccessibleRetrieval);
// Actions should be exposed on any accessible having related DOM node
// with registered 'click' event handler.
//////////////////////////////////////////////////////////////////////////
// generic td
gID = "td1";
gNode = document.getElementById(gID);
gAcc = gAccService.getAccessibleFor(gNode);
is(gAcc.numActions, 0, gID + ": shouldn't have actions");
//////////////////////////////////////////////////////////////////////////
// td with 'onclick' attribute
gID = "td2";
gNode = document.getElementById(gID);
gAcc = gAccService.getAccessibleFor(gNode);
is(gAcc.numActions, 1, gID + ": should have one action");
is(gAcc.getActionName(0), "click", gID + ": should have 'click' action");
gAcc.doAction(0);
// actions are performed via timeout
window.setTimeout(doTest2, 0);
}
function doTest2()
{
//////////////////////////////////////////////////////////////////////////
// td with 'onclick' attribute (sequel, see doTest1())
ok(gTdClickAttr, gID + ": 'click' action hasn't been performed");
//////////////////////////////////////////////////////////////////////////
// td with registered 'click' event handler
gID = "td3";
gNode = document.getElementById(gID);
gAcc = gAccService.getAccessibleFor(gNode);
// register 'click' event handler
gClickHandler = {
handleEvent: function handleEvent(aEvent)
{
gTdClickEventHandler = true;
}
};
gNode.addEventListener("click", gClickHandler, false);
// check actions
is(gAcc.numActions, 1, gID + ": should have one action");
is(gAcc.getActionName(0), "click", gID + ": should have 'click' action");
gAcc.doAction(0);
// actions are performed via timeout
window.setTimeout(doTest3, 0);
}
function doTest3()
{
//////////////////////////////////////////////////////////////////////////
// td with registered 'click' event handler (sequel, see doTest2())
ok(gTdClickEventHandler, gID + ": 'click' action hasn't been performed");
// unregister click event handler
gNode.removeEventListener("click", gClickHandler, false);
// check actions
// XXX see bug 456347, sometimes after removing the event listener, the
// accessible is no longer valid. When fixing that bug, remove the
// try/exception and simply test for the gAcc.numActions value directly.
var numActions = -1;
try {
numActions = gAcc.numActions;
} catch(e) {}
if (numActions == -1)
todo(false,
"gAcc.numActions should not throw after click handler was removed!");
else
is(numActions, 0, gID + ": shouldn't have actions");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
</script>
</head>
<body>
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=420863"
title="If an HTML element has an onClick attribute, expose its click action on the element rather than its child text leaf node."
target="_blank">Mozilla Bug 420863</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<table>
<tr>
<td id="td1">Can't click this cell</td>
<td onclick="gTdClickAttr = true;"
id="td2">Cell with 'onclick' attribute</td>
<td id="td3">Cell with registered 'click' event handler</td>
</tr>
</table>
</body>
</html>