diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /editor/libeditor/tests/test_root_element_replacement.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | editor/libeditor/tests/test_root_element_replacement.html | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_root_element_replacement.html b/editor/libeditor/tests/test_root_element_replacement.html new file mode 100644 index 0000000000..45765d9ab2 --- /dev/null +++ b/editor/libeditor/tests/test_root_element_replacement.html @@ -0,0 +1,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> <body></body></html>', designMode", + initializer: runDesignModeTest, + args: [ "<html> <body></body></html>" ] }, + { description: "Replace to ' <html> <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> |