File: test_tb_htmlmail_reply_below_quote.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (72 lines) | stat: -rw-r--r-- 2,879 bytes parent folder | download | duplicates (3)
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>nsIHTMLEditor.insertElementAtSelection() shouldn't touch preceding blockquote content</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
"use strict";

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  document.designMode = "on";
  const htmlEditor = getHTMLEditor();
  htmlEditor.enableUndo(false);
  // https://searchfox.org/comm-central/rev/1016048a635bd062b826bfe767c86acaeadd004a/mailnews/compose/src/nsMsgCompose.cpp#529
  const precedingDiv = SpecialPowers.unwrap(htmlEditor.createElementWithDefaults("div"));
  precedingDiv.innerHTML = "Somebody wrote:";
  precedingDiv.appendChild(SpecialPowers.unwrap(htmlEditor.createElementWithDefaults("br")));
  htmlEditor.insertElementAtSelection(precedingDiv, true);
  getSelection().collapse(document.body, 1); // Collapse selection after the <div>
  const originalHTMLMailHead = `
    <meta charset="utf-8">
    <title>Original Email</title>
  `;
  const originalHTMLMailBody = `
    First line<br>
    You wrote:<br>
    <blockquote type="cite">
      Quoted first line
    </blockquote>
  `;
  const originalHTMLMail = `<!doctype html>
<html>
  <head>${originalHTMLMailHead}</head>
  <body>${originalHTMLMailBody}</body>
</html>
`;
  // https://searchfox.org/comm-central/rev/1016048a635bd062b826bfe767c86acaeadd004a/mailnews/compose/src/nsMsgCompose.cpp#537-538
  const blockquote = SpecialPowers.unwrap(htmlEditor.insertAsCitedQuotation(originalHTMLMail, "", true));
  const expectedBlockquoteContent = `\n\n  ${originalHTMLMailHead}\n  ${originalHTMLMailBody}\n\n`;
  is(
    blockquote.innerHTML,
    expectedBlockquoteContent,
    "The original mail body should be inserted into the <blockquote>"
  );
  // https://searchfox.org/comm-central/rev/59abd448822dcbee815be6d599b19108d0d42c0b/mail/components/compose/content/MsgComposeCommands.js#740
  getSelection().collapse(document.body, 2); // Collapse selection after the <blockquote>
  const p = SpecialPowers.unwrap(htmlEditor.createElementWithDefaults("p"));
  p.appendChild(SpecialPowers.unwrap(htmlEditor.createElementWithDefaults("br")));
  htmlEditor.insertElementAtSelection(p, false);
  getSelection().collapse(p, 0);
  is(
    document.body.innerHTML,
    `<div>Somebody wrote:<br></div><blockquote type="cite">${expectedBlockquoteContent}</blockquote><p><br></p>`,
    "The original mail should be quoted as expected when the initialization finished"
  );
  SimpleTest.finish();
});


function getHTMLEditor() {
  var Ci = SpecialPowers.Ci;
  var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
  return editingSession.getEditorForWindow(window)
    .QueryInterface(Ci.nsIHTMLEditor)
    .QueryInterface(Ci.nsIEditorMailSupport);
}
</script>
</head>
<body></body>
</html>