Bug 1770047 [wpt PR 34117] - [Clipboard API] Clipboard Web Custom Formats implementat...
[gecko.git] / testing / web-platform / tests / clipboard-apis / async-navigator-clipboard-read-resource-load.https.html
blobd1e3019e7f939965f6814436752e92a44ecb1b25
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>
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>
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">');
25 promise_test(async test => {
26 let loadObserved = false;
27 const observer = new PerformanceObserver(() => loadObserved = true);
28 observer.observe({type: 'resource'});
29 await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
30 await test_driver.click(button);
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();
37 assert_equals(html, '<img src="https://example.com/oops">');
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>