toolkit/content/tests/chrome/test_dialogfocus.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_dialogfocus.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +
     1.8 +<window width="500" height="600"
     1.9 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.10 +
    1.11 +<script type="application/javascript"
    1.12 +        src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +<script type="application/javascript"
    1.14 +        src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.15 +
    1.16 +<button id="test" label="Test"/>
    1.17 +
    1.18 +<body xmlns="http://www.w3.org/1999/xhtml">
    1.19 +<p id="display"></p>
    1.20 +<div id="content" style="display: none">
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +</pre>
    1.24 +</body>
    1.25 +
    1.26 +<script>
    1.27 +<![CDATA[
    1.28 +
    1.29 +SimpleTest.waitForExplicitFinish();
    1.30 +SimpleTest.requestCompleteLog();
    1.31 +
    1.32 +var expected = [ "one", "_extra2", "tab", "one", "tabbutton2", "tabbutton", "two", "textbox-yes", "one" ];
    1.33 +// non-Mac will always focus the default button if any of the dialog buttons
    1.34 +// would be focused
    1.35 +if (navigator.platform.indexOf("Mac") == -1)
    1.36 +  expected[1] = "_accept";
    1.37 +
    1.38 +var step = 0;
    1.39 +var fullKeyboardAccess = false;
    1.40 +
    1.41 +function startTest()
    1.42 +{
    1.43 +  var testButton = document.getElementById("test");
    1.44 +  synthesizeKey("VK_TAB", { });
    1.45 +  fullKeyboardAccess = (document.activeElement == testButton);
    1.46 +  info("We " + (fullKeyboardAccess ? "have" : "don't have") + " full keyboard access");
    1.47 +  runTest();
    1.48 +}
    1.49 +
    1.50 +function runTest()
    1.51 +{
    1.52 +  step++;
    1.53 +  info("runTest(), step = " + step + ", expected = " + expected[step - 1]);
    1.54 +  if (step > expected.length || (!fullKeyboardAccess && step == 2)) {
    1.55 +    info("finishing");
    1.56 +    SimpleTest.finish();
    1.57 +    return;
    1.58 +  }
    1.59 +
    1.60 +  var expectedFocus = expected[step - 1];
    1.61 +  var win = window.openDialog("dialog_dialogfocus.xul", "_new", "chrome,dialog", step);
    1.62 +
    1.63 +  function checkDialogFocus(event)
    1.64 +  {
    1.65 +    info("checkDialogFocus()");
    1.66 +    // if full keyboard access is not on, just skip the tests
    1.67 +    var match = false;
    1.68 +    if (fullKeyboardAccess) {
    1.69 +      if (!(event.target instanceof Element)) {
    1.70 +        info("target not an Element");
    1.71 +        return;
    1.72 +      }
    1.73 +
    1.74 +      if (expectedFocus == "textbox-yes")
    1.75 +        match = (win.document.activeElement == win.document.getElementById(expectedFocus).inputField);
    1.76 +      else if (expectedFocus[0] == "_")
    1.77 +        match = (win.document.activeElement.dlgType == expectedFocus.substring(1));
    1.78 +      else
    1.79 +        match = (win.document.activeElement.id == expectedFocus);
    1.80 +      info("match = " + match);
    1.81 +      if (!match)
    1.82 +        return;
    1.83 +    }
    1.84 +    else {
    1.85 +      match = (win.document.activeElement == win.document.documentElement);
    1.86 +      info("match = " + match);
    1.87 +    }
    1.88 +
    1.89 +    win.removeEventListener("focus", checkDialogFocus, true);
    1.90 +    ok(match, "focus step " + step);
    1.91 +
    1.92 +    win.close();
    1.93 +    SimpleTest.waitForFocus(runTest, window);
    1.94 +  }
    1.95 +
    1.96 +  win.addEventListener("focus", checkDialogFocus, true);
    1.97 +}
    1.98 +
    1.99 +SimpleTest.waitForFocus(startTest, window);
   1.100 +
   1.101 +]]>
   1.102 +
   1.103 +</script>
   1.104 +
   1.105 +</window>

mercurial