Bug 1452811 [wpt PR 10352] - Add external WPT test for cross-origin requests, a=testonly
authorTarun Bansal <tbansal@chromium.org>
Thu, 19 Apr 2018 13:34:29 +0000
changeset 468397 bbf635ed186ce4222ca7ec09e2e6475543985cc8
parent 468396 55ab75b9e31220f2c6f025ac446d800256f3127f
child 468398 897ebf44f505010b0be8d4773368bc926c32315e
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1452811, 10352, 817049, 1000841, 549238
milestone61.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 1452811 [wpt PR 10352] - Add external WPT test for cross-origin requests, a=testonly Automatic update from web-platform-testsAdd external WPT test for cross-origin requests The browser should not attach client hints to the requests fetched from cross origins. Bug: 817049 Change-Id: Ia7cedfbb6edaaf3616d6e2783965cc52f93c0cd9 Reviewed-on: https://chromium-review.googlesource.com/1000841 Commit-Queue: Tarun Bansal <tbansal@chromium.org> Reviewed-by: Philip J├Ągenstedt <foolip@chromium.org> Cr-Commit-Position: refs/heads/master@{#549238} -- wpt-commits: 46abbd55aa879ee92ce2f830819569936d9f531f wpt-pr: 10352 wpt-commits: 46abbd55aa879ee92ce2f830819569936d9f531f wpt-pr: 10352
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/client-hints/accept_ch.sub.https.html
testing/web-platform/tests/client-hints/echo_client_hints_received.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -404471,25 +404471,25 @@
    "e2181077e6d378a288d4944aee8c76939aa896fe",
    "testharness"
   ],
   "client-hints/accept_ch.http.html.headers": [
    "25cd8622db940411b0e8eb39921e6086916e4f36",
    "support"
   ],
   "client-hints/accept_ch.sub.https.html": [
-   "4e3f60751fbbc8f58bbf6fb7eadd1f334c9789ad",
+   "7d5a8d7d6ffb78f99d17fc0c41abf26718c6b6b0",
    "testharness"
   ],
   "client-hints/accept_ch.sub.https.html.headers": [
    "25cd8622db940411b0e8eb39921e6086916e4f36",
    "support"
   ],
   "client-hints/echo_client_hints_received.py": [
-   "3d3b57376cbacbd2118fe4fe07abad5bd9ad95fd",
+   "a6cf24dc7d02b044a27813f50737bb3aff4af8bf",
    "support"
   ],
   "clipboard-apis/OWNERS": [
    "bae753666bda85e9805a5e2fad80ba71459b8aba",
    "support"
   ],
   "clipboard-apis/async-interfaces.https.html": [
    "ffc8726b7afa6dc3e58745bd0dac525a570970ef",
--- a/testing/web-platform/tests/client-hints/accept_ch.sub.https.html
+++ b/testing/web-platform/tests/client-hints/accept_ch.sub.https.html
@@ -2,31 +2,45 @@
 <body>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 
 <script>
 
 // If the response for the HTML file contains "Accept-CH" in the response
 // headers, then the browser should attach the specified client hints in the
-// HTTP request headers. Test this functionality by fetching an
-// XHR from this page. The response headers for this page include
-// "Accept-CH: device-memory, dpr, viewport-width".
+// HTTP request headers depending on whether the resource is being fetched from
+// the same origin or a different origin. Test this functionality by fetching
+// same-origin and cross-origin resources from this page. The response headers
+// for this page include "Accept-CH: device-memory, dpr, viewport-width".
 //
 // echo_client_hints_received.py includes "device-memory-received",
 // "dpr-received" and "viewport-width-received" in the response headers
 // depending on the set of client hints it receives in the request headers.
 
-  promise_test(t => {
+promise_test(t => {
   return fetch("https://{{domains[]}}:{{ports[https][0]}}/client-hints/echo_client_hints_received.py", {"mode": "no-cors"}).then(r => {
     assert_equals(r.status, 200)
-    // Verify that the browser includes client hints in the headers when
-    // fetching the XHR.
+    // Verify that the browser includes client hints in the headers for a
+    // same-origin fetch.
     assert_true(r.headers.has("device-memory-received"), "device-memory-received");
     assert_true(r.headers.has("dpr-received"), "dpr-received");
     assert_true(r.headers.has("viewport-width-received"), "viewport-width-received");
   });
 }, "Accept-CH header test");
 
+promise_test(t => {
+  return fetch("https://{{domains[www]}}:{{ports[https][0]}}/client-hints/echo_client_hints_received.py").then(r => {
+    assert_equals(r.status, 200)
+    // Verify that the browser does not include client hints in the headers
+    // for a cross-origin fetch.
+    assert_false(r.headers.has("device-memory-received"), "device-memory-received");
+    assert_false(r.headers.has("dpr-received"), "dpr-received");
+    assert_false(r.headers.has("viewport-width-received"), "viewport-width-received");
+  });
+}, "Cross-Origin Accept-CH header test");
+
+
+
 </script>
 
 </body>
 </html>
--- a/testing/web-platform/tests/client-hints/echo_client_hints_received.py
+++ b/testing/web-platform/tests/client-hints/echo_client_hints_received.py
@@ -1,12 +1,14 @@
 def main(request, response):
     """
     Simple handler that sets a response header based on if device-memory
     request header was received or not.
     """
 
+    response.headers.append("Access-Control-Allow-Origin", "*")
+
     if "device-memory" in request.headers:
             response.headers.set("device-memory-received", "true")
     if "dpr" in request.headers:
             response.headers.set("dpr-received", "true")
     if "viewport-width" in request.headers:
             response.headers.set("viewport-width-received", "true")
\ No newline at end of file