toolkit/content/tests/chrome/test_showcaret.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     5 <window title="Show Caret Test"
     6         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     8   <script type="application/javascript"
     9           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    11 <iframe id="f1" width="100" height="100" onload="frameLoaded()"
    12         src="data:text/html,%3Cbody%20style='height:%208000px'%3E%3Cp%3EHello%3C/p%3EGoodbye%3C/body%3E"/>
    13 <!-- <body style='height: 8000px'><p>Hello</p><span id='s'>Goodbye<span></body> -->
    14 <iframe id="f2" type="content" showcaret="true" width="100" height="100" onload="frameLoaded()"
    15         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"/>
    17 <script>
    18 <![CDATA[
    20 var framesLoaded = 0;
    21 var otherWindow = null;
    23 function frameLoaded() { if (++framesLoaded == 2) SimpleTest.waitForFocus(runTest); }
    25 SimpleTest.waitForExplicitFinish();
    26 function runTest()
    27 {
    28   var sel1 = frames[0].getSelection();
    29   sel1.collapse(frames[0].document.body, 0);
    31   var sel2 = frames[1].getSelection();
    32   sel2.collapse(frames[1].document.body, 0);
    33   window.frames[0].focus();
    34   document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
    36   var listener = function() {
    37     if (!(frames[0].scrollY > 0)) {
    38       window.content.removeEventListener("scroll", listener, false);
    39     }
    40   }
    41   window.frames[0].addEventListener("scroll", listener, false);
    43   var sel1 = frames[0].getSelection();
    44   sel1.collapse(frames[0].document.body, 0);
    46   var sel2 = frames[1].getSelection();
    47   sel2.collapse(frames[1].document.body, 0);
    49   window.frames[0].focus();
    50   document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
    51   is(sel1.focusNode, frames[0].document.body, "focusNode for non-showcaret");
    52   is(sel1.focusOffset, 0, "focusOffset for non-showcaret");
    54   window.frames[1].focus();
    55   document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
    57   ok(frames[1].scrollY <
    58        frames[1].document.getElementById('s').getBoundingClientRect().top,
    59      "scrollY for showcaret");
    60   isnot(sel2.focusNode, frames[1].document.body, "focusNode for showcaret");
    61   ok(sel2.anchorOffset > 0, "focusOffset for showcaret");
    63   otherWindow = window.open("window_showcaret.xul", "_blank", "chrome,width=400,height=200");
    64   otherWindow.addEventListener("focus", otherWindowFocused, false);
    65 }
    67 function otherWindowFocused()
    68 {
    69   otherWindow.removeEventListener("focus", otherWindowFocused, false);
    71   // enable caret browsing temporarily to test caret movement
    72   var prefs = Components.classes["@mozilla.org/preferences-service;1"].
    73                 getService(Components.interfaces.nsIPrefBranch);
    74   prefs.setBoolPref("accessibility.browsewithcaret", true);
    76   var hbox = otherWindow.document.documentElement.firstChild;
    77   hbox.focus();
    78   is(otherWindow.document.activeElement, hbox, "hbox in other window is focused");
    80   document.commandDispatcher.getControllerForCommand("cmd_lineNext").doCommand("cmd_lineNext");
    81   is(otherWindow.document.activeElement, hbox, "hbox still focused in other window after down movement");
    83   prefs.setBoolPref("accessibility.browsewithcaret", false);
    85   otherWindow.close();
    86   SimpleTest.finish();
    87 }
    89 ]]>
    90 </script>
    92 <body xmlns="http://www.w3.org/1999/xhtml">
    93 <p id="display">
    94 </p>
    95 <div id="content" style="display: none">
    96 </div>
    97 <pre id="test">
    98 </pre>
    99 </body>
   101 </window>

mercurial