mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 12:15:33 +00:00
Bug 1514493 [wpt PR 14541] - Async Clipboard: ReadImageExperimental/WriteImageExperimental, a=testonly
Automatic update from web-platform-tests Async Clipboard: ReadImageExperimental/WriteImageExperimental API Goal: - Async Clipboard functionality to ReadImageExperimental() and WriteImageExperimental() - JS layer will send Blobs with MIME type "image/png" - Images will be "safe", as we'll re-encode to strip potentially dangerous metadata and protect from arbitrary code execution. Only image types supported by the Skia library will be supported for this initial POC. - First release into experimental with this ReadImageExperimental()/WriteImageExperimental() - Later integrate into Read()/Write() and remove ReadImageExperimental()/WriteImageExperimental() Features: - FileReader used to read Blobs asynchronously. - Image Decoding on a separate thread. - Image read/write accomplished, where Images are represented by Blobs holding MIME type "image/png" Bug: 150835 Change-Id: I4380116642b4720bb9773185eb2e28757688c5ec Reviewed-on: https://chromium-review.googlesource.com/c/1345090 Commit-Queue: Darwin Huang <huangdarwin@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Gary Kacmarcik <garykac@chromium.org> Cr-Commit-Position: refs/heads/master@{#622726} -- wpt-commits: 1561bbb52522453394f599f80d941d474a35d7eb wpt-pr: 14541
This commit is contained in:
parent
def66880ae
commit
1f2ebf236d
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Async Clipboard basic tests</title>
|
||||
<title>Async Clipboard input type validation tests</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
@ -46,6 +46,21 @@ promise_test(async t => {
|
||||
navigator.clipboard.writeText());
|
||||
}, "navigator.clipboard.writeText() fails (expect DOMString)");
|
||||
|
||||
/* clipboard.writeImageExperimental() */
|
||||
|
||||
promise_test(async () => {
|
||||
const fetched = await fetch(
|
||||
'http://localhost:8001/clipboard-apis/resources/greenbox.png');
|
||||
const image = await fetched.blob();
|
||||
|
||||
await navigator.clipboard.writeImageExperimental(image);
|
||||
}, "navigator.clipboard.writeImageExperimental(Blob) succeeds");
|
||||
|
||||
promise_test(async t => {
|
||||
await promise_rejects(t, new TypeError(),
|
||||
navigator.clipboard.writeImageExperimental());
|
||||
}, "navigator.clipboard.writeImageExperimental() fails (expect Blob)");
|
||||
|
||||
|
||||
/* clipboard.read() */
|
||||
|
||||
@ -62,4 +77,11 @@ promise_test(async () => {
|
||||
assert_equals(typeof result, "string");
|
||||
}, "navigator.clipboard.readText() succeeds");
|
||||
|
||||
/* clipboard.readImageExperimental() */
|
||||
|
||||
promise_test(async () => {
|
||||
const result = await navigator.clipboard.readImageExperimental();
|
||||
assert_equals(typeof result, "object");
|
||||
}, "navigator.clipboard.readImageExperimental() succeeds");
|
||||
|
||||
</script>
|
||||
|
@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>
|
||||
Async Clipboard writeImageExperimental -> readImageExperimental tests
|
||||
</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
|
||||
<div>Original Image:</div>
|
||||
<image id='image-to-copy' src="resources/greenbox.png"></image>
|
||||
<div>Image after copy/paste:</div>
|
||||
<image id='image-on-clipboard'></image>
|
||||
|
||||
<canvas id="canvas" width="30" height="30"></canvas>
|
||||
|
||||
<script>
|
||||
// Must compare a bitmap as opposed to simply blob data, because an encoded
|
||||
// image may have different contents depending on encoder.
|
||||
const getBitmapString = async blob => {
|
||||
const imageBitmap = await createImageBitmap(blob);
|
||||
const canvas = document.getElementById('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
ctx.drawImage(imageBitmap, 0,0);
|
||||
|
||||
let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
return imageData.data.toString();
|
||||
};
|
||||
|
||||
const loadBlob = async fileName => {
|
||||
const fetched = await fetch(fileName);
|
||||
return await fetched.blob();
|
||||
}
|
||||
|
||||
promise_test(async t => {
|
||||
const input = await loadBlob(
|
||||
'http://localhost:8001/clipboard-apis/resources/greenbox.png');
|
||||
|
||||
await navigator.clipboard.writeImageExperimental(input);
|
||||
const output = await navigator.clipboard.readImageExperimental();
|
||||
|
||||
document.getElementById('image-on-clipboard').src =
|
||||
window.URL.createObjectURL(output);
|
||||
|
||||
const comparableInput = await getBitmapString(input);
|
||||
const comparableOutput = await getBitmapString(output);
|
||||
|
||||
assert_equals(comparableOutput, comparableInput);
|
||||
}, "Verify write and read clipboard (DOMString)");
|
||||
</script>
|
||||
<br/><br/>
|
||||
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.
|
||||
<br/><br/>
|
||||
The bottom image should display the same image as the top image.
|
BIN
testing/web-platform/tests/clipboard-apis/resources/greenbox.png
Normal file
BIN
testing/web-platform/tests/clipboard-apis/resources/greenbox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 95 B |
Loading…
Reference in New Issue
Block a user