Skip to content

Commit

Permalink
Handle load events
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres committed May 29, 2024
1 parent 7074de5 commit 739a448
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
await tryGrantWritePermission();

const iframe = document.getElementById('iframe');
await new Promise(resolve => {
iframe.onload = resolve;
iframe.src = 'about:blank';
});
const iframeClipboard = iframe.contentWindow.navigator.clipboard;
const blobInput = new Blob(['test string'], {type: 'text/plain'});
const clipboardItemInput = new ClipboardItem({'text/plain': blobInput});
await test_driver.bless();
await test_driver.bless("clipboard", null, iframe.contentWindow);

// Clipboard API must only be available in focused documents.
// reference: https://www.w3.org/TR/clipboard-apis/#privacy-async
iframe.focus();
Expand All @@ -34,7 +39,7 @@
assert_equals(readResultAttached.length, 1,
'attached iframes should be able to read and write normally');

iframe.parentNode.removeChild(iframe);
iframe.remove();
// Writing onto a detached iframe's clipboard should fail, but not crash.
await iframeClipboard.write([clipboardItemInput]);
const readResultDetached = await iframeClipboard.read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
await tryGrantWritePermission();

const iframe = document.getElementById('iframe');
await test_driver.bless();
await new Promise(resolve => {
iframe.onload = resolve;
iframe.src = 'about:blank';
});
await test_driver.bless("clipboard", null, iframe.contentWindow);
// Clipboard API must only be available in focused documents.
// reference: https://www.w3.org/TR/clipboard-apis/#privacy-async
iframe.focus();
Expand All @@ -29,7 +33,7 @@
assert_equals(attachedWriteResult, attachedWriteText,
'attached iframes should be able to readText and writeText normally');

iframe.parentNode.removeChild(iframe);
iframe.remove();
// Writing onto a detached iframe's clipboard should fail, but not crash.
const detachedWriteText = 'detached write text';
await iframeClipboard.writeText(detachedWriteText);
Expand Down

0 comments on commit 739a448

Please sign in to comment.