Bug 1769170 [wpt PR 34049] - Async clipboard APIs should not trigger image loading, a=testonly
authorXiaocheng Hu <xiaochengh@chromium.org>
Wed, 18 May 2022 03:33:43 +0000
changeset 618470 af3d2205f52207d1e10486773baab17df7769960
parent 618469 546a404b0f5f13dd2e2728b08ba67d7ca55dfcc8
child 618471 1bbffbb985be5a9f53b03a2c2137e5f84d5b4547
push id163295
push userwptsync@mozilla.com
push dateSun, 22 May 2022 08:42:45 +0000
treeherderautoland@28d8297085fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1769170, 34049, 1315560, 3631266, 1003888
milestone102.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 1769170 [wpt PR 34049] - Async clipboard APIs should not trigger image loading, a=testonly Automatic update from web-platform-tests Async clipboard APIs should not trigger image loading Async clipboard APIs sanitizes the raw markup mostly in a dummy document, but in the last step, creates a DocumentFragment in the real document and re-serialize for URL completion. The last step triggers image loading because the image elements are now owned by the real document. This patch changes the APIs to do the entire job in the dummy document so that we don't start image loading. Fixed: 1315560 Change-Id: Id8e318e3b0b0aa43bc6add557d70d355e88dec40 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3631266 Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org> Reviewed-by: Austin Sullivan <asully@chromium.org> Reviewed-by: Yoshifumi Inoue <yosin@chromium.org> Cr-Commit-Position: refs/heads/main@{#1003888} -- wpt-commits: 523c6b1d4cd059f3d6d246b571d39bb79e1c7a07 wpt-pr: 34049
testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-read-resource-load.https.html
copy from testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-read-sanitize.https.html
copy to testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-read-resource-load.https.html
--- a/testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-read-sanitize.https.html
+++ b/testing/web-platform/tests/clipboard-apis/async-navigator-clipboard-read-resource-load.https.html
@@ -1,44 +1,40 @@
 <!doctype html>
 <meta charset="utf-8">
-<title>Async Clipboard.read() should sanitize text/html</title>
+<title>Async Clipboard.read() should not trigger resource loading</title>
 <link rel="help" href="https://w3c.github.io/clipboard-apis/#dom-clipboard-read">
 <link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1315563">
 <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>
 
 <p><button id="button">Put payload in the clipboard</button></p>
 <div id="output"></div>
 
 <script>
-let testFailed = false;
-function fail() {
-  testFailed = true;
-}
-
 button.onclick = () => document.execCommand('copy');
 document.oncopy = ev => {
   ev.preventDefault();
   ev.clipboardData.setData(
       'text/html',
-      `<form><math><mtext></form><form><mglyph><xmp></math><img src=invalid onerror=fail()></xmp>`);
+      '<img src="https://example.com/oops">');
 };
 
 promise_test(async test => {
+  let loadObserved = false;
+  const observer = new PerformanceObserver(() => loadObserved = true);
+  observer.observe({type: 'resource'});
   await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
   await test_driver.click(button);
 
   const items = await navigator.clipboard.read();
   const htmlBlob = await items[0].getType("text/html");
   const html = await htmlBlob.text();
 
-  // This inserts an image with `onerror` handler if `html` is not properly sanitized
-  output.innerHTML = html;
+  assert_equals(html, '<img src="https://example.com/oops">');
 
-  // Allow the 'error' event to be dispatched asynchronously
+  // Allow resource loading to start asynchronously
   await new Promise(resolve => test.step_timeout(resolve, 100));
-
-  assert_false(testFailed);
+  assert_false(loadObserved, 'Should not observe resource loading');
 });
 </script>