<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>

<window title="Show Caret Test"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript" 
          src="chrome://mochikit/content/MochiKit/packed.js"/>
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

<iframe id="f1" width="100" height="100" onload="frameLoaded()"
        src="data:text/html,%3Cbody%20style='height:%208000px'%3E%3Cp%3EHello%3C/p%3EGoodbye%3C/body%3E"/>
<iframe id="f2" type="content" showcaret="true" width="100" height="100" onload="frameLoaded()"
        src="data:text/html,%3Cbody%20style='height:%208000px'%3E%3Cp%3EHello%3C/p%3EGoodbye%3C/body%3E"/>

<script>
<![CDATA[

var framesLoaded = 0;
function frameLoaded() { if (++framesLoaded == 2) runTest(); }

SimpleTest.waitForExplicitFinish();
function runTest()
{
  var sel1 = frames[0].getSelection();
  sel1.collapse(frames[0].document.body, 0);

  var sel2 = frames[1].getSelection();
  sel2.collapse(frames[1].document.body, 0);

  window.frames[0].focus();
  document.commandDispatcher.getControllerForCommand("cmd_scrollBottom").doCommand("cmd_scrollBottom");

  ok(frames[0].scrollY > 0, "scrollY for non-showcaret");
  is(sel1.focusNode, frames[0].document.body, "focusNode for non-showcaret");
  is(sel1.focusOffset, 0, "focusOffset for non-showcaret");

  window.frames[1].focus();
  document.commandDispatcher.getControllerForCommand("cmd_scrollBottom").doCommand("cmd_scrollBottom");

  is(frames[1].scrollY, 0, "scrollY for showcaret");
  isnot(sel2.focusNode, frames[1].document.body, "focusNode for showcaret");
  ok(sel2.anchorOffset > 0, "focusOffset for showcaret");

  SimpleTest.finish();
}

]]>
</script>

<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>

</window>
