2007-07-03 06:37:32 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=238987
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 238987</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=238987">Mozilla Bug 238987</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 238987 **/
|
|
|
|
|
|
|
|
var shouldStop = false;
|
|
|
|
var modifier = 0;
|
|
|
|
var expectedResult = "i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12";
|
2007-07-03 09:27:28 -07:00
|
|
|
var forwardFocusArray = expectedResult.split(",");
|
|
|
|
var backwardFocusArray = expectedResult.split(",");
|
|
|
|
var forwardBlurArray = expectedResult.split(",");
|
|
|
|
var backwardBlurArray = expectedResult.split(",");
|
|
|
|
// Adding 3 for "begin", "end", "begin" and one for the <a> in the Mochitest template,
|
|
|
|
var expectedWindowFocusCount = forwardFocusArray.length + backwardFocusArray.length + 4;
|
|
|
|
// but the last blur event goes to i1, not "begin".
|
|
|
|
var expectedWindowBlurCount = forwardFocusArray.length + backwardFocusArray.length + 3;
|
2007-07-03 06:37:32 -07:00
|
|
|
|
|
|
|
// accessibility.tabfocus must be set to value 7 before running test also
|
|
|
|
// on a mac.
|
|
|
|
function setOrRestoreTabFocus(newValue) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
const prefSvcContractID = "@mozilla.org/preferences-service;1";
|
|
|
|
const prefSvcIID = Components.interfaces.nsIPrefService;
|
|
|
|
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
|
|
|
|
.getBranch("accessibility.");
|
|
|
|
if (!newValue) {
|
2011-04-17 12:53:25 -07:00
|
|
|
prefs.clearUserPref("tabfocus");
|
2007-07-03 06:37:32 -07:00
|
|
|
} else {
|
|
|
|
prefs.setIntPref("tabfocus", newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleFocus(e) {
|
|
|
|
if (e.target.id == "begin") {
|
|
|
|
// if the modifier is set, the test is coming back from the end.
|
|
|
|
if (modifier) {
|
|
|
|
shouldStop = true;
|
|
|
|
}
|
|
|
|
} else if (e.target.id == "end") {
|
2012-08-04 00:44:00 -07:00
|
|
|
modifier = Components.interfaces.nsIDOMEvent.SHIFT_MASK;
|
2007-07-03 06:37:32 -07:00
|
|
|
} else if (modifier) {
|
2007-07-03 09:27:28 -07:00
|
|
|
var expected = backwardFocusArray.pop();
|
2007-07-03 06:37:32 -07:00
|
|
|
ok(expected == e.target.id,
|
2007-07-03 09:27:28 -07:00
|
|
|
"(focus) Backward tabbing, expected [" +
|
|
|
|
expected + "], got [" + e.target.id + "]");
|
2007-07-03 06:37:32 -07:00
|
|
|
} else {
|
2007-07-03 09:27:28 -07:00
|
|
|
var expected = forwardFocusArray.shift();
|
2012-05-04 07:41:49 -07:00
|
|
|
is(e.target, document.activeElement, "Wrong activeElement!");
|
2007-07-03 06:37:32 -07:00
|
|
|
ok(expected == e.target.id,
|
2007-07-03 09:27:28 -07:00
|
|
|
"(focus) Forward tabbing, expected [" +
|
|
|
|
expected + "], got [" + e.target.id + "]");
|
2007-07-03 06:37:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleWindowFocus(e) {
|
|
|
|
--expectedWindowFocusCount;
|
|
|
|
var s = "target " + e.target;
|
|
|
|
if ("id" in e.target) {
|
|
|
|
s = s + ", id=\"" + e.target.id + "\"";
|
|
|
|
}
|
|
|
|
ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
|
2007-07-03 09:27:28 -07:00
|
|
|
"|window| should not have got a focus event, " + s);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleBlur(e) {
|
|
|
|
if (e.target.id == "begin" || e.target.id == "end") {
|
|
|
|
return;
|
|
|
|
} else if (modifier) {
|
|
|
|
var expected = backwardBlurArray.pop();
|
|
|
|
ok(expected == e.target.id,
|
|
|
|
"(blur) backward tabbing, expected [" +
|
|
|
|
expected + "], got [" + e.target.id + "]");
|
|
|
|
} else {
|
|
|
|
var expected = forwardBlurArray.shift();
|
|
|
|
ok(expected == e.target.id,
|
|
|
|
"(blur) forward tabbing, expected [" +
|
|
|
|
expected + "], got [" + e.target.id + "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleWindowBlur(e) {
|
|
|
|
--expectedWindowBlurCount;
|
|
|
|
var s = "target " + e.target;
|
|
|
|
if ("id" in e.target) {
|
|
|
|
s = s + ", id=\"" + e.target.id + "\"";
|
|
|
|
}
|
|
|
|
ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
|
|
|
|
"|window| should not have got a blur event, " + s);
|
2007-07-03 06:37:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function tab() {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
|
|
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
|
|
|
// Send tab key events.
|
|
|
|
var key = Components.interfaces.nsIDOMKeyEvent.DOM_VK_TAB;
|
|
|
|
utils.sendKeyEvent("keydown", key, 0, modifier);
|
|
|
|
utils.sendKeyEvent("keypress", key, 0, modifier);
|
|
|
|
utils.sendKeyEvent("keyup", key, 0, modifier);
|
|
|
|
if (shouldStop) {
|
2007-07-03 09:27:28 -07:00
|
|
|
// Did focus handling succeed
|
2008-12-16 23:33:33 -08:00
|
|
|
is(forwardFocusArray.length, 0,
|
2007-07-03 09:27:28 -07:00
|
|
|
"Not all forward tabbing focus tests were run, " +
|
|
|
|
forwardFocusArray.toString());
|
2008-12-16 23:33:33 -08:00
|
|
|
is(backwardFocusArray.length, 0,
|
2007-07-03 09:27:28 -07:00
|
|
|
"Not all backward tabbing focus tests were run, " +
|
|
|
|
backwardFocusArray.toString());
|
2008-12-16 23:33:33 -08:00
|
|
|
is(expectedWindowFocusCount, 0,
|
2007-07-03 09:27:28 -07:00
|
|
|
"|window| didn't get the right amount of focus events");
|
|
|
|
|
|
|
|
// and blur.
|
2008-12-16 23:33:33 -08:00
|
|
|
is(forwardBlurArray.length, 0,
|
2007-07-03 09:27:28 -07:00
|
|
|
"Not all forward tabbing blur tests were run, " +
|
|
|
|
forwardBlurArray.toString());
|
2008-12-16 23:33:33 -08:00
|
|
|
is(backwardBlurArray.length, 0,
|
2007-07-03 09:27:28 -07:00
|
|
|
"Not all backward tabbing blur tests were run, " +
|
|
|
|
backwardBlurArray.toString());
|
2008-12-16 23:33:33 -08:00
|
|
|
is(expectedWindowBlurCount, 0,
|
2007-07-03 09:27:28 -07:00
|
|
|
"|window| didn't get the right amount of blur events");
|
2012-06-01 11:52:37 -07:00
|
|
|
|
|
|
|
// Cleanup
|
2007-07-03 06:37:32 -07:00
|
|
|
setOrRestoreTabFocus(0);
|
2012-06-01 11:52:37 -07:00
|
|
|
window.removeEventListener("focus", handleWindowFocus, true);
|
|
|
|
window.removeEventListener("focus", handleWindowFocus, false);
|
|
|
|
window.removeEventListener("blur", handleWindowBlur, true);
|
|
|
|
window.removeEventListener("blur", handleWindowBlur, false);
|
|
|
|
var elements = document.getElementsByTagName("*");
|
|
|
|
for (var i = 0; i < elements.length; ++i) {
|
|
|
|
if (elements[i].hasAttribute("id")) {
|
|
|
|
elements[i].removeEventListener("focus", handleFocus, false);
|
|
|
|
elements[i].removeEventListener("blur", handleBlur, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-03 06:37:32 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
} else {
|
2011-04-20 02:46:32 -07:00
|
|
|
setTimeout(tab, 0);
|
2007-07-03 06:37:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function start() {
|
|
|
|
window.focus();
|
|
|
|
window.addEventListener("focus", handleWindowFocus, true);
|
|
|
|
window.addEventListener("focus", handleWindowFocus, false);
|
2007-07-03 09:27:28 -07:00
|
|
|
window.addEventListener("blur", handleWindowBlur, true);
|
|
|
|
window.addEventListener("blur", handleWindowBlur, false);
|
2007-07-03 06:37:32 -07:00
|
|
|
var elements = document.getElementsByTagName("*");
|
|
|
|
for (var i = 0; i < elements.length; ++i) {
|
|
|
|
if (elements[i].hasAttribute("id")) {
|
|
|
|
elements[i].addEventListener("focus", handleFocus, false);
|
2007-07-03 09:27:28 -07:00
|
|
|
elements[i].addEventListener("blur", handleBlur, false);
|
2007-07-03 06:37:32 -07:00
|
|
|
}
|
2008-12-16 23:33:33 -08:00
|
|
|
if (elements[i].getAttribute("tabindex") == "1") {
|
|
|
|
elements[i].setAttribute("tabindex", "-1");
|
|
|
|
}
|
2007-07-03 06:37:32 -07:00
|
|
|
}
|
|
|
|
tab();
|
|
|
|
}
|
|
|
|
|
|
|
|
function doTest() {
|
2007-07-03 09:27:28 -07:00
|
|
|
setOrRestoreTabFocus(7);
|
2011-04-20 02:46:32 -07:00
|
|
|
setTimeout(start, 0);
|
2007-07-03 06:37:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
addLoadEvent(doTest);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
<h4 tabindex="0" id="begin">Test:</h4>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>type="text"</td><td><input type="text" id="i1" value=""></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="button"</td><td><input type="button" id="i2" value="type='button'"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="checkbox"</td><td><input type="checkbox" id="i3" ></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="radio" checked</td><td><input type="radio" id="i4" name="radio" checked>
|
|
|
|
<input type="radio" id="i4b" name="radio"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="radio"</td><td><input type="radio" id="i5" name="radio2">
|
|
|
|
<input type="radio" id="i6" name="radio2"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="password"</td><td><input type="password" id="i7"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="file"</td><td><input type="file" id="i8"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>button</td><td><button id="i9">button</button></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>select</td><td><select id="i10"><option>select</option></select></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>a</td><td><a href="#radio" id="i11">a link</a></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>tabindex="0"</td><td><span tabindex="0" id="i12">span</span></td>
|
|
|
|
</tr>
|
2008-12-16 23:33:33 -08:00
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td><h3>Form elements with tabindex="-1"</h3></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="text"</td><td><input type="text" tabindex="-1" value=""></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="button"</td><td><input type="button" tabindex="-1" value="type='button'"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="checkbox"</td><td><input type="checkbox" tabindex="-1"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="radio" checked</td><td><input type="radio" tabindex="-1" name="radio3" checked>
|
|
|
|
<input type="radio" tabindex="-1" name="radio3"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="radio"</td><td><input type="radio" tabindex="-1" name="radio4">
|
|
|
|
<input type="radio" tabindex="-1" name="radio4"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="password"</td><td><input type="password" tabindex="-1"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="file"</td><td><input type="file" tabindex="-1"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>button</td><td><button tabindex="-1">button</button></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>select</td><td><select tabindex="-1"><option>select</option></select></td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
<td><h3>Form elements with .setAttribute("tabindex", "-1")</h3></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="text"</td><td><input type="text" tabindex="1" value=""></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="button"</td><td><input type="button" tabindex="1" value="type='button'"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="checkbox"</td><td><input type="checkbox" tabindex="1"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="radio" checked</td><td><input type="radio" tabindex="1" name="radio5" checked>
|
|
|
|
<input type="radio" tabindex="1" name="radio5"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="radio"</td><td><input type="radio" tabindex="1" name="radio6">
|
|
|
|
<input type="radio" tabindex="1" name="radio6"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="password"</td><td><input type="password" tabindex="1"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>type="file"</td><td><input type="file" tabindex="1"></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>button</td><td><button tabindex="1">button</button></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>select</td><td><select tabindex="1"><option>select</option></select></td>
|
|
|
|
</tr>
|
|
|
|
|
2007-07-03 06:37:32 -07:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<h4 tabindex="0" id="end">done.</h4>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|