toolkit/content/tests/chrome/test_showcaret.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_showcaret.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     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 title="Show Caret Test"
     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 +
    1.14 +<iframe id="f1" width="100" height="100" onload="frameLoaded()"
    1.15 +        src="data:text/html,%3Cbody%20style='height:%208000px'%3E%3Cp%3EHello%3C/p%3EGoodbye%3C/body%3E"/>
    1.16 +<!-- <body style='height: 8000px'><p>Hello</p><span id='s'>Goodbye<span></body> -->
    1.17 +<iframe id="f2" type="content" showcaret="true" width="100" height="100" onload="frameLoaded()"
    1.18 +        src="data:text/html,%3Cbody%20style%3D%27height%3A%208000px%27%3E%3Cp%3EHello%3C%2Fp%3E%3Cspan%20id%3D%27s%27%3EGoodbye%3Cspan%3E%3C%2Fbody%3E"/>
    1.19 +
    1.20 +<script>
    1.21 +<![CDATA[
    1.22 +
    1.23 +var framesLoaded = 0;
    1.24 +var otherWindow = null;
    1.25 +
    1.26 +function frameLoaded() { if (++framesLoaded == 2) SimpleTest.waitForFocus(runTest); }
    1.27 +
    1.28 +SimpleTest.waitForExplicitFinish();
    1.29 +function runTest()
    1.30 +{
    1.31 +  var sel1 = frames[0].getSelection();
    1.32 +  sel1.collapse(frames[0].document.body, 0);
    1.33 +
    1.34 +  var sel2 = frames[1].getSelection();
    1.35 +  sel2.collapse(frames[1].document.body, 0);
    1.36 +  window.frames[0].focus();
    1.37 +  document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
    1.38 +
    1.39 +  var listener = function() {
    1.40 +    if (!(frames[0].scrollY > 0)) {
    1.41 +      window.content.removeEventListener("scroll", listener, false);
    1.42 +    }
    1.43 +  }
    1.44 +  window.frames[0].addEventListener("scroll", listener, false);
    1.45 +
    1.46 +  var sel1 = frames[0].getSelection();
    1.47 +  sel1.collapse(frames[0].document.body, 0);
    1.48 +
    1.49 +  var sel2 = frames[1].getSelection();
    1.50 +  sel2.collapse(frames[1].document.body, 0);
    1.51 +
    1.52 +  window.frames[0].focus();
    1.53 +  document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
    1.54 +  is(sel1.focusNode, frames[0].document.body, "focusNode for non-showcaret");
    1.55 +  is(sel1.focusOffset, 0, "focusOffset for non-showcaret");
    1.56 +
    1.57 +  window.frames[1].focus();
    1.58 +  document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
    1.59 +
    1.60 +  ok(frames[1].scrollY <
    1.61 +       frames[1].document.getElementById('s').getBoundingClientRect().top,
    1.62 +     "scrollY for showcaret");
    1.63 +  isnot(sel2.focusNode, frames[1].document.body, "focusNode for showcaret");
    1.64 +  ok(sel2.anchorOffset > 0, "focusOffset for showcaret");
    1.65 +
    1.66 +  otherWindow = window.open("window_showcaret.xul", "_blank", "chrome,width=400,height=200");
    1.67 +  otherWindow.addEventListener("focus", otherWindowFocused, false);
    1.68 +}
    1.69 +
    1.70 +function otherWindowFocused()
    1.71 +{
    1.72 +  otherWindow.removeEventListener("focus", otherWindowFocused, false);
    1.73 +
    1.74 +  // enable caret browsing temporarily to test caret movement
    1.75 +  var prefs = Components.classes["@mozilla.org/preferences-service;1"].
    1.76 +                getService(Components.interfaces.nsIPrefBranch);
    1.77 +  prefs.setBoolPref("accessibility.browsewithcaret", true);
    1.78 +
    1.79 +  var hbox = otherWindow.document.documentElement.firstChild;
    1.80 +  hbox.focus();
    1.81 +  is(otherWindow.document.activeElement, hbox, "hbox in other window is focused");
    1.82 +
    1.83 +  document.commandDispatcher.getControllerForCommand("cmd_lineNext").doCommand("cmd_lineNext");
    1.84 +  is(otherWindow.document.activeElement, hbox, "hbox still focused in other window after down movement");
    1.85 +
    1.86 +  prefs.setBoolPref("accessibility.browsewithcaret", false);
    1.87 +
    1.88 +  otherWindow.close();
    1.89 +  SimpleTest.finish();
    1.90 +}
    1.91 +
    1.92 +]]>
    1.93 +</script>
    1.94 +
    1.95 +<body xmlns="http://www.w3.org/1999/xhtml">
    1.96 +<p id="display">
    1.97 +</p>
    1.98 +<div id="content" style="display: none">
    1.99 +</div>
   1.100 +<pre id="test">
   1.101 +</pre>
   1.102 +</body>
   1.103 +
   1.104 +</window>

mercurial