forked from rnewman/services-central-old
/
test_bug420863.html
138 lines (112 loc) · 4.54 KB
/
test_bug420863.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!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>