Bug 1733562 [wpt PR 31040] - [Clipboard API] Add support for Promise to Blobs in clipboard item., a=testonly
authorAnupam Snigdha <snianu@microsoft.com>
Sat, 27 Nov 2021 09:47:59 +0000
changeset 600499 bab641f2a55059e9a4106134f23e1e867ed3dbab
parent 600498 f33a851e0a6e1ef9323fea1a17ac79f397ec12d6
child 600500 b09ba3a52dd160f6fbf4591cba62175a8f4f7693
push id39022
push userimoraru@mozilla.com
push dateTue, 30 Nov 2021 04:22:47 +0000
treeherdermozilla-central@58d2fbdb6b4a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1733562, 31040, 1014310, 3169593, 945323
milestone96.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 1733562 [wpt PR 31040] - [Clipboard API] Add support for Promise to Blobs in clipboard item., a=testonly Automatic update from web-platform-tests [Clipboard API] Add support for Promise to Blobs in clipboard item. This patch adds promise support to `ClipboardItem` object. This helps the web author to call async write method without having to provide the Blob data synchronously. Authors can choose to resolve the promise later when the Blob data is available. This change does not break any existing code that only takes a Blob parameter while constructing `ClipboardItem` object, so this should not be considered as a breaking change. I2S: https://groups.google.com/a/chromium.org/g/blink-dev/c/8z0qWJ5Fztc/m/qJwfgMTxAAAJ?utm_medium=email&utm_source=footer Bug: 1014310 Change-Id: I5104c70e6f3e28591801f72165d7b9ec381bd04f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169593 Commit-Queue: Anupam Snigdha <snianu@microsoft.com> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/main@{#945323} -- wpt-commits: 2865f7276a9140a0f19f6ef5b9f5b3675a135bf0 wpt-pr: 31040
testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-basics.https.html
testing/web-platform/tests/clipboard-apis/async-promise-write-blobs-read-blobs.https.html
--- 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
@@ -80,9 +80,26 @@ promise_test(async () => {
   assert_true(result[0] instanceof ClipboardItem);
 }, 'navigator.clipboard.read() succeeds');
 
 promise_test(async () => {
   const result = await navigator.clipboard.readText();
   assert_equals(typeof result, 'string');
 }, 'navigator.clipboard.readText() succeeds');
 
+promise_test(async () => {
+  await getPermissions();
+  const promise_blob = Promise.resolve(new Blob(['hello'], {type: 'text/plain'}));
+  const item = new ClipboardItem({'text/plain': promise_blob});
+
+  await navigator.clipboard.write([item]);
+}, 'navigator.clipboard.write(Promise<Blob>) succeeds');
+
+promise_test(async () => {
+  await getPermissions();
+  const promise_text_blob = Promise.resolve(new Blob(['hello'], {type: 'text/plain'}));
+  const promise_html_blob = Promise.resolve(new Blob(["<p style='color: red; font-style: oblique;'>Test</p>"], {type: 'text/html'}));
+  const item = new ClipboardItem({'text/plain': promise_text_blob, 'text/html': promise_html_blob});
+
+  await navigator.clipboard.write([item]);
+}, 'navigator.clipboard.write(Promise<Blob>s) succeeds');
+
 </script>
copy from testing/web-platform/tests/clipboard-apis/async-write-blobs-read-blobs.https.html
copy to testing/web-platform/tests/clipboard-apis/async-promise-write-blobs-read-blobs.https.html
--- a/testing/web-platform/tests/clipboard-apis/async-write-blobs-read-blobs.https.html
+++ b/testing/web-platform/tests/clipboard-apis/async-promise-write-blobs-read-blobs.https.html
@@ -1,44 +1,43 @@
 <!doctype html>
 <meta charset="utf-8">
 <title>
-  Async Clipboard write blobs -> read blobs tests
+  Async Clipboard write blobs -> read blobs with promise tests
 </title>
 <link rel="help" href="https://w3c.github.io/clipboard-apis/#async-clipboard-api">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="/resources/testdriver.js"></script>
 <script src="/resources/testdriver-vendor.js"></script>
 
 <script>
 async function loadBlob(fileName) {
   const fetched = await fetch(fileName);
   return await fetched.blob();
 }
 
 promise_test(async t => {
+  const promise1 = new Promise((resolve, reject) => {
+    resolve(loadBlob('resources/greenbox.png'));
+  });
   await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
   await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
 
   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');
 
   const clipboardItemInput = new ClipboardItem(
-        {'text/plain' : blobText, 'image/png' : blobImage});
+        {'text/plain' : blobText, 'image/png' : promise1});
 
   await navigator.clipboard.write([clipboardItemInput]);
   const clipboardItems = await navigator.clipboard.read();
 
   assert_equals(clipboardItems.length, 1);
   const clipboardItem = clipboardItems[0];
   assert_true(clipboardItem instanceof ClipboardItem);
 
   assert_equals(clipboardItem.types.length, 2);
   const blobTextOutput = await clipboardItem.getType('text/plain');
   const blobImageOutput = await clipboardItem.getType('image/png');
   assert_equals(blobTextOutput.type, 'text/plain');
   assert_equals(blobImageOutput.type, 'image/png');
-}, 'Verify write and read clipboard (multiple types)');
+}, 'Verify write and read clipboard (multiple types) with promise to Blobs');
 </script>