<head>
<style type="text/css">
  .ahem { font: 20px Ahem; }
</style>
<script>
if (window.testRunner)
    testRunner.dumpAsText();

function runTest() {
  runFrameCursorMoveTest();
  runDivCursorMoveTest();
}

function generateContent() {
    var content = "";
    for (var i = 0; i < 10; ++i)
        content += "<p>line " + i + "</p>\n";
    return content;
}

function runFrameCursorMoveTest() {
    var frame = frames[0];
    var doc = frame.document;
    var body = doc.body;
    body.innerHTML = generateContent();
    frame.focus();
    frame.getSelection().setPosition(body.firstChild, 0);
    runCursorMoveTest("iframe", frame, frame);
}

function runDivCursorMoveTest() {
    var editable = document.getElementById('editable');
    editable.innerHTML = generateContent();
    editable.focus();
    window.getSelection().setPosition(editable, 0);
    runCursorMoveTest("div", editable, window);
}

function runCursorMoveTest(testName, frame, selectionSource)
{
    var onMacPlatform = navigator.userAgent.search(/\bMac OS X\b/) != -1;
    var modifiers = onMacPlatform ? ["altKey"] : [];

    if (!window.eventSender)
        return;

    eventSender.keyDown("pageDown", modifiers);
    var line = selectionSource.getSelection().baseNode.nodeValue;
    if (line != "line 3")
        throw "cursor should be at line 3, not " + line;

    eventSender.keyDown("pageDown", modifiers);
    var line = selectionSource.getSelection().baseNode.nodeValue;
    if (line != "line 6")
        throw "cursor should be at line 6, not " + line;

    eventSender.keyDown("pageUp", modifiers);
    var line = selectionSource.getSelection().baseNode.nodeValue;
    if (line != "line 3")
        throw "cursor should be at line 3, not " + line;

    // Test that on Mac pageDown/pageUp does not move the cursor at all.
    if (onMacPlatform) {
      eventSender.keyDown("pageDown", []);
      var line = selectionSource.getSelection().baseNode.nodeValue;
      if (line != "line 3") {
          document.getElementById("results").innerText = "cursor should be at line 3, not " + line;
          throw "cursor should be at line 3, not " + line;
      }

      eventSender.keyDown("pageUp", []);
      var line = selectionSource.getSelection().baseNode.nodeValue;
      if (line != "line 3") {
          document.getElementById("results").innerText = "cursor should be at line 3, not " + line;
          throw "cursor should be at line 3, not " + line;
      }
    }

    document.getElementById("results").innerHTML += testName + " PASS<br/>";
}
</script>
</head>
<body onload="runTest()">
<div>Page up/down (option+page up/down on Mac) should move the move cursor and scroll the content
in contenteditable elements. This sample covers cursor position move test of a) iframe element containing
contenteditable body, and b) content editable div element.</div>
<iframe src="../resources/contenteditable-iframe-fixed-size-src.html"></iframe>
<div id="editable" contenteditable="true" class="ahem" style="height:150px; overflow:auto;"></div>
<div id="results"></div>
</body>
