Bug 1636565 [wpt PR 23490] - Add lazy load image and iframe referrerpolicy tests, a=testonly
authorDominic Farolino <dom@chromium.org>
Wed, 13 May 2020 10:00:36 +0000
changeset 531181 f0e5fdd3cecd35183cd40f5a97174e94d158d8de
parent 531180 38475a9adc1e4ce74f26ae7a810ac90d2916920b
child 531182 180a226742fd396680e6491caf4c277fcf564182
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1636565, 23490, 2171816, 1080739, 2185395, 767367
milestone78.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 1636565 [wpt PR 23490] - Add lazy load image and iframe referrerpolicy tests, a=testonly Automatic update from web-platform-tests Add lazy load image and iframe referrerpolicy tests This CL does the following: - Adds a correct <img loading=lazy referrerpolicy> test, to assert that the referrerpolicy a deferred image is ultimately fetched with is the latest one. This is because `referrerpolicy` mutations are considered relevant mutations as per https://crrev.com/c/2171816 and https://github.com/whatwg/html/pull/5434, so the latest referrerpolicy should be honored when an image is fetched after being deferred. - Adds an <iframe loading=lazy referrerpolicy> test, to assert that the referrerpolicy a deferred iframe is fetched with is the referrerpolicy at parse-time. This is because iframes do not respond to referrerpolicy mutations, and during spec discussions, it was mentioned that the request for iframes be set up and finalized at parse-time. The test is marked tentative because the spec does not officially exist yet. - Cleans up an <img loading=lazy crossorigin> test. Bug: 1080739 Change-Id: I8ec6c344557180721c317f6accaad1b336b39b8c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2185395 Commit-Queue: Dominic Farolino <dom@chromium.org> Reviewed-by: Fredrik Söderquist <fs@opera.com> Cr-Commit-Position: refs/heads/master@{#767367} -- wpt-commits: 2728d5f74309f29be73f7a5a07fe8ba5813bfcd9 wpt-pr: 23490
testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-referrerpolicy-change.sub.tentative.html
testing/web-platform/tests/html/semantics/embedded-content/the-img-element/image-loading-lazy-crossorigin-change.sub.html
testing/web-platform/tests/html/semantics/embedded-content/the-img-element/image-loading-lazy-referrerpolicy-change.sub.html
testing/web-platform/tests/html/semantics/embedded-content/the-img-element/original-referrer-policy-applied.sub.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/iframe-loading-lazy-referrerpolicy-change.sub.tentative.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<head>
+  <title>Deferred loading=lazy iframes are fetched with the parse-time
+         `referrerpolicy` attribute</title>
+  <link rel="author" title="Dom Farolino" href="mailto:dom@chromium.org">
+  <link rel="author" title="Raj T" href="mailto:rajendrant@chromium.org">
+  <link rel="help" href="https://github.com/scott-little/lazyload">
+  <script src="/resources/testharness.js"></script>
+  <script src="/resources/testharnessreport.js"></script>
+  <script src="../the-img-element/common.js"></script>
+</head>
+
+<script>
+  const below_viewport_iframe = new ElementLoadPromise("below_viewport_iframe");
+
+  async_test(function(t) {
+    // Change the referrer-policy and scroll down to load the deferred elements.
+    window.addEventListener("load", t.step_func(() => {
+      below_viewport_iframe.element().referrerPolicy = "no-referrer";
+      below_viewport_iframe.element().scrollIntoView();
+    }));
+
+    below_viewport_iframe.promise.then(
+      t.step_func_done(function() {
+        // The `Referer` header should be the full URL, as specified by the
+        // iframe's `referrerpolicy` attribute at parse-time, and not the origin
+        // (as specified in meta referrer tag) or null (as overridden
+        // referrerpolicy=no-referrer after load deferral).
+        assert_true(below_viewport_iframe.element().contentDocument.body.innerHTML
+                    .includes("Referer: http://{{location[host]}}{{location[path]}}"),
+                    "The iframe's `Referer` should be the referrer's full URL");
+      }));
+  }, "Test that when a deferred iframe is fetched, it uses the " +
+     "`referrerpolicy` specified at parse-time");
+</script>
+
+<body>
+  <meta name="referrer" content="origin">
+  <div style="height:1000vh;"></div>
+  <iframe id="below_viewport_iframe" src="/xhr/resources/echo-headers.py"
+          loading="lazy" width="200px" height="100px"
+          referrerpolicy="unsafe-url"
+          onload="below_viewport_iframe.resolve();">
+  </iframe>
+</body>
--- a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/image-loading-lazy-crossorigin-change.sub.html
+++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/image-loading-lazy-crossorigin-change.sub.html
@@ -4,27 +4,37 @@
   <link rel="author" title="Raj T" href="mailto:rajendrant@chromium.org">
   <link rel="author" title="Rob Buis" href="mailto:rbuis@igalia.com">
   <script src="/resources/testharness.js"></script>
   <script src="/resources/testharnessreport.js"></script>
   <script src="common.js"></script>
 </head>
 
 <script>
-  const crossorigin_img = new ElementLoadPromise("crossorigin_img");
-
-  // Set the crossorigin attribute and scroll down to load the deferred image.
-  window.addEventListener("load", () => {
-    crossorigin_img.element().crossOrigin = 'anonymous';
-    crossorigin_img.element().scrollIntoView();
-  });
+  const img = new ElementLoadPromise("cross-origin");
 
   async_test(function(t) {
-    crossorigin_img.promise.then(t.unreached_func("The image should not load.")).catch(t.step_func_done());
+    window.addEventListener("load", t.step_func(() => {
+      // At this point the image's #updating-the-image-data algorithm has been
+      // invoked, and the image request has been deferred. The deferred
+      // cross-origin image request was created with the `no-cors` request mode,
+      // which would succeed to load the cross-origin image.
+      // While the request is deferred, we'll set the `crossorigin` attribute to a
+      // value that would cause the image request to fail. Since `crossorigin`
+      // mutations trigger another #updating-the-image-data invocation (replacing
+      // the first one), when we scroll the image into view, the image should be
+      // fetched with the latest `crossorigin` attribute value, and fail to load.
+      img.element().crossOrigin = 'anonymous';
+      img.element().scrollIntoView();
+    }));
+
+    img.promise
+      .then(t.unreached_func("The image should not load."))
+      .catch(t.step_func_done());
   }, "Test that when deferred image is loaded, it uses the latest crossorigin attribute.");
 </script>
 
 <body>
   <div style="height:1000vh;"></div>
-  <img id="crossorigin_img" loading="lazy"
+  <img id="cross-origin" loading="lazy"
        src='http://{{hosts[alt][]}}:{{ports[http][0]}}/html/semantics/embedded-content/the-img-element/resources/image.png'
-       onload="crossorigin_img.resolve();" onerror="crossorigin_img.reject();">
+       onload="img.resolve();" onerror="img.reject();">
 </body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/image-loading-lazy-referrerpolicy-change.sub.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<head>
+  <title>Deferred loading=lazy images are fetched with the latest
+         `referrerpolicy` attribute</title>
+  <link rel="author" title="Dom Farolino" href="mailto:dom@chromium.org">
+  <link rel="author" title="Raj T" href="mailto:rajendrant@chromium.org">
+  <link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data">
+  <script src="/resources/testharness.js"></script>
+  <script src="/resources/testharnessreport.js"></script>
+  <script src="common.js"></script>
+</head>
+
+<script>
+  const below_viewport_img = new ElementLoadPromise("below_viewport_img");
+
+  async_test(function(t) {
+    // At this point the image's #updating-the-image-data algorithm has been
+    // invoked, and the image request has been deferred. The deferred request
+    // was created with the default referrer policy, which will result in a
+    // `Referer` header being sent when the request is finally made. The request
+    // is also for an image that the server will send a broken response for if
+    // the request has a `Referer` header.
+    // While the request is deferred, we'll set the `referrerpolicy` attribute
+    // to `no-referrer`, which would cause the image request to succeed. Since
+    // `referrerpolicy` mutations trigger another #updating-the-image-data
+    // invocation (replacing the first one), when we scroll the image into view,
+    // the image should be fetched with no `Referer` header, and succeed.
+    window.addEventListener("load", t.step_func(() => {
+      below_viewport_img.element().referrerPolicy = "no-referrer";
+      below_viewport_img.element().scrollIntoView();
+    }));
+
+    below_viewport_img.promise
+      .then(t.step_func_done())
+      .catch(t.unreached_func("The image request should successfully load"))
+  }, "Test that when a deferred image is loaded, it uses the latest referrerpolicy");
+</script>
+
+<body>
+  <div style="height:1000vh;"></div>
+  <img id="below_viewport_img"
+       src="resources/referrer-checker-img.py?expected_referrer="
+       loading="lazy" referrerpolicy="unsafe-url"
+       onload="below_viewport_img.resolve();"
+       onerror="below_viewport_img.reject();">
+</body>
deleted file mode 100644
--- a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/original-referrer-policy-applied.sub.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<!DOCTYPE html>
-<head>
-  <title>Deferred iframes and images with loading='lazy' use the original referrer-policy specified at the parse time</title>
-  <link rel="author" title="Raj T" href="mailto:rajendrant@chromium.org">
-  <link rel="help" href="https://github.com/scott-little/lazyload">
-  <script src="/resources/testharness.js"></script>
-  <script src="/resources/testharnessreport.js"></script>
-  <script src="common.js"></script>
-</head>
-
-<script>
-  const below_viewport_iframe = new ElementLoadPromise("below_viewport_iframe");
-  const below_viewport_img = new ElementLoadPromise("below_viewport_img");
-
-  // Change the referrer-policy and scroll down to load the deferred elements.
-  window.addEventListener("load", () => {
-    below_viewport_iframe.element().referrerPolicy = "no-referrer";
-    below_viewport_img.element().referrerPolicy = "no-referrer";
-    document.getElementById("below_viewport_iframe").scrollIntoView();
-  });
-
-  async_test(function(t) {
-    below_viewport_iframe.promise.then(
-      t.step_func_done(function() {
-        // The referer header should be the full URL (as specified in the iframe
-        // at parse time), and not the origin (as specified in meta referrer
-        // tag) or null (as overridden by iframe referrerpolicy=no-referrer).
-        assert_true(below_viewport_iframe.element().contentDocument.body.innerHTML
-            .includes("Referer: http://{{location[host]}}{{location[path]}}"));
-      }));
-  }, "Test that when deferred iframe is loaded, it uses the referrer-policy specified at parse time.");
-
-  async_test(function(t) {
-    below_viewport_img.promise.then(
-      t.step_func_done(function() {
-        // The image will load successfully if the full URL is sent as referrer.
-        assert_true(below_viewport_img.element().complete);
-        assert_greater_than(below_viewport_img.element().naturalWidth, 0);
-      })
-    ).catch(t.unreached_func("The image load should not fail, by sending the wrong referer header."));
-  }, "Test that when deferred img is loaded, it uses the referrer-policy specified at parse time.");
-</script>
-
-<body>
-  <meta name="referrer" content="origin">
-  <div style="height:10000px;"></div>
-  <iframe id="below_viewport_iframe" src="/xhr/resources/echo-headers.py" loading="lazy" width="200px" height="100px" referrerpolicy="unsafe-url" onload="below_viewport_iframe.resolve();">
-  </iframe>
-  <img id="below_viewport_img" src="resources/referrer-checker-img.py?expected_referrer=http://{{location[host]}}{{location[path]}}"
-       loading="lazy" referrerpolicy="unsafe-url" onload="below_viewport_img.resolve();" onerror="below_viewport_img.reject();">
-</body>