Bug 1532248 [wpt PR 15609] - Async Clipboard: Read/Write Blob->sequence<Blob>, a=testonly

Automatic update from web-platform-tests
Async Clipboard: Read/Write Blob->sequence<Blob>

- read(Blob) updated to read(sequence<Blob>).
- write() returns sequence<Blob> instead of Blob now.
- All available and valid types are returned in read() or allowed for write().
- Tests updated and added for these API changes.

Also:
- Updated header file function ordering.
- Duplicate MIME types not allowed on write (consistent w/existing clipboard).

Bug: 150835
Change-Id: I5b08e648a5313222552757dfa6fa0db6a7e46f68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1471492
Commit-Queue: Darwin Huang <huangdarwin@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638905}

--

wpt-commits: 3eb820dcc7cc5255f7182080caf9bd56f04d3cc2
wpt-pr: 15609
This commit is contained in:
Darwin Huang 2019-03-26 14:04:37 +00:00 коммит произвёл James Graham
Родитель da46e66a24
Коммит 1f81a8ba21
7 изменённых файлов: 97 добавлений и 42 удалений

Просмотреть файл

@ -11,32 +11,25 @@ test(() => {
assert_equals(navigator.clipboard, navigator.clipboard); assert_equals(navigator.clipboard, navigator.clipboard);
}, "navigator.clipboard exists"); }, "navigator.clipboard exists");
/* clipboard.write(text/plain Blob) */
promise_test(async () => { promise_test(async () => {
const blob = new Blob(["hello"], {type: 'text/plain'}); const blob = new Blob(["hello"], {type: 'text/plain'});
await navigator.clipboard.write(blob); await navigator.clipboard.write([blob]);
}, "navigator.clipboard.write(text/plain Blob) succeeds"); }, "navigator.clipboard.write([text/plain Blob]) succeeds");
/* clipboard.write(invalid input) */
promise_test(async t => { promise_test(async t => {
await promise_rejects(t, new TypeError(), await promise_rejects(t, new TypeError(),
navigator.clipboard.write()); navigator.clipboard.write());
}, "navigator.clipboard.write() fails (expect Blob)"); }, "navigator.clipboard.write() fails (expect [Blob])");
promise_test(async t => { promise_test(async t => {
await promise_rejects(t, new TypeError(), await promise_rejects(t, new TypeError(),
navigator.clipboard.write(null)); navigator.clipboard.write(null));
}, "navigator.clipboard.write(null) fails (expect Blob)"); }, "navigator.clipboard.write(null) fails (expect [Blob])");
promise_test(async t => { promise_test(async t => {
await promise_rejects(t, new TypeError(), await promise_rejects(t, new TypeError(),
navigator.clipboard.write("Bad string")); navigator.clipboard.write("Bad string"));
}, "navigator.clipboard.write(DOMString) fails (expect Blob)"); }, "navigator.clipboard.write(DOMString) fails (expect [Blob])");
/* clipboard.writeText() */
promise_test(async () => { promise_test(async () => {
await navigator.clipboard.writeText("New clipboard text"); await navigator.clipboard.writeText("New clipboard text");
@ -47,27 +40,21 @@ promise_test(async t => {
navigator.clipboard.writeText()); navigator.clipboard.writeText());
}, "navigator.clipboard.writeText() fails (expect DOMString)"); }, "navigator.clipboard.writeText() fails (expect DOMString)");
/* clipboard.write(image/png Blob) */
promise_test(async () => { promise_test(async () => {
const fetched = await fetch( const fetched = await fetch(
'http://localhost:8001/clipboard-apis/resources/greenbox.png'); 'http://localhost:8001/clipboard-apis/resources/greenbox.png');
const image = await fetched.blob(); const image = await fetched.blob();
await navigator.clipboard.write(image); await navigator.clipboard.write([image]);
}, "navigator.clipboard.write(image/png Blob) succeeds"); }, "navigator.clipboard.write([image/png Blob]) succeeds");
/* text/plain or image/png Blob clipboard.read() */
promise_test(async () => { promise_test(async () => {
const result = await navigator.clipboard.read(); const result = await navigator.clipboard.read();
assert_true(result instanceof Blob); assert_true(result instanceof Array);
assert_true(result[0] instanceof Blob);
assert_equals(typeof result, "object"); assert_equals(typeof result, "object");
}, "navigator.clipboard.read() succeeds"); }, "navigator.clipboard.read() succeeds");
/* clipboard.readText() */
promise_test(async () => { promise_test(async () => {
const result = await navigator.clipboard.readText(); const result = await navigator.clipboard.readText();
assert_equals(typeof result, "string"); assert_equals(typeof result, "string");

Просмотреть файл

@ -0,0 +1,34 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>
Async Clipboard write blobs -> read blobs tests
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async function loadBlob(fileName) {
const fetched = await fetch(fileName);
return await fetched.blob();
}
promise_test(async t => {
const blobText = new Blob(["test text"], {type: 'text/plain'});
const blobImage = await loadBlob('resources/greenbox.png');
assert_equals(blobText.type, "text/plain");
assert_equals(blobImage.type, "image/png");
await navigator.clipboard.write([blobText, blobImage]);
const output = await navigator.clipboard.read();
assert_equals(output.length, 2);
assert_equals(output[0].type, "text/plain");
assert_equals(output[1].type, "image/png");
}, "Verify write and read clipboard (multiple blobs)");
</script>
<p>
Note: This is a manual test because it writes/reads to the shared system
clipboard and thus cannot be run async with other tests that might interact
with the clipboard.
</p>

Просмотреть файл

@ -1,6 +1,8 @@
<!DOCTYPE html> <!DOCTYPE html>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Async Clipboard write (text/plain Blob) -> read (text/plain Blob) tests</title> <title>
Async Clipboard write ([text/plain Blob]) -> read ([text/plain Blob]) tests
</title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script> <script>
@ -8,8 +10,10 @@ async function readWriteTest(textInput) {
promise_test(async t => { promise_test(async t => {
const blobInput = new Blob([textInput], {type: 'text/plain'}); const blobInput = new Blob([textInput], {type: 'text/plain'});
await navigator.clipboard.write(blobInput); await navigator.clipboard.write([blobInput]);
const blobOutput = await navigator.clipboard.read(); const blobsOutput = await navigator.clipboard.read();
assert_equals(blobsOutput.length, 1);
const blobOutput = blobsOutput[0];
assert_equals(blobOutput.type, "text/plain"); assert_equals(blobOutput.type, "text/plain");
const textOutput = await (new Response(blobOutput)).text(); const textOutput = await (new Response(blobOutput)).text();
@ -17,7 +21,7 @@ async function readWriteTest(textInput) {
}, "Verify write and read clipboard given text: " + textInput); }, "Verify write and read clipboard given text: " + textInput);
} }
readWriteTest("Clipboard write (text/plain Blob) -> read (text/plain Blob) test"); readWriteTest("Clipboard write ([text/plain Blob]) -> read ([text/plain Blob]) test");
readWriteTest("non-Latin1 text encoding test データ"); readWriteTest("non-Latin1 text encoding test データ");
</script> </script>
<p> <p>

Просмотреть файл

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Async Clipboard write (text/plain Blob) -> readText tests</title> <title>Async Clipboard write ([text/plain Blob]) -> readText tests</title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script> <script>
@ -8,14 +8,14 @@ async function readWriteTest(textInput) {
promise_test(async t => { promise_test(async t => {
const blobInput = new Blob([textInput], {type: 'text/plain'}); const blobInput = new Blob([textInput], {type: 'text/plain'});
await navigator.clipboard.write(blobInput); await navigator.clipboard.write([blobInput]);
const textOutput = await navigator.clipboard.readText(); const textOutput = await navigator.clipboard.readText();
assert_equals(textOutput, textInput); assert_equals(textOutput, textInput);
}, "Verify write and read clipboard given text: " + textInput); }, "Verify write and read clipboard given text: " + textInput);
} }
readWriteTest("Clipboard write (text/plain Blob) -> read text test"); readWriteTest("Clipboard write ([text/plain Blob]) -> read text test");
readWriteTest("non-Latin1 text encoding test データ"); readWriteTest("non-Latin1 text encoding test データ");
</script> </script>
<p> <p>

Просмотреть файл

@ -0,0 +1,26 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>
Async Clipboard write duplicate mime type test
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
const blobText = new Blob(["test text"], {type: 'text/plain'});
const blobText2 = new Blob(["test text"], {type: 'text/plain'});
assert_equals(blobText.type, "text/plain");
assert_equals(blobText2.type, "text/plain");
await promise_rejects(t, 'NotAllowedError',
navigator.clipboard.write([blobText, blobText2]));
}, "Verify write and read clipboard (multiple blobs)");
</script>
<p>
Note: This is a manual test because it writes/reads to the shared system
clipboard and thus cannot be run async with other tests that might interact
with the clipboard.
</p>

Просмотреть файл

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<meta charset="utf-8"> <meta charset="utf-8">
<title> <title>
Async Clipboard write image/png Blob -> read image/png Blob tests Async Clipboard write [image/png Blob] -> read [image/png Blob] tests
</title> </title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
@ -37,21 +37,23 @@ async function loadBlob(fileName) {
} }
promise_test(async t => { promise_test(async t => {
const input = await loadBlob('resources/greenbox.png'); const blobInput = await loadBlob('resources/greenbox.png');
assert_equals(input.type, "image/png"); assert_equals(blobInput.type, "image/png");
await navigator.clipboard.write(input); await navigator.clipboard.write([blobInput]);
const output = await navigator.clipboard.read(); const blobsOutput = await navigator.clipboard.read();
assert_equals(output.type, "image/png"); assert_equals(blobsOutput.length, 1);
const blobOutput = blobsOutput[0];
assert_equals(blobOutput.type, "image/png");
document.getElementById('image-on-clipboard').src = document.getElementById('image-on-clipboard').src =
window.URL.createObjectURL(output); window.URL.createObjectURL(blobOutput);
const comparableInput = await getBitmapString(input); const comparableInput = await getBitmapString(blobInput);
const comparableOutput = await getBitmapString(output); const comparableOutput = await getBitmapString(blobOutput);
assert_equals(comparableOutput, comparableInput); assert_equals(comparableOutput, comparableInput);
}, "Verify write and read clipboard (DOMString)"); }, "Verify write and read clipboard ([image/png Blob])");
</script> </script>
<p> <p>
Note: This is a manual test because it writes/reads to the shared system Note: This is a manual test because it writes/reads to the shared system

Просмотреть файл

@ -1,13 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Async Clipboard writeText -> read (text/plain Blob) tests</title> <title>Async Clipboard writeText -> read ([text/plain Blob]) tests</title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script> <script>
async function readWriteTest(textInput) { async function readWriteTest(textInput) {
promise_test(async t => { promise_test(async t => {
await navigator.clipboard.writeText(textInput); await navigator.clipboard.writeText(textInput);
const blobOutput = await navigator.clipboard.read(); const blobsOutput = await navigator.clipboard.read();
assert_equals(blobsOutput.length, 1);
const blobOutput = blobsOutput[0];
assert_equals(blobOutput.type, "text/plain"); assert_equals(blobOutput.type, "text/plain");
const textOutput = await (new Response(blobOutput)).text(); const textOutput = await (new Response(blobOutput)).text();
@ -15,7 +17,7 @@ async function readWriteTest(textInput) {
}, "Verify write and read clipboard given text: " + textInput); }, "Verify write and read clipboard given text: " + textInput);
} }
readWriteTest("Clipboard write text -> read (text/plain Blob) test"); readWriteTest("Clipboard write text -> read ([text/plain Blob]) test");
readWriteTest("non-Latin1 text encoding test データ"); readWriteTest("non-Latin1 text encoding test データ");
</script> </script>
<p> <p>