async-writeText-read.https.html (1500B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title> 4 Async Clipboard writeText -> read ([text/plain ClipboardItem]) 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 <script> 14 async function readWriteTest(textInput) { 15 promise_test(async t => { 16 await tryGrantReadPermission(); 17 await tryGrantWritePermission(); 18 19 await waitForUserActivation(); 20 await navigator.clipboard.writeText(textInput); 21 await waitForUserActivation(); 22 const clipboardItems = await navigator.clipboard.read(); 23 assert_equals(clipboardItems.length, 1); 24 const clipboardItem = clipboardItems[0]; 25 assert_true(clipboardItem instanceof ClipboardItem); 26 assert_equals(clipboardItem.types.length, 1); 27 const blobOutput = await clipboardItem.getType('text/plain'); 28 assert_equals(blobOutput.type, 'text/plain'); 29 30 const textOutput = await (new Response(blobOutput)).text(); 31 assert_equals(textOutput, textInput); 32 }, 'Verify write and read clipboard given text: ' + textInput); 33 } 34 35 readWriteTest('Clipboard write text -> read ([text/plain ClipboardItem]) test'); 36 readWriteTest('non-Latin1 text encoding test データ'); 37 </script>