write-on-detaching-iframe.https.html (1520B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>navigator.clipboard write on detaching 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 // Clipboard API must only be available in focused documents. 26 // reference: https://www.w3.org/TR/clipboard-apis/#privacy-async 27 iframe.focus(); 28 29 // An iframe detaching while writing to the clipboard should fail, but not 30 // crash. The lack of await here means that the iframe will detach while the 31 // write operation is running. 32 iframeClipboard.write([clipboardItemInput]); 33 iframe.parentNode.removeChild(iframe); 34 }, 'Verify write fails on detaching iframe'); 35 </script>