Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / tests / test_root_element_replacement.html
blob45765d9ab2aed010bf116eba4281e64fb16947d6
1 <html>
2 <head>
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" />
8 </head>
9 <body>
10 <p id="display">
11 </p>
12 <div id="content" style="display: none">
14 </div>
15 <pre id="test">
16 </pre>
18 <script class="testbody" type="application/javascript">
20 SimpleTest.waitForExplicitFinish();
21 SimpleTest.waitForFocus(runTest);
23 function runDesignModeTest(aDoc, aFocus, aNewSource) {
24 aDoc.designMode = "on";
26 if (aFocus) {
27 aDoc.documentElement.focus();
30 aDoc.open();
31 aDoc.write(aNewSource);
32 aDoc.close();
33 aDoc.documentElement.focus();
36 function runContentEditableTest(aDoc, aFocus, aNewSource) {
37 if (aFocus) {
38 aDoc.body.setAttribute("contenteditable", "true");
39 aDoc.body.focus();
42 aDoc.open();
43 aDoc.write(aNewSource);
44 aDoc.close();
45 aDoc.getElementById("focus").focus();
48 var gTestIndex = 0;
50 const kTests = [
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>&nbsp;<body></body></html>', designMode",
58 initializer: runDesignModeTest,
59 args: [ "<html> <body></body></html>" ] },
60 { description: "Replace to '&nbsp;<html>&nbsp;<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>" ] },
75 var gIFrame;
76 var gSetFocusToIFrame = false;
78 function onLoadIFrame() {
79 var frameDoc = gIFrame.contentWindow.document;
81 var selCon = SpecialPowers.wrap(gIFrame).contentWindow.
82 docShell.
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);
94 } else {
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);
105 if (content) {
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;
123 gTestIndex = 0;
124 setTimeout(runTest, 0);
125 } else {
126 SimpleTest.finish();
130 function runTest() {
131 gIFrame = document.createElement("iframe");
132 document.getElementById("display").appendChild(gIFrame);
133 gIFrame.src = "about:blank";
134 gIFrame.onload = onLoadIFrame;
137 </script>
138 </body>
140 </html>