2010-04-21 07:53:42 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
2010-12-16 18:22:28 -08:00
|
|
|
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
|
2010-04-21 07:53:42 -07:00
|
|
|
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
|
|
|
|
|
|
<script type="application/javascript"
|
2010-08-24 10:29:34 -07:00
|
|
|
src="/tests/SimpleTest/SimpleTest.js"></script>
|
2010-04-21 07:53:42 -07:00
|
|
|
<script type="application/javascript"
|
2010-08-24 10:29:34 -07:00
|
|
|
src="/tests/SimpleTest/EventUtils.js"></script>
|
2010-06-21 05:37:34 -07:00
|
|
|
<script type="application/javascript"
|
2010-08-24 10:29:34 -07:00
|
|
|
src="/tests/SimpleTest/WindowSnapshot.js"></script>
|
2010-04-21 07:53:42 -07:00
|
|
|
|
|
|
|
<html:style xmlns:html="http://www.w3.org/1999/xhtml" type="text/css">
|
|
|
|
* { outline: none; }
|
|
|
|
#l1:-moz-focusring, #l3:-moz-focusring, #b1:-moz-focusring { outline: 2px solid red; }
|
|
|
|
#l2:focus, #b2:focus { outline: 2px solid red; }
|
|
|
|
</html:style>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<![CDATA[
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2010-06-21 05:37:34 -07:00
|
|
|
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) {
|
|
|
|
if (prefs.prefHasUserValue("tabfocus")) {
|
|
|
|
prefs.clearUserPref("tabfocus");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
prefs.setIntPref("tabfocus", newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function snapShot(element) {
|
|
|
|
var rect = element.getBoundingClientRect();
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
|
|
|
|
var canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
|
|
|
canvas.setAttribute("width", rect.width + 12);
|
|
|
|
canvas.setAttribute("height", rect.height + 12);
|
|
|
|
var ctx = canvas.getContext("2d");
|
|
|
|
ctx.drawWindow(window, rect.left - 6, rect.top - 6, rect.width + 6, rect.height + 6,
|
|
|
|
"transparent");
|
|
|
|
return canvas;
|
|
|
|
}
|
|
|
|
|
2010-04-21 07:53:42 -07:00
|
|
|
function runTest()
|
|
|
|
{
|
2010-06-21 05:37:34 -07:00
|
|
|
setOrRestoreTabFocus(7);
|
|
|
|
|
2010-04-21 07:53:42 -07:00
|
|
|
var isMac = (navigator.platform.indexOf("Mac") >= 0);
|
|
|
|
var isWin = (navigator.platform.indexOf("Win") >= 0);
|
|
|
|
|
|
|
|
function checkFocus(element, visible, testid)
|
|
|
|
{
|
|
|
|
var outline = getComputedStyle(element, "").outlineWidth;
|
|
|
|
is(outline, visible ? "2px" : "0px", testid);
|
|
|
|
}
|
|
|
|
|
2010-06-21 05:37:34 -07:00
|
|
|
// make sure that a focus ring appears on the focused button
|
|
|
|
if (navigator.platform.indexOf("Mac") >= 0) {
|
|
|
|
var focusedButton = $("b3");
|
|
|
|
ok(compareSnapshots(snapShot(focusedButton), snapShot($("b2")), true)[0], "unfocused shows no ring");
|
|
|
|
focusedButton.focus();
|
|
|
|
ok(compareSnapshots(snapShot(focusedButton), snapShot($("b2")), false)[0], "focus shows ring");
|
|
|
|
}
|
2010-04-21 07:53:42 -07:00
|
|
|
|
2010-06-21 05:37:34 -07:00
|
|
|
checkFocus($("l1"), false, "initial appearance");
|
2010-04-21 07:53:42 -07:00
|
|
|
|
|
|
|
// we can't really test the situation on Windows where a dialog doesn't show
|
|
|
|
// focus rings until a key is pressed, as the default state depends on what
|
|
|
|
// kind of real user input, mouse or key, was last entered. But we can handle
|
2010-06-21 05:37:34 -07:00
|
|
|
// the test regardless of which user input last occurred.
|
|
|
|
$("l1").focus();
|
2010-04-21 07:53:42 -07:00
|
|
|
var expectedVisible = (!isWin || getComputedStyle($("l1"), "").outlineWidth == "2px");
|
2010-08-09 09:15:47 -07:00
|
|
|
testHTMLElements(htmlElements, isMac, isWin && !expectedVisible);
|
|
|
|
|
|
|
|
if (isMac) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
prefs.setBoolPref("accessibility.mouse_focuses_formcontrol", true);
|
|
|
|
|
|
|
|
testHTMLElements(htmlElementsMacPrefSet, true, false);
|
|
|
|
|
|
|
|
prefs.setBoolPref("accessibility.mouse_focuses_formcontrol", false);
|
|
|
|
}
|
2010-04-21 07:53:42 -07:00
|
|
|
|
2010-06-21 05:37:34 -07:00
|
|
|
$("l1").focus();
|
|
|
|
checkFocus($("l1"), expectedVisible, "appearance on list after focus() with :moz-focusring");
|
2010-04-21 07:53:42 -07:00
|
|
|
$("l2").focus();
|
|
|
|
|
|
|
|
checkFocus($("l2"), true, "appearance on list after focus() with :focus");
|
|
|
|
|
|
|
|
is(getComputedStyle($("l1"), "").outlineWidth, "0px", "appearance on previous list after focus() with :focus");
|
|
|
|
|
|
|
|
synthesizeMouse($("l1"), 4, 4, { });
|
2010-06-21 05:37:34 -07:00
|
|
|
checkFocus($("l1"), expectedVisible, "appearance on list after mouse focus with :moz-focusring");
|
2010-04-21 07:53:42 -07:00
|
|
|
synthesizeMouse($("l2"), 4, 4, { });
|
|
|
|
checkFocus($("l2"), true, "appearance on list after mouse focus with :focus");
|
|
|
|
|
|
|
|
synthesizeMouse($("b1"), 4, 4, { });
|
|
|
|
checkFocus($("b1"), !isMac && expectedVisible, "appearance on button after mouse focus with :moz-focusring");
|
2010-06-21 05:37:34 -07:00
|
|
|
if (navigator.platform.indexOf("Mac") >= 0) {
|
|
|
|
ok(compareSnapshots(snapShot($("b1")), snapShot($("b2")), false)[0], "focus after mouse shows no ring");
|
|
|
|
}
|
2010-04-21 07:53:42 -07:00
|
|
|
|
|
|
|
synthesizeMouse($("b2"), 4, 4, { });
|
|
|
|
checkFocus($("b2"), !isMac, "appearance on button after mouse focus with :focus");
|
|
|
|
|
|
|
|
// after a key is pressed, the focus ring will always be visible
|
|
|
|
$("l2").focus();
|
|
|
|
synthesizeKey("VK_TAB", { });
|
|
|
|
checkFocus($("l3"), true, "appearance on list after tab focus");
|
|
|
|
|
2010-06-21 05:37:34 -07:00
|
|
|
setOrRestoreTabFocus(0);
|
2010-04-21 07:53:42 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
2010-06-21 05:37:34 -07:00
|
|
|
var htmlElements = [
|
|
|
|
"<button id='elem'>Button</button>",
|
|
|
|
"<input id='elem' class='canfocus'>",
|
|
|
|
"<input id='elem' type='password' class='canfocus'>",
|
|
|
|
"<input id='elem' type='button'>",
|
2010-08-09 09:15:47 -07:00
|
|
|
"<input id='elem' type='checkbox'>",
|
2010-06-21 05:37:34 -07:00
|
|
|
"<textarea id='elem' class='canfocus'></textarea>",
|
|
|
|
"<select id='elem' class='canfocus'><option>One</select>",
|
|
|
|
"<select id='elem' rows='5' class='canfocus'><option>One</select>",
|
2011-01-05 05:23:37 -08:00
|
|
|
"<div id='elem' tabindex='0' class='canfocus' style='width: 10px; height: 10px;'></div>",
|
2010-06-21 05:37:34 -07:00
|
|
|
"<a href='about:blank' class='canfocus' onclick='return false;'>about:blank</a>",
|
|
|
|
];
|
|
|
|
|
2010-08-09 09:15:47 -07:00
|
|
|
var htmlElementsMacPrefSet = [
|
|
|
|
"<button id='elem' class='canfocus'>Button</button>",
|
|
|
|
"<input id='elem' class='canfocus'>",
|
|
|
|
"<input id='elem' type='button' class='canfocus'>",
|
|
|
|
"<input id='elem' type='checkbox' class='canfocus'>",
|
|
|
|
];
|
|
|
|
|
|
|
|
function testHTMLElements(list, isMac, expectedNoRingsOnWin)
|
2010-06-21 05:37:34 -07:00
|
|
|
{
|
|
|
|
var childwin = frames[0];
|
|
|
|
var childdoc = childwin.document;
|
|
|
|
var container = childdoc.getElementById("container");
|
2010-08-09 09:15:47 -07:00
|
|
|
for (var e = 0; e < list.length; e++) {
|
|
|
|
container.innerHTML = list[e];
|
2010-06-21 05:37:34 -07:00
|
|
|
|
|
|
|
var elem = container.firstChild;
|
|
|
|
|
|
|
|
var shouldFocus = !isMac || (elem.className == "canfocus");
|
|
|
|
var ringSize = (shouldFocus ? (expectedNoRingsOnWin ? 2 : 1) : 0) + "px";
|
|
|
|
if (elem.localName == "a")
|
|
|
|
ringSize = "0px";
|
|
|
|
|
|
|
|
synthesizeMouse(elem, 8, 8, { }, childwin);
|
2010-08-09 09:15:47 -07:00
|
|
|
is(childdoc.activeElement, shouldFocus ? elem : childdoc.body, "mouse click on " + list[e]);
|
|
|
|
is(childwin.getComputedStyle(elem, "").outlineWidth, ringSize, "mouse click on " + list[e] + " ring");
|
2010-06-21 05:37:34 -07:00
|
|
|
|
|
|
|
if (childdoc.activeElement)
|
|
|
|
childdoc.activeElement.blur();
|
|
|
|
|
|
|
|
ringSize = (elem.localName == "a" ? "0" : (expectedNoRingsOnWin ? 2 : 1)) + "px";
|
|
|
|
|
|
|
|
elem.focus();
|
2010-08-09 09:15:47 -07:00
|
|
|
is(childdoc.activeElement, elem, "focus() on " + list[e]);
|
2010-06-21 05:37:34 -07:00
|
|
|
is(childwin.getComputedStyle(elem, "").outlineWidth, ringSize,
|
2010-08-09 09:15:47 -07:00
|
|
|
"focus() on " + list[e] + " ring");
|
2010-06-21 05:37:34 -07:00
|
|
|
|
|
|
|
childdoc.activeElement.blur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-21 07:53:42 -07:00
|
|
|
SimpleTest.waitForFocus(runTest);
|
|
|
|
|
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<listbox id="l1" class="plain" height="20"/>
|
|
|
|
<listbox id="l2" class="plain" height="20"/>
|
|
|
|
<listbox id="l3" class="plain" height="20"/>
|
|
|
|
<button id="b1" label="Button"/>
|
|
|
|
<button id="b2" label="Button"/>
|
2010-06-21 05:37:34 -07:00
|
|
|
<button id="b3" label="Button"/>
|
|
|
|
|
2011-05-24 08:39:57 -07:00
|
|
|
<iframe id="child" src="data:text/html,<html><style>* { outline: none; -moz-appearance: none; } %23elem:focus { outline: 2px solid red; } %23elem:-moz-focusring { outline: 1px solid blue; }</style><div id='container'></html>"/>
|
2010-04-21 07:53:42 -07:00
|
|
|
|
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
|
|
|
|
|
|
|
|
</window>
|