From d86a5f7150f42a07a9c991046ffb993b93ecd737 Mon Sep 17 00:00:00 2001 From: Anupam Snigdha Date: Tue, 24 Oct 2023 15:28:16 -0700 Subject: [PATCH] [Async Clipboard API] Add supports method to async clipboard API. In this change we are adding a new static method `supports` to the ClipboardItem interface to help web authors detect clipboard format types that are supported by Chromium. Github Issue: https://github.com/w3c/clipboard-apis/issues/170 Spec: https://github.com/w3c/clipboard-apis/pull/192 https://github.com/w3c/clipboard-apis/pull/195 I2S: https://groups.google.com/a/chromium.org/g/blink-dev/c/pjpN9Lwv5Tk/m/KrAZRbdwAQAJ?utm_medium=email&utm_source=footer&pli=1 Bug: 1483026, 1490635 Change-Id: Ief7c0786833548d2fb51215cefbc39e5930af875 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4865377 Reviewed-by: Kent Tamura Commit-Queue: Anupam Snigdha Reviewed-by: Evan Stade Cr-Commit-Position: refs/heads/main@{#1214477} --- clipboard-apis/clipboard-item.https.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clipboard-apis/clipboard-item.https.html b/clipboard-apis/clipboard-item.https.html index 9ed6f583bde5ce..b50a1c97d74616 100644 --- a/clipboard-apis/clipboard-item.https.html +++ b/clipboard-apis/clipboard-item.https.html @@ -95,4 +95,18 @@ const text = await (new Response(blob)).text(); assert_equals(text, 'xxx'); }, "getType(DOMString invalid type) converts DOMString to Blob"); + +promise_test(async () => { + assert_true(ClipboardItem.supports('text/plain')); + assert_true(ClipboardItem.supports('text/html')); + assert_true(ClipboardItem.supports('image/png')); + assert_false(ClipboardItem.supports('web ')); + assert_false(ClipboardItem.supports('web')); // without space. + assert_false(ClipboardItem.supports('web foo')); + assert_false(ClipboardItem.supports('foo/bar')); + assert_true(ClipboardItem.supports('web foo/bar')); + assert_true(ClipboardItem.supports('web text/html')); + assert_false(ClipboardItem.supports('image/svg+xml')); + assert_false(ClipboardItem.supports('not a/real type')); +}, "supports(DOMString) returns true for types that are supported, false otherwise");