toolkit/content/tests/chrome/test_showcaret.xul

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:e9e0eb4a7068
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"?>
4
5 <window title="Show Caret Test"
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
7
8 <script type="application/javascript"
9 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
10
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"/>
16
17 <script>
18 <![CDATA[
19
20 var framesLoaded = 0;
21 var otherWindow = null;
22
23 function frameLoaded() { if (++framesLoaded == 2) SimpleTest.waitForFocus(runTest); }
24
25 SimpleTest.waitForExplicitFinish();
26 function runTest()
27 {
28 var sel1 = frames[0].getSelection();
29 sel1.collapse(frames[0].document.body, 0);
30
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");
35
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);
42
43 var sel1 = frames[0].getSelection();
44 sel1.collapse(frames[0].document.body, 0);
45
46 var sel2 = frames[1].getSelection();
47 sel2.collapse(frames[1].document.body, 0);
48
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");
53
54 window.frames[1].focus();
55 document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
56
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");
62
63 otherWindow = window.open("window_showcaret.xul", "_blank", "chrome,width=400,height=200");
64 otherWindow.addEventListener("focus", otherWindowFocused, false);
65 }
66
67 function otherWindowFocused()
68 {
69 otherWindow.removeEventListener("focus", otherWindowFocused, false);
70
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);
75
76 var hbox = otherWindow.document.documentElement.firstChild;
77 hbox.focus();
78 is(otherWindow.document.activeElement, hbox, "hbox in other window is focused");
79
80 document.commandDispatcher.getControllerForCommand("cmd_lineNext").doCommand("cmd_lineNext");
81 is(otherWindow.document.activeElement, hbox, "hbox still focused in other window after down movement");
82
83 prefs.setBoolPref("accessibility.browsewithcaret", false);
84
85 otherWindow.close();
86 SimpleTest.finish();
87 }
88
89 ]]>
90 </script>
91
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>
100
101 </window>

mercurial