async-navigator-clipboard-read-resource-load.https.html (1583B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>Async Clipboard.read() should not trigger resource loading</title> 4 <link rel="help" href="https://w3c.github.io/clipboard-apis/#dom-clipboard-read"> 5 <link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1315563"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-vendor.js"></script> 10 <script src="resources/user-activation.js"></script> 11 12 <body>Body needed for test_driver.click() 13 <p><button id="button">Put payload in the clipboard</button></p> 14 <div id="output"></div> 15 16 <script> 17 button.onclick = () => document.execCommand('copy'); 18 document.oncopy = ev => { 19 ev.preventDefault(); 20 ev.clipboardData.setData( 21 'text/html', 22 '<img src="https://example.com/oops">'); 23 }; 24 25 promise_test(async test => { 26 let loadObserved = false; 27 const observer = new PerformanceObserver(() => loadObserved = true); 28 observer.observe({type: 'resource'}); 29 await tryGrantReadPermission(); 30 await test_driver.click(button); 31 32 await waitForUserActivation(); 33 const items = await navigator.clipboard.read(); 34 const htmlBlob = await items[0].getType("text/html"); 35 const html = await htmlBlob.text(); 36 37 assert_true(html.includes('<img src="https://example.com/oops">')); 38 39 // Allow resource loading to start asynchronously 40 await new Promise(resolve => test.step_timeout(resolve, 100)); 41 assert_false(loadObserved, 'Should not observe resource loading'); 42 }); 43 </script> 44 </body>