writeText-readText-on-detached-iframe.https.html (1752B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>navigator.clipboard readText and writeText 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 await tryGrantReadPermission(); 16 await tryGrantWritePermission(); 17 18 const iframe = document.getElementById('iframe'); 19 await waitForUserActivation(); 20 // Clipboard API must only be available in focused documents. 21 // reference: https://www.w3.org/TR/clipboard-apis/#privacy-async 22 iframe.focus(); 23 const iframeClipboard = iframe.contentWindow.navigator.clipboard; 24 25 // Writing and reading should succeed on same-origin iframes. 26 const attachedWriteText = 'attached write text' 27 await iframeClipboard.writeText(attachedWriteText); 28 const attachedWriteResult = await iframeClipboard.readText(); 29 assert_equals(attachedWriteResult, attachedWriteText, 30 'attached iframes should be able to readText and writeText normally'); 31 32 iframe.parentNode.removeChild(iframe); 33 // Writing onto a detached iframe's clipboard should fail, but not crash. 34 const detachedWriteText = 'detached write text'; 35 await iframeClipboard.writeText(detachedWriteText); 36 const readResultDetached = await iframeClipboard.readText(); 37 assert_equals(readResultDetached, undefined, 38 'reading from detached iframes should output undefined'); 39 }, 'Verify readText and writeText fails on detached iframe'); 40 </script>