dom/tests/mochitest/chrome/window_focus_docnav.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/chrome/window_focus_docnav.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +
     1.7 +<window onload="start()"
     1.8 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     1.9 +
    1.10 +<script type="application/javascript"
    1.11 +        src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.12 +
    1.13 +<textbox id="textbox"/>
    1.14 +
    1.15 +<panel id="panel2" onpopupshown="runTests(this, 2);" onpopuphidden="document.getElementById('panel').hidePopup()">
    1.16 +  <textbox id="p2textbox" value="Popup2"/>
    1.17 +</panel>
    1.18 +<panel id="panel" onpopupshown="runTests(this, 1);"
    1.19 +                  onpopuphidden="done()">
    1.20 +  <textbox id="p1textbox" value="Popup1"/>
    1.21 +</panel>
    1.22 +
    1.23 +<browser id="browser" type="content" src="focus_frameset.html" width="500" height="400"/>
    1.24 +
    1.25 +<script type="application/javascript">
    1.26 +<![CDATA[
    1.27 +
    1.28 +var fm = Components.classes["@mozilla.org/focus-manager;1"].
    1.29 +           getService(Components.interfaces.nsIFocusManager);
    1.30 +
    1.31 +function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }
    1.32 +function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); }
    1.33 +
    1.34 +function done()
    1.35 +{
    1.36 +  var opener = window.opener;
    1.37 +  window.close();
    1.38 +  opener.wrappedJSObject.SimpleTest.finish();
    1.39 +}
    1.40 +
    1.41 +function previous(expectedWindow, expectedElement, desc)
    1.42 +{
    1.43 +  synthesizeKey("VK_F6", { shiftKey: true });
    1.44 +  is(fm.focusedWindow, expectedWindow, desc);
    1.45 +  is(fm.focusedElement, expectedElement, desc + " element");
    1.46 +}
    1.47 +
    1.48 +function next(expectedWindow, expectedElement, desc)
    1.49 +{
    1.50 +  synthesizeKey("VK_F6", { });
    1.51 +  is(fm.focusedWindow, expectedWindow, desc);
    1.52 +  is(fm.focusedElement, expectedElement, desc + " element" + "::" + (fm.focusedElement ? fm.focusedElement.parentNode.id : "<none>"));
    1.53 +}
    1.54 +
    1.55 +// This test runs through three cases. Document navigation forward and
    1.56 +// backward using the F6 key when no popups are open, with one popup open and
    1.57 +// with two popups open.
    1.58 +function runTests(panel, popupCount)
    1.59 +{
    1.60 +  if (!popupCount || popupCount > 2)
    1.61 +    popupCount = 0;
    1.62 +
    1.63 +  fm.clearFocus(window);
    1.64 +
    1.65 +  var childwin = document.getElementById("browser").contentWindow;
    1.66 +
    1.67 +  if (popupCount) {
    1.68 +    if (popupCount == 2) {
    1.69 +      next(window, document.getElementById("p2textbox").inputField, "First into popup 2 with " + popupCount);
    1.70 +    }
    1.71 +
    1.72 +    next(window, document.getElementById("p1textbox").inputField, "First into popup 1 with " + popupCount);
    1.73 +  }
    1.74 +
    1.75 +  next(childwin.frames[0], childwin.frames[0].document.documentElement, "First with " + popupCount);
    1.76 +  next(childwin.frames[1], childwin.frames[1].document.documentElement, "Second with " + popupCount);
    1.77 +  previous(childwin.frames[0], childwin.frames[0].document.documentElement, "Second back with " + popupCount);
    1.78 +
    1.79 +  if (popupCount) {
    1.80 +    previous(window, document.getElementById("p1textbox").inputField, "First back from popup 1 with " + popupCount);
    1.81 +
    1.82 +    if (popupCount == 2) {
    1.83 +      previous(window, document.getElementById("p2textbox").inputField, "First back from popup 2 with " + popupCount);
    1.84 +    }
    1.85 +  }
    1.86 +
    1.87 +  previous(window, document.getElementById("textbox").inputField, "First back with " + popupCount);
    1.88 +
    1.89 +  if (panel == document.getElementById("panel"))
    1.90 +    document.getElementById("panel2").openPopup(null, "after_start", 100, 20);
    1.91 +  else if (panel == document.getElementById("panel2"))
    1.92 +    panel.hidePopup();
    1.93 +  else
    1.94 +    document.getElementById("panel").openPopup(null, "after_start");
    1.95 +}
    1.96 +
    1.97 +function start()
    1.98 +{
    1.99 +  window.opener.wrappedJSObject.SimpleTest.waitForExplicitFinish();
   1.100 +  window.opener.wrappedJSObject.SimpleTest.waitForFocus(
   1.101 +    function() { runTests(null, 0); },
   1.102 +    document.getElementById("browser").contentWindow);
   1.103 +}
   1.104 +
   1.105 +]]></script>
   1.106 +
   1.107 +</window>

mercurial