tor-browser

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

async-promise-write-blobs-read-blobs.https.html (1717B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>
      4  Async Clipboard write blobs -> read blobs with promise tests
      5 </title>
      6 <link rel="help" href="https://w3c.github.io/clipboard-apis/#async-clipboard-api">
      7 <body>Body needed for test_driver.click()</body>
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src="/resources/testdriver.js"></script>
     11 <script src="/resources/testdriver-vendor.js"></script>
     12 <script src="resources/user-activation.js"></script>
     13 
     14 <script>
     15 async function loadBlob(fileName) {
     16  const fetched = await fetch(fileName);
     17  return await fetched.blob();
     18 }
     19 
     20 promise_test(async t => {
     21  const promise1 = new Promise((resolve, reject) => {
     22    resolve(loadBlob('resources/greenbox.png'));
     23  });
     24  await tryGrantReadPermission();
     25  await tryGrantWritePermission();
     26 
     27  const blobText = new Blob(['test text'], {type: 'text/plain'});
     28 
     29  const clipboardItemInput = new ClipboardItem(
     30        {'text/plain' : blobText, 'image/png' : promise1});
     31  await waitForUserActivation();
     32  await navigator.clipboard.write([clipboardItemInput]);
     33  await waitForUserActivation();
     34  const clipboardItems = await navigator.clipboard.read();
     35 
     36  assert_equals(clipboardItems.length, 1);
     37  const clipboardItem = clipboardItems[0];
     38  assert_true(clipboardItem instanceof ClipboardItem);
     39 
     40  assert_equals(clipboardItem.types.length, 2);
     41  const blobTextOutput = await clipboardItem.getType('text/plain');
     42  const blobImageOutput = await clipboardItem.getType('image/png');
     43  assert_equals(blobTextOutput.type, 'text/plain');
     44  assert_equals(blobImageOutput.type, 'image/png');
     45 }, 'Verify write and read clipboard (multiple types) with promise to Blobs');
     46 </script>