tor-browser

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

test_bug795418-2.html (2606B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=795418
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test #2 for Bug 772796</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <script src="/tests/SimpleTest/EventUtils.js"></script>
     11  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=772796">Mozilla Bug 795418</a>
     15 <p id="display"></p>
     16 <div id="content" style="display: none">
     17 </div>
     18 
     19 <div id="copySource">Copy this</div>
     20 <!-- load content of type application/xhtml+xml using an *.sjs file -->
     21 <iframe src="./file_bug795418-2.sjs"></iframe>
     22 
     23 <pre id="test">
     24 
     25 <script type="application/javascript">
     26 
     27 /** Test for Bug 795418 */
     28 SimpleTest.waitForExplicitFinish();
     29 SimpleTest.waitForFocus(function() {
     30  const div = document.getElementById("copySource");
     31  getSelection().setBaseAndExtent(div.firstChild, 0, div.firstChild, "Copy this".length);
     32  info(`Selected test: "${getSelection().getRangeAt(0).toString()}"`);
     33 
     34  function checkResult() {
     35    var iframe = document.querySelector("iframe");
     36    var theEdit = iframe.contentDocument.firstChild;
     37    theEdit.offsetHeight;
     38    is(theEdit.innerHTML,
     39       "<blockquote xmlns=\"http://www.w3.org/1999/xhtml\" type=\"cite\">Copy this</blockquote><span xmlns=\"http://www.w3.org/1999/xhtml\">AB</span>",
     40       "unexpected HTML for test");
     41    SimpleTest.finish();
     42  }
     43 
     44  function pasteQuote() {
     45    var iframe = document.querySelector("iframe");
     46    var iframeWindow = iframe.contentWindow;
     47    var theEdit = iframe.contentDocument.firstChild;
     48    theEdit.offsetHeight;
     49    iframeWindow.focus();
     50    SimpleTest.waitForFocus(function() {
     51      var iframeSel = iframeWindow.getSelection();
     52      iframeSel.removeAllRanges();
     53      let span = iframe.contentDocument.querySelector("span");
     54      iframeSel.collapse(span, 1);
     55 
     56      SpecialPowers.doCommand(iframeWindow, "cmd_pasteQuote");
     57      setTimeout(checkResult, 0);
     58    }, iframeWindow);
     59  }
     60 
     61  SimpleTest.waitForClipboard(
     62    aData => {
     63      if (aData.includes(`${getSelection().getRangeAt(0)?.toString()}`)) {
     64        return true;
     65      }
     66      info(`Text in the clipboard: "${aData}"`);
     67      return false;
     68    },
     69    function setup() {
     70      synthesizeKey("c", {accelKey: true});
     71    },
     72    function onSuccess() {
     73      SimpleTest.executeSoon(pasteQuote);
     74    },
     75    function onFailure() {
     76      SimpleTest.finish();
     77    },
     78    // TODO: bug 1686012
     79    SpecialPowers.isHeadless ? "text/plain" : "text/html"
     80  );
     81 });
     82 
     83 </script>
     84 
     85 </pre>
     86 </body>
     87 </html>