async-write-blobs-read-blobs.https.html (2291B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title> 4 Async Clipboard write blobs -> read blobs 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 await tryGrantReadPermission(); 22 await tryGrantWritePermission(); 23 24 const blobText = new Blob(['test text'], {type: 'text/plain'}); 25 const blobImage = await loadBlob('resources/greenbox.png'); 26 27 assert_equals(blobText.type, 'text/plain'); 28 assert_equals(blobImage.type, 'image/png'); 29 30 const clipboardItemInput = new ClipboardItem( 31 {'text/plain' : blobText, 'image/png' : blobImage}); 32 33 await waitForUserActivation(); 34 await navigator.clipboard.write([clipboardItemInput]); 35 await waitForUserActivation(); 36 const clipboardItems = await navigator.clipboard.read(); 37 38 assert_equals(clipboardItems.length, 1); 39 const clipboardItem = clipboardItems[0]; 40 assert_true(clipboardItem instanceof ClipboardItem); 41 42 assert_equals(clipboardItem.types.length, 2); 43 const blobTextOutput = await clipboardItem.getType('text/plain'); 44 const blobImageOutput = await clipboardItem.getType('image/png'); 45 assert_equals(blobTextOutput.type, 'text/plain'); 46 assert_equals(blobImageOutput.type, 'image/png'); 47 }, 'Verify write and read clipboard (multiple types)'); 48 49 promise_test(async () => { 50 await tryGrantReadPermission(); 51 await tryGrantWritePermission(); 52 const text_blob = new Blob(['hello'], {type: 'text/plain'}); 53 const html_blob = new Blob(undefined, {type: 'text/html'}); 54 const item = new ClipboardItem({'text/plain': text_blob, 'text/html': html_blob}); 55 56 await waitForUserActivation(); 57 await navigator.clipboard.write([item]); 58 await waitForUserActivation(); 59 const [clipboardItem] = await navigator.clipboard.read(); 60 }, 'navigator.clipboard.read() does not crash if clipboard data has null values'); 61 62 </script>