tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_tb_htmlmail_reply_below_quote.html (2879B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>nsIHTMLEditor.insertElementAtSelection() shouldn't touch preceding blockquote content</title>
      6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      8 <script>
      9 "use strict";
     10 
     11 SimpleTest.waitForExplicitFinish();
     12 SimpleTest.waitForFocus(async () => {
     13  document.designMode = "on";
     14  const htmlEditor = getHTMLEditor();
     15  htmlEditor.enableUndo(false);
     16  // https://searchfox.org/comm-central/rev/1016048a635bd062b826bfe767c86acaeadd004a/mailnews/compose/src/nsMsgCompose.cpp#529
     17  const precedingDiv = SpecialPowers.unwrap(htmlEditor.createElementWithDefaults("div"));
     18  precedingDiv.innerHTML = "Somebody wrote:";
     19  precedingDiv.appendChild(SpecialPowers.unwrap(htmlEditor.createElementWithDefaults("br")));
     20  htmlEditor.insertElementAtSelection(precedingDiv, true);
     21  getSelection().collapse(document.body, 1); // Collapse selection after the <div>
     22  const originalHTMLMailHead = `
     23    <meta charset="utf-8">
     24    <title>Original Email</title>
     25  `;
     26  const originalHTMLMailBody = `
     27    First line<br>
     28    You wrote:<br>
     29    <blockquote type="cite">
     30      Quoted first line
     31    </blockquote>
     32  `;
     33  const originalHTMLMail = `<!doctype html>
     34 <html>
     35  <head>${originalHTMLMailHead}</head>
     36  <body>${originalHTMLMailBody}</body>
     37 </html>
     38 `;
     39  // https://searchfox.org/comm-central/rev/1016048a635bd062b826bfe767c86acaeadd004a/mailnews/compose/src/nsMsgCompose.cpp#537-538
     40  const blockquote = SpecialPowers.unwrap(htmlEditor.insertAsCitedQuotation(originalHTMLMail, "", true));
     41  const expectedBlockquoteContent = `\n\n  ${originalHTMLMailHead}\n  ${originalHTMLMailBody}\n\n`;
     42  is(
     43    blockquote.innerHTML,
     44    expectedBlockquoteContent,
     45    "The original mail body should be inserted into the <blockquote>"
     46  );
     47  // https://searchfox.org/comm-central/rev/59abd448822dcbee815be6d599b19108d0d42c0b/mail/components/compose/content/MsgComposeCommands.js#740
     48  getSelection().collapse(document.body, 2); // Collapse selection after the <blockquote>
     49  const p = SpecialPowers.unwrap(htmlEditor.createElementWithDefaults("p"));
     50  p.appendChild(SpecialPowers.unwrap(htmlEditor.createElementWithDefaults("br")));
     51  htmlEditor.insertElementAtSelection(p, false);
     52  getSelection().collapse(p, 0);
     53  is(
     54    document.body.innerHTML,
     55    `<div>Somebody wrote:<br></div><blockquote type="cite">${expectedBlockquoteContent}</blockquote><p><br></p>`,
     56    "The original mail should be quoted as expected when the initialization finished"
     57  );
     58  SimpleTest.finish();
     59 });
     60 
     61 
     62 function getHTMLEditor() {
     63  var Ci = SpecialPowers.Ci;
     64  var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
     65  return editingSession.getEditorForWindow(window)
     66    .QueryInterface(Ci.nsIHTMLEditor)
     67    .QueryInterface(Ci.nsIEditorMailSupport);
     68 }
     69 </script>
     70 </head>
     71 <body></body>
     72 </html>