Bug 1619698 [wpt PR 22068] - [client hints] Fix handling of redirects in navigation, a=testonly
authorMaks Orlovich <morlovich@chromium.org>
Tue, 28 Apr 2020 11:42:52 +0000
changeset 527262 28d1dd0a877e8d959b5b75429e19c44d36f76729
parent 527261 ed06ca73fddfdc5073257aef59b31240f0c4e3f9
child 527263 00be66227a0c18fd63d230b84163871ab2fb6edf
push id114648
push userwptsync@mozilla.com
push dateThu, 30 Apr 2020 19:15:02 +0000
treeherderautoland@2545233d9410 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1619698, 22068, 1050726, 2085114, 762329
milestone77.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 1619698 [wpt PR 22068] - [client hints] Fix handling of redirects in navigation, a=testonly Automatic update from web-platform-tests [client hints] Fix handling of redirects in navigation In particular, the browser needs to handle accept-ch there since the renderer doesn't see the intermediate steps until after everything is fetched, and new client hints may be requested in the middle of the chain. This is done by having the network service parse the header and store in ParseHeaders, then using that in the browser This is also likely the first step towards moving more of handling of accept-ch to browser (which will simplify some things and fix some bugs). Bug: 1050726 Change-Id: Ie02d7492c02b75034b36af30e489ebbb430d6a1b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2085114 Commit-Queue: Maksim Orlovich <morlovich@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Cr-Commit-Position: refs/heads/master@{#762329} -- wpt-commits: 39411b7ef888f9bd67e430970042f757bac0bed0 wpt-pr: 22068
testing/web-platform/tests/client-hints/accept-ch-stickiness/resources/accept-ch-and-redir-to-expect.py
testing/web-platform/tests/client-hints/accept-ch-stickiness/resources/accept-ch-test.js
testing/web-platform/tests/client-hints/accept-ch-stickiness/resources/expect-received.py
testing/web-platform/tests/client-hints/accept-ch-stickiness/same-origin-navigation-redirect.https.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/accept-ch-stickiness/resources/accept-ch-and-redir-to-expect.py
@@ -0,0 +1,2 @@
+def main(request, response):
+    return 301, [('Location', 'expect-received.py'),('Accept-CH', 'device-memory, DPR')], ''
--- a/testing/web-platform/tests/client-hints/accept-ch-stickiness/resources/accept-ch-test.js
+++ b/testing/web-platform/tests/client-hints/accept-ch-stickiness/resources/accept-ch-test.js
@@ -1,28 +1,49 @@
 const echo = "/client-hints/accept-ch-stickiness/resources/echo-client-hints-received.py";
 const accept = "/client-hints/accept-ch-stickiness/resources/accept-ch.html";
 const httpequiv_accept = "/client-hints/accept-ch-stickiness/resources/http-equiv-accept-ch.html";
 const expect = "/client-hints/accept-ch-stickiness/resources/expect-client-hints-headers.html"
 const do_not_expect = "/client-hints/accept-ch-stickiness/resources/do-not-expect-client-hints-headers.html"
 
 const host_info = get_host_info();
-const run_test = test => {
-  // First, verify the initial state to make sure that the browser does not have
-  // client hints preferences cached from a previous run of the test.
+
+function verify_initial_state(initial_url, test_name) {
   promise_test(t => {
-    return fetch(test.initial_url).then(r => {
+    return fetch(initial_url).then(r => {
       assert_equals(r.status, 200)
       // Verify that the browser did not include client hints in the request
       // headers when fetching echo-client-hints-received.py.
       assert_false(r.headers.has("device-memory-received"),
         "device-memory-received");
     });
-  }, test.name + " precondition: Test that the browser does not have client " +
+  }, test_name + " precondition: Test that the browser does not have client " +
     "hints preferences cached");
+}
+
+function verify_navigation_state(expect_url, test_name) {
+  promise_test(t => {
+    return new Promise(resolve => {
+      let win;
+      window.addEventListener('message', t.step_func(function(e) {
+        win.close();
+        assert_equals(e.data, "PASS", "message from opened page");
+        fetch("/client-hints/accept-ch-stickiness/resources/clear-site-data.html").then(resolve);
+      }));
+      // Open a new window. Verify that the user agent attaches client hints.
+      win = window.open(expect_url);
+      assert_not_equals(win, null, "Popup windows not allowed?");
+    });
+  }, test_name + " got client hints according to expectations.");
+}
+
+const run_test = test => {
+  // First, verify the initial state to make sure that the browser does not have
+  // client hints preferences cached from a previous run of the test.
+  verify_initial_state(test.initial_url, test.name);
 
   // Then, attempt to set Accept-CH
   promise_test(t => {
     return new Promise(resolve => {
       if (test.type == "navigation") {
         const win = window.open(test.accept_url);
         assert_not_equals(win, null, "Popup windows not allowed?");
         addEventListener('message', t.step_func(() => {
@@ -48,23 +69,11 @@ const run_test = test => {
         });
       } else {
         assert_unreached("unknown test type");
       }
     });
   }, test.name + " set Accept-CH");
 
   // Finally, verify that CH are actually sent (or not) on requests
-  promise_test(t => {
-    return new Promise(resolve => {
-      let win;
-      window.addEventListener('message', t.step_func(function(e) {
-        win.close();
-        assert_equals(e.data, "PASS", "message from opened page");
-        fetch("/client-hints/accept-ch-stickiness/resources/clear-site-data.html").then(resolve);
-      }));
-      // Open a new window. Verify that the user agent attaches client hints.
-      win = window.open(test.expect_url);
-      assert_not_equals(win, null, "Popup windows not allowed?");
-    });
-  }, test.name + " got client hints according to expectations.");
+  verify_navigation_state(test.expect_url, test.name);
 };
 
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/accept-ch-stickiness/resources/expect-received.py
@@ -0,0 +1,19 @@
+def main(request, response):
+    """
+    Check that headers sent to navigate here contain the device-memory client
+    hint, and report success/failure in a way compatible with
+    verify_navigation_state() in accept-ch-test.js
+    """
+
+    if "device-memory" in request.headers:
+      result = "PASS"
+    else:
+      result = "FAIL"
+
+    content = '''
+<script>
+  window.opener.postMessage("%s" , "*");
+</script>
+''' % (result)
+    headers = [("Content-Type", "text/html")]
+    return 200, headers, content
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/accept-ch-stickiness/same-origin-navigation-redirect.https.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<meta name="timeout" content="long">
+<title>Accept-CH Persistence test</title>
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="resources/accept-ch-test.js"></script>
+
+<script>
+// This is similar to accept-ch-test.js tests, except setting and checking
+// header here are a single step, connected via redirect.
+const test_name = "redirect on navigation";
+verify_initial_state(echo, test_name);
+verify_navigation_state("resources/accept-ch-and-redir-to-expect.py", test_name);
+</script>
+</body>
+</html>
+