tor-browser

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

test_pasting_svg_image.html (3327B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test pasting &lt;svg&gt;&lt;image href&gt;</title>
      6  <script src="/tests/SimpleTest/EventUtils.js"></script>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      9  <script>
     10    const kPasteTargetId = "pasteTarget";
     11    const kTestContentId = "testContent";
     12    const kIncludeCommonAncestor = SpecialPowers.getBoolPref(
     13      "dom.serializer.includeCommonAncestor.enabled"
     14    );
     15 
     16    function selectSVG() {
     17      const testContent = document.getElementById(kTestContentId);
     18      document.getSelection().selectAllChildren(testContent);
     19    }
     20 
     21    async function copyToClipboard() {
     22      function validatorFn(aData) {
     23        const testContent = document.getElementById(kTestContentId);
     24 
     25        let expectedData = kIncludeCommonAncestor ? testContent.outerHTML
     26                                                  : testContent.innerHTML;
     27        if (navigator.platform.includes(kPlatformWindows)) {
     28          expectedData = kTextHtmlPrefixClipboardDataWindows +
     29            expectedData + kTextHtmlSuffixClipboardDataWindows;
     30        }
     31 
     32        return SimpleTest.stripLinebreaksAndWhitespaceAfterTags(aData) ==
     33          SimpleTest.stripLinebreaksAndWhitespaceAfterTags(expectedData);
     34      }
     35 
     36      function setupFn() {
     37        synthesizeKey("c", { accelKey: true } /* aEvent */);
     38      }
     39 
     40      const flavor = "text/html";
     41 
     42      await SimpleTest.promiseClipboardChange(validatorFn, setupFn, flavor);
     43    }
     44 
     45    async function pasteTo(aTargetElement) {
     46      document.getSelection().selectAllChildren(aTargetElement);
     47 
     48      const promiseInputEvent = new Promise(resolve => {
     49        document.addEventListener("input", resolve,
     50          { once: true } /* options */);
     51        synthesizeKey("v", { accelKey: true } /* aEvent */);
     52      });
     53 
     54      await promiseInputEvent;
     55    }
     56 
     57    async function runTest() {
     58      selectSVG();
     59      await copyToClipboard();
     60 
     61      // Get the test-content before pasting, because pasting will duplicate
     62      // ids.
     63      const expectedPastedInnerHTML =
     64        SimpleTest.stripLinebreaksAndWhitespaceAfterTags(
     65          kIncludeCommonAncestor ? document.getElementById(kTestContentId).outerHTML
     66                                 : document.getElementById(kTestContentId).innerHTML);
     67 
     68      const pasteTargetElement = document.getElementById(kPasteTargetId);
     69      await pasteTo(pasteTargetElement);
     70 
     71      const pastedInnerHTMLWithoutLinebreaksAndWhitespaceAfterTags =
     72        SimpleTest.stripLinebreaksAndWhitespaceAfterTags(
     73          pasteTargetElement.innerHTML);
     74 
     75      is(pastedInnerHTMLWithoutLinebreaksAndWhitespaceAfterTags,
     76        expectedPastedInnerHTML,
     77        "Pasted HTML is as expected.");
     78 
     79      SimpleTest.finish()
     80    }
     81 
     82    function onLoad() {
     83      SimpleTest.waitForExplicitFinish();
     84      SimpleTest.waitForFocus(runTest);
     85    };
     86  </script>
     87 </head>
     88 <body onload="onLoad()">
     89  <h6>
     90    Test for <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1669050">bug 1669050</a>
     91  </h6>
     92 <div id="testContent">
     93  foo
     94  <svg>
     95    <image
     96     href="http://mochi.test:8888/tests/dom/base/test/name_of_some_image_file.png"
     97     height="200" width="200">
     98    </image>
     99  </svg>
    100  bar
    101 </div>
    102 <div contenteditable id="pasteTarget"/>
    103 </body>
    104 </html>