tor-browser

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

write-read-on-detached-iframe.https.html (1975B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>navigator.clipboard read and write on detached iframe</title>
      4 <link rel='help' href='https://w3c.github.io/clipboard-apis/#async-clipboard-api'>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/resources/testdriver.js"></script>
      8 <script src="/resources/testdriver-vendor.js"></script>
      9 <script src="../resources/user-activation.js"></script>
     10 <iframe id="iframe"></iframe>
     11 <script>
     12 'use strict';
     13 
     14 promise_test(async t => {
     15  // This tests proper behavior on a detaching iframe. text/plain is chosen for
     16  // simplicity, and the test should fail the same way no matter what the input
     17  // type is.
     18  await tryGrantReadPermission();
     19  await tryGrantWritePermission();
     20 
     21  const iframe = document.getElementById('iframe');
     22  const iframeClipboard = iframe.contentWindow.navigator.clipboard;
     23  const blobInput = new Blob(['test string'], {type: 'text/plain'});
     24  const clipboardItemInput = new ClipboardItem({'text/plain': blobInput});
     25  await waitForUserActivation();
     26  // Clipboard API must only be available in focused documents.
     27  // reference: https://www.w3.org/TR/clipboard-apis/#privacy-async
     28  iframe.focus();
     29 
     30  // Writing and reading should succeed on same-origin iframes.
     31  await iframeClipboard.write([clipboardItemInput]);
     32  const readResultAttached = await iframeClipboard.read();
     33  assert_not_equals(readResultAttached, undefined);
     34  assert_equals(readResultAttached.length, 1,
     35      'attached iframes should be able to read and write normally');
     36 
     37  iframe.parentNode.removeChild(iframe);
     38  // Writing onto a detached iframe's clipboard should fail, but not crash.
     39  await iframeClipboard.write([clipboardItemInput]);
     40  const readResultDetached = await iframeClipboard.read();
     41  assert_equals(readResultDetached, undefined,
     42      'reading from detached iframes should output undefined');
     43 }, 'Verify read and write fail on detached iframe');
     44 </script>