DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
<html>
<head>
  <title>Test for root element replacement</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css"
          href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display">
</p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
</pre>

<script class="testbody" type="application/javascript">

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTest);

function runDesignModeTest(aDoc, aFocus, aNewSource) {
  aDoc.designMode = "on";

  if (aFocus) {
    aDoc.documentElement.focus();
  }

  aDoc.open();
  aDoc.write(aNewSource);
  aDoc.close();
  aDoc.documentElement.focus();
}

function runContentEditableTest(aDoc, aFocus, aNewSource) {
  if (aFocus) {
    aDoc.body.setAttribute("contenteditable", "true");
    aDoc.body.focus();
  }

  aDoc.open();
  aDoc.write(aNewSource);
  aDoc.close();
  aDoc.getElementById("focus").focus();
}

var gTestIndex = 0;

const kTests = [
  { description: "Replace to '<body></body>', designMode",
    initializer: runDesignModeTest,
    args: [ "<body></body>" ] },
  { description: "Replace to '<html><body></body></html>', designMode",
    initializer: runDesignModeTest,
    args: [ "<html><body></body></html>" ] },
  { description: "Replace to '<html>&nbsp;<body></body></html>', designMode",
    initializer: runDesignModeTest,
    args: [ "<html> <body></body></html>" ] },
  { description: "Replace to '&nbsp;<html>&nbsp;<body></body></html>', designMode",
    initializer: runDesignModeTest,
    args: [ " <html> <body></body></html>" ] },

  { description: "Replace to '<html contenteditable='true'><body></body></html>",
    initializer: runContentEditableTest,
    args: [ "<html contenteditable='true' id='focus'><body></body></html>" ] },
  { description: "Replace to '<html><body contenteditable='true'></body></html>",
    initializer: runContentEditableTest,
    args: [ "<html><body contenteditable='true' id='focus'></body></html>" ] },
  { description: "Replace to '<body contenteditable='true'></body>",
    initializer: runContentEditableTest,
    args: [ "<body contenteditable='true' id='focus'></body>" ] },
];

var gIFrame;
var gSetFocusToIFrame = false;

function onLoadIFrame() {
  var frameDoc = gIFrame.contentWindow.document;

  var selCon = SpecialPowers.wrap(gIFrame).contentWindow.
    docShell.
    QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
    getInterface(SpecialPowers.Ci.nsISelectionDisplay).
    QueryInterface(SpecialPowers.Ci.nsISelectionController);
  var utils = SpecialPowers.getDOMWindowUtils(window);

  // move focus to the HTML editor
  const kTest = kTests[gTestIndex];
  ok(true, "Running " + kTest.description);
  if (kTest.args.length == 1) {
    kTest.initializer(frameDoc, gSetFocusToIFrame, kTest.args[0]);
    ok(selCon.caretVisible, "caret isn't visible -- " + kTest.description);
  } else {
    ok(false, "kTests is broken at index=" + gTestIndex);
  }

  is(utils.IMEStatus, utils.IME_STATUS_ENABLED,
     "IME isn't enabled -- " + kTest.description);
  synthesizeKey("A", { }, gIFrame.contentWindow);
  synthesizeKey("B", { }, gIFrame.contentWindow);
  synthesizeKey("C", { }, gIFrame.contentWindow);
  var content = frameDoc.body.firstChild;
  ok(content, "body doesn't have contents -- " + kTest.description);
  if (content) {
    is(content.nodeType, Node.TEXT_NODE,
       "the content of body isn't text node -- " + kTest.description);
    if (content.nodeType == Node.TEXT_NODE) {
      is(content.data, "ABC",
         "the content of body text isn't 'ABC' -- " + kTest.description);
      is(frameDoc.body.innerHTML, "ABC",
         "the innerHTML of body isn't 'ABC' -- " + kTest.description);
    }
  }

  document.getElementById("display").removeChild(gIFrame);

  // Do next test or finish the tests.
  if (++gTestIndex < kTests.length) {
    setTimeout(runTest, 0);
  } else if (!gSetFocusToIFrame) {
    gSetFocusToIFrame = true;
    gTestIndex = 0;
    setTimeout(runTest, 0);
  } else {
    SimpleTest.finish();
  }
}

function runTest() {
  gIFrame = document.createElement("iframe");
  document.getElementById("display").appendChild(gIFrame);
  gIFrame.src = "about:blank";
  gIFrame.onload = onLoadIFrame;
}

</script>
</body>

</html>