Bug 1874684 - Part 17: Fix uninitialised variable warnings from clang-tidy. r=allstarschh
[gecko.git] / editor / libeditor / tests / test_pasting_in_root_element.xhtml
blobd647899ca726a1d1a1ad25056d402b8ffd906f76
1 <!DOCTYPE HTML>
2 <html contenteditable="" xmlns="http://www.w3.org/1999/xhtml"><head>
3 <!-- https://bugzilla.mozilla.org/show_bug.cgi?id=1719387 -->
4 <meta charset="utf-8"/>
5 <title>Test to paste plaintext in the clipboard into the html element which does not have body element</title>
6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
8 </head><span>Text outside body</span><script><![CDATA[
9 "use strict";
11 SimpleTest.waitForExplicitFinish();
12 SimpleTest.waitForFocus(async () => {
13 info("Waiting for initializing clipboard...");
14 await SimpleTest.promiseClipboardChange(
15 "plain text",
16 () => {
17 SpecialPowers.clipboardCopyString("plain text");
21 focus();
23 function getInnerHTMLOfBody() {
24 return document.documentElement.innerHTML.replace(/\n/g, "")
25 .replace(/ xmlns="http:\/\/www.w3.org\/1999\/xhtml"/g, "")
26 .replace(/<head.+[\/]head>/g, "")
27 .replace(/<script.+[\/]script>/g, "");
30 try {
31 getSelection().collapse(document.documentElement, 1); // collapse to before the <span> element.
32 document.execCommand("insertText", false, "plain text");
33 todo_is(
34 getInnerHTMLOfBody(),
35 "plain text<span>Text outside body</span>", // Chrome's result: "<span>plain textText outside body</span>"
36 "Typing text should insert the text before the <span> element"
38 } catch (ex) {
39 ok(false, `Failed to typing text due to ${ex}`);
40 } finally {
41 SpecialPowers.doCommand(window, "cmd_undo");
44 try {
45 getSelection().collapse(document.documentElement, 1); // collapse to before the <span> element.
46 SpecialPowers.doCommand(window, "cmd_paste");
47 is(
48 getInnerHTMLOfBody(),
49 "plain text<span>Text outside body</span>", // Chrome's result: "<span>plain textText outside body</span>"
50 "\"cmd_paste\" should insert text in the clipboard before the <span> element"
52 } catch (ex) {
53 todo(false, `Failed to typing text due to ${ex}`);
54 } finally {
55 SpecialPowers.doCommand(window, "cmd_undo");
58 try {
59 getSelection().collapse(document.documentElement, 1); // collapse to before the <span> element.
60 SpecialPowers.doCommand(window, "cmd_pasteQuote");
61 is(
62 getInnerHTMLOfBody(),
63 "<blockquote type=\"cite\">plain text</blockquote><span>Text outside body</span>",
64 "\"cmd_pasteQuote\" should insert the text wrapping with <blockquote> element before the <span> element"
66 } catch (ex) {
67 ok(false, `Failed to typing text due to ${ex}`);
68 } finally {
69 SpecialPowers.doCommand(window, "cmd_undo");
72 SimpleTest.finish();
73 });
74 ]]></script></html>