Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipboard API: use bless() instead #37098

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
customFormatMap[customFormatArray[i]] = blobInput;
}
const clipboardItemInput = new ClipboardItem(customFormatMap);
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.write([clipboardItemInput]));
}, 'navigator.clipboard.write() fails for more than 100 custom formats');
Expand All @@ -36,7 +36,7 @@
const blobInput2 = new Blob(['input data 2'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1, [format2]: blobInput2});
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.write([clipboardItemInput]));
}, 'navigator.clipboard.write() fails for custom formats without web prefix');
Expand All @@ -50,7 +50,7 @@
const blobInput2 = new Blob(['input data 2'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1, [format2]: blobInput2});
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.write([clipboardItemInput]));
}, 'navigator.clipboard.write() fails for custom formats with web prefix, but invalid MIME types');
Expand All @@ -63,7 +63,7 @@
const blobInput1 = new Blob(['input data 1'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1});
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.write([clipboardItemInput]));
}, 'navigator.clipboard.write() fails for custom format with web prefix, but different Blob type');
Expand All @@ -76,7 +76,7 @@
const blobInput1 = new Blob(['input data 1'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1});
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.write([clipboardItemInput]));
}, 'navigator.clipboard.write() fails for custom format with different case than the Blob type');
Expand All @@ -89,7 +89,7 @@
const blobInput1 = new Blob(['input data 1'], {type: format1});
const clipboardItemInput = new ClipboardItem(
{[format2]: blobInput1});
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.write([clipboardItemInput]));
}, 'navigator.clipboard.write() fails for invalid mime type that is different than the Blob type');
Expand All @@ -102,7 +102,7 @@
const blobInput1 = new Blob(['input data 1'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1});
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.write([clipboardItemInput]));
}, 'navigator.clipboard.write() fails for invalid mime type with web prefix and the Blob type');
Expand All @@ -115,7 +115,7 @@
const blobInput1 = new Blob(['input data 1'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1});
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.write([clipboardItemInput]));
}, 'navigator.clipboard.write() fails for custom format and Blob type with different case');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
const blobInput1 = new Blob(['input data 1'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItemInput]);
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();
assert_equals(clipboardItems.length, 1);
const clipboardItem = clipboardItems[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
const blobInput1 = new Blob(['input data 1'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItemInput]);
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();
assert_equals(clipboardItems.length, 1);
const clipboardItem = clipboardItems[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
const blobInput2 = new Blob(['input data 2'], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1, [format2]: blobInput2});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItemInput]);

// Items should be readable on a custom format clipboard after custom format
// write.
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();
assert_equals(clipboardItems.length, 1);
const clipboardItem = clipboardItems[0];
Expand Down
4 changes: 2 additions & 2 deletions clipboard-apis/async-html-script-removal.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
await tryGrantWritePermission();
const blobInput = new Blob([html_with_script], {type: 'text/html'});
const clipboardItem = new ClipboardItem({'text/html': blobInput});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItem]);
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();

const html = clipboardItems[0];
Expand Down
2 changes: 1 addition & 1 deletion clipboard-apis/async-navigator-clipboard-basics.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
async function getPermissions() {
await tryGrantReadPermission();
await tryGrantWritePermission();
await waitForUserActivation();
await test_driver.bless();
}

test(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
await tryGrantReadPermission();
await test_driver.click(button);

await waitForUserActivation();
await test_driver.bless();
const items = await navigator.clipboard.read();
const htmlBlob = await items[0].getType("text/html");
const html = await htmlBlob.text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
await tryGrantReadPermission();
await test_driver.click(button);

await waitForUserActivation();
await test_driver.bless();
const items = await navigator.clipboard.read();
const htmlBlob = await items[0].getType("text/html");
const html = await htmlBlob.text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
async function getPermissions() {
await tryGrantReadPermission();
await tryGrantWritePermission()
await waitForUserActivation();
await test_driver.bless();
}

function waitForMessage(msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

const clipboardItemInput = new ClipboardItem(
{'text/plain' : blobText, 'image/png' : promise1});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItemInput]);
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();

assert_equals(clipboardItems.length, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
const blobInput2 = new Blob([textInput], {type: format2});
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1, [format2]: blobInput2});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItemInput]);

// Read unsanitized version of HTML format.
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();

assert_equals(clipboardItems.length, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
assert_equals(blobInput2.type, format2.toLowerCase());
const clipboardItemInput = new ClipboardItem(
{[format1]: blobInput1, [format2]: blobInput2});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItemInput]);

// Items should be readable on a system clipboard after custom format write.
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();
assert_equals(clipboardItems.length, 1);
const clipboardItem = clipboardItems[0];
Expand All @@ -45,7 +45,7 @@

// These examples use native text formats, so these formats should be
// accessible as text.
await waitForUserActivation();
await test_driver.bless();
const textOutput = await navigator.clipboard.readText();
assert_equals(textOutput, dataToWrite);
}, 'Verify write and read unsanitized content to the clipboard given standard and custom formats as input');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@
promise_test(async t => {
await tryGrantReadPermission();

await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.read({unsanitized: ['text/html', 'text/plain']}));
}, 'navigator.clipboard.read() fails for multiple unsanitized formats requested.');

promise_test(async t => {
await tryGrantReadPermission();

await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.read({unsanitized: ['text/plain']}));
}, 'navigator.clipboard.read() fails for unsanitized text/plain requested.');

promise_test(async t => {
await tryGrantReadPermission();

await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.read({unsanitized: ['image/png']}));
}, 'navigator.clipboard.read() fails for unsanitized image/png requested.');

promise_test(async t => {
await tryGrantReadPermission();

await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.read({unsanitized: ['image/svg+xml']}));
}, 'navigator.clipboard.read() fails for unsanitized image/svg+xml requested.');
Expand Down
4 changes: 2 additions & 2 deletions clipboard-apis/async-write-blobs-read-blobs.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
const clipboardItemInput = new ClipboardItem(
{'text/plain' : blobText, 'image/png' : blobImage});

await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItemInput]);
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();

assert_equals(clipboardItems.length, 1);
Expand Down
4 changes: 2 additions & 2 deletions clipboard-apis/async-write-html-read-html.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
await tryGrantWritePermission();
const blobInput = new Blob([textInput], {type: 'text/html'});
const clipboardItem = new ClipboardItem({'text/html': blobInput});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItem]);
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read({type: 'text/html'});

const html = clipboardItems[0];
Expand Down
6 changes: 3 additions & 3 deletions clipboard-apis/async-write-image-read-image.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@

assert_equals(blobInput.type, 'image/png');
const clipboardItemInput = new ClipboardItem({'image/png' : blobInput});
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.write([clipboardItemInput]);
await waitForUserActivation();
await test_driver.bless();
const clipboardItems = await navigator.clipboard.read();

assert_equals(clipboardItems.length, 1);
Expand All @@ -77,7 +77,7 @@
const invalidPngBlob = new Blob(['this text is not a valid png image'],
{type: 'image/png'});
const clipboardItemInput = new ClipboardItem({'image/png' : invalidPngBlob});
await waitForUserActivation();
await test_driver.bless();
await promise_rejects_dom(t, 'DataError',
navigator.clipboard.write([clipboardItemInput]));
}, 'Verify write error on malformed data [image/png ClipboardItem]');
Expand Down
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';
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm? Are we sure loading about:blank is synchronous everywhere? The existing wait code in waitForUserActivation is better IMO.

And we probably should still have a helper function for this.

const iframeClipboard = iframe.contentWindow.navigator.clipboard;
const blobInput = new Blob(['test string'], {type: 'text/plain'});
const clipboardItemInput = new ClipboardItem({'text/plain': blobInput});
await waitForUserActivation();
await test_driver.bless("clipboard", null, iframe.contentWindow);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this change the test behavior here? Previously it clicked the parent page and now this clicks the iframe. wpt.fyi reports no change though.

And should the intent argument be passed consistently?


// 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 waitForUserActivation();
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// only, cross-origin focus is asynchronous. Implement WPT support for
// cross-origin focus.
promise_test(async t => {
await waitForUserActivation();
await test_driver.bless();
test_feature_availability(
'navigator.clipboard.readText()',
t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'/feature-policy/resources/feature-policy-clipboard-read.html';

promise_test(async t => {
await waitForUserActivation();
await test_driver.bless();
test_feature_availability(
'navigator.clipboard.readText()',
t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// only, cross-origin focus is asynchronous. Implement WPT support for
// cross-origin focus.
promise_test(async t => {
await waitForUserActivation();
await test_driver.bless();
test_feature_availability(
'navigator.clipboard.readText()',
t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

promise_test(async t => {
await tryGrantReadPermission();
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.readText('test text');
}, 'Feature-Policy header clipboard-read "*" allows the top-level document.');

promise_test(async t => {
await waitForUserActivation();
await test_driver.bless();
test_feature_availability(
'navigator.clipboard.readText()',
t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

promise_test(async t => {
await tryGrantReadPermission();
await waitForUserActivation();
await test_driver.bless();
await navigator.clipboard.readText('test text');
}, 'Feature-Policy header clipboard-read "self" allows the top-level document.');

promise_test(async t => {
await waitForUserActivation();
await test_driver.bless();
test_feature_availability(
'navigator.clipboard.readText()',
t,
Expand Down
Loading