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>
17 button
.onclick
= () => document
.execCommand('copy');
18 document
.oncopy
= ev
=> {
20 ev
.clipboardData
.setData(
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');