3 <title>Test for root element replacement
</title>
4 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
5 <script src=
"/tests/SimpleTest/EventUtils.js"></script>
6 <link rel=
"stylesheet" type=
"text/css"
7 href=
"/tests/SimpleTest/test.css" />
12 <div id=
"content" style=
"display: none">
18 <script class=
"testbody" type=
"application/javascript">
20 SimpleTest.waitForExplicitFinish();
21 SimpleTest.waitForFocus(runTest);
23 function runDesignModeTest(aDoc, aFocus, aNewSource) {
24 aDoc.designMode =
"on";
27 aDoc.documentElement.focus();
31 aDoc.write(aNewSource);
33 aDoc.documentElement.focus();
36 function runContentEditableTest(aDoc, aFocus, aNewSource) {
38 aDoc.body.setAttribute(
"contenteditable",
"true");
43 aDoc.write(aNewSource);
45 aDoc.getElementById(
"focus").focus();
51 { description:
"Replace to '<body></body>', designMode",
52 initializer: runDesignModeTest,
53 args: [
"<body></body>" ] },
54 { description:
"Replace to '<html><body></body></html>', designMode",
55 initializer: runDesignModeTest,
56 args: [
"<html><body></body></html>" ] },
57 { description:
"Replace to '<html> <body></body></html>', designMode",
58 initializer: runDesignModeTest,
59 args: [
"<html> <body></body></html>" ] },
60 { description:
"Replace to ' <html> <body></body></html>', designMode",
61 initializer: runDesignModeTest,
62 args: [
" <html> <body></body></html>" ] },
64 { description:
"Replace to '<html contenteditable='true'><body></body></html>",
65 initializer: runContentEditableTest,
66 args: [
"<html contenteditable='true' id='focus'><body></body></html>" ] },
67 { description:
"Replace to '<html><body contenteditable='true'></body></html>",
68 initializer: runContentEditableTest,
69 args: [
"<html><body contenteditable='true' id='focus'></body></html>" ] },
70 { description:
"Replace to '<body contenteditable='true'></body>",
71 initializer: runContentEditableTest,
72 args: [
"<body contenteditable='true' id='focus'></body>" ] },
76 var gSetFocusToIFrame = false;
78 function onLoadIFrame() {
79 var frameDoc = gIFrame.contentWindow.document;
81 var selCon = SpecialPowers.wrap(gIFrame).contentWindow.
83 QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
84 getInterface(SpecialPowers.Ci.nsISelectionDisplay).
85 QueryInterface(SpecialPowers.Ci.nsISelectionController);
86 var utils = SpecialPowers.getDOMWindowUtils(window);
88 // move focus to the HTML editor
89 const kTest = kTests[gTestIndex];
90 ok(true,
"Running " + kTest.description);
91 if (kTest.args.length ==
1) {
92 kTest.initializer(frameDoc, gSetFocusToIFrame, kTest.args[
0]);
93 ok(selCon.caretVisible,
"caret isn't visible -- " + kTest.description);
95 ok(false,
"kTests is broken at index=" + gTestIndex);
98 is(utils.IMEStatus, utils.IME_STATUS_ENABLED,
99 "IME isn't enabled -- " + kTest.description);
100 synthesizeKey(
"A", { }, gIFrame.contentWindow);
101 synthesizeKey(
"B", { }, gIFrame.contentWindow);
102 synthesizeKey(
"C", { }, gIFrame.contentWindow);
103 var content = frameDoc.body.firstChild;
104 ok(content,
"body doesn't have contents -- " + kTest.description);
106 is(content.nodeType, Node.TEXT_NODE,
107 "the content of body isn't text node -- " + kTest.description);
108 if (content.nodeType == Node.TEXT_NODE) {
109 is(content.data,
"ABC",
110 "the content of body text isn't 'ABC' -- " + kTest.description);
111 is(frameDoc.body.innerHTML,
"ABC",
112 "the innerHTML of body isn't 'ABC' -- " + kTest.description);
116 document.getElementById(
"display").removeChild(gIFrame);
118 // Do next test or finish the tests.
119 if (++gTestIndex < kTests.length) {
120 setTimeout(runTest,
0);
121 } else if (!gSetFocusToIFrame) {
122 gSetFocusToIFrame = true;
124 setTimeout(runTest,
0);
131 gIFrame = document.createElement(
"iframe");
132 document.getElementById(
"display").appendChild(gIFrame);
133 gIFrame.src =
"about:blank";
134 gIFrame.onload = onLoadIFrame;