Bug 1514493 [wpt PR 14541] - Async Clipboard: ReadImageExperimental/WriteImageExperimental, a=testonly
authorDarwin Huang <huangdarwin@chromium.org>
Thu, 31 Jan 2019 18:55:17 +0000
changeset 457987 93e8279ba244f9c3ecab9dc2a5c69468b59070fd
parent 457986 249c9bd6e304a687a2edec887489b24a637610da
child 457988 fea5433464fdc96281f80c5c79a761354419aa10
push id35518
push useropoprus@mozilla.com
push dateFri, 08 Feb 2019 09:55:14 +0000
treeherdermozilla-central@3a3e393396f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1514493, 14541, 150835, 1345090, 622726
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-basics.https.html
testing/web-platform/tests/clipboard-apis/async-write-image-read-image-manual.https.html
testing/web-platform/tests/clipboard-apis/resources/greenbox.png
--- a/testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-basics.https.html
+++ b/testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-basics.https.html
@@ -1,11 +1,11 @@
 <!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>
 
 test(() => {
   assert_not_equals(navigator.clipboard, undefined);
   assert_true(navigator.clipboard instanceof Clipboard);
   assert_equals(navigator.clipboard, navigator.clipboard);
@@ -41,25 +41,47 @@ promise_test(async () => {
   await navigator.clipboard.writeText("New clipboard text");
 }, "navigator.clipboard.writeText(DOMString) succeeds");
 
 promise_test(async t => {
   await promise_rejects(t, new TypeError(),
                          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() */
 
 promise_test(async () => {
   const result = await navigator.clipboard.read();
   assert_true(result instanceof DataTransfer);
 }, "navigator.clipboard.read() succeeds");
 
 
 /* clipboard.readText() */
 
 promise_test(async () => {
   const result = await navigator.clipboard.readText();
   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>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/clipboard-apis/async-write-image-read-image-manual.https.html
@@ -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.
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6e555e3b197ce2f448f59d61e1488a0175490145
GIT binary patch
literal 95
zc%17D@N?(olHy`uVBq!ia0vp^k|4~%1SGw?g-n2ynx~6nNX49_gdgV}Oii+`t%zKl
l);r4-!bnsAs$ls4pPAumLEgGv<4v6)zNf37%Q~loCIC3!8-xG=