<!doctype html>
<meta charset="utf-8">
<title>
Async Clipboard write garbage collection race condition test
</title>
<body>Body needed for test_driver.click()</body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/testdriver.js"></script>
<script src="../../resources/testdriver-vendor.js"></script>
<script src="resources/user-activation.js"></script>
<script>
promise_test(async t => {
await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const blobText = new Blob(['test text'], {type: 'text/plain'});
const clipboardItemInput = new ClipboardItem(
{'text/plain' : blobText});
await waitForUserActivation();
const promise = navigator.clipboard.write([clipboardItemInput]);
for (let i = 0; i < 10; ++i) {
// TODO(https://github.com/web-platform-tests/wpt/issues/7899): Support
// cross-browser GC triggers, and move this test to the Web Platform
// Test suite.
if(window.gc) {
window.gc();
}
await new Promise(resolve => setTimeout(resolve, 0));
}
await promise;
}, 'Verify write clipboard avoids garbage collection race condition.');
</script>