Bug 1558821 [wpt PR 17232] - Fix duplicate value of client hint headers on asynchronous validation requests, a=testonly
authorAaron Tagliaboschi <aarontag@chromium.org>
Fri, 13 Sep 2019 10:33:56 +0000
changeset 554548 6d8c124b5b203e4f6d791d7f8b4ebb56eadba848
parent 554547 2722436f641955ca436f921b30aad25cb2f3c7f2
child 554549 9deab0f44cb04c09fcaed56beeed1d30f56b829e
push id12169
push userffxbld-merge
push dateMon, 14 Oct 2019 16:59:29 +0000
treeherdermozilla-beta@c819687300ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1558821, 17232, 959611, 1645455, 694763
milestone71.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 1558821 [wpt PR 17232] - Fix duplicate value of client hint headers on asynchronous validation requests, a=testonly Automatic update from web-platform-tests Fix duplicate value of client hint headers on asynchronous validation requests Fix issue where asynchronous validation requests (specifically, revalidation on stale-while-revalidate requests) result in a duplicate value for client hint headers (i.e. `Sec-CH-UA: Chromium 76, Chromium 76` instead of `Sec-CH-UA: Chromium 76`) Bug: 959611 Change-Id: Iac16b84b129108b9ebe1258e11722cdc9eaa52de Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1645455 Commit-Queue: Aaron Tagliaboschi <aarontag@chromium.org> Reviewed-by: Robert Ma <robertma@chromium.org> Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Reviewed-by: Maks Orlovich <morlovich@chromium.org> Cr-Commit-Position: refs/heads/master@{#694763} -- wpt-commits: 8b2e7c95c621390fbdb0c0c064c932016c22d224 wpt-pr: 17232
testing/web-platform/tests/client-hints/accept-ch-cache-revalidation.https.html
testing/web-platform/tests/client-hints/accept-ch-cache-revalidation.https.html.headers
testing/web-platform/tests/client-hints/resources/stale-echo-client-hints.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/accept-ch-cache-revalidation.https.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Tests Stale While Revalidate is not executed for fetch API</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/utils.js"></script>
+<script>
+function wait25ms(test) {
+  return new Promise(resolve => {
+    test.step_timeout(() => {
+      resolve();
+    }, 25);
+  });
+}
+
+promise_test(async (test) => {
+  var request_token = token();
+  var client_hint_headers = [
+    "device-memory",
+    "dpr",
+    "width",
+    "viewport-width",
+    "rtt",
+    "downlink",
+    "ect",
+    "sec-ch-lang",
+    "sec-ch-ua",
+    "sec-ch-ua-arch",
+    "sec-ch-ua-platform",
+    "sec-ch-ua-model",
+  ];
+
+  const response = await fetch(`resources/stale-echo-client-hints.py?token=` + request_token);
+  const response2 = await fetch(`resources/stale-echo-client-hints.py?token=` + request_token);
+
+  assert_equals(response.headers.get('Unique-Id'), response2.headers.get('Unique-Id'));
+
+  while(true) {
+    const revalidation_check = await fetch(`resources/stale-echo-client-hints.py?query&token=` + request_token);
+    if (revalidation_check.headers.get('Count') == '2') {
+      client_hint_headers.forEach(header => {
+        assert_equals(revalidation_check.headers.get(header+"-recieved"), revalidation_check.headers.get(header+"-previous"));
+      });
+      break;
+    }
+    await wait25ms(test);
+  }
+}, 'Same headers sent for revalidation request');
+</script>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/accept-ch-cache-revalidation.https.html.headers
@@ -0,0 +1,1 @@
+Accept-CH: dpr,device-memory,viewport-width,rtt,downlink,ect,lang,ua,arch,platform,model
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/resources/stale-echo-client-hints.py
@@ -0,0 +1,60 @@
+import random
+import string
+
+def id_token():
+   letters = string.ascii_lowercase
+   return ''.join(random.choice(letters) for i in range(20))
+
+def main(request, response):
+    client_hint_headers = [
+      "device-memory",
+      "dpr",
+      "width",
+      "viewport-width",
+      "rtt",
+      "downlink",
+      "ect",
+      "sec-ch-lang",
+      "sec-ch-ua",
+      "sec-ch-ua-arch",
+      "sec-ch-ua-platform",
+      "sec-ch-ua-model",
+    ]
+
+    client_hints_curr = {i:request.headers.get(i) for i in client_hint_headers}
+
+    token = request.GET.first("token", None)
+    is_query = request.GET.first("query", None) is not None
+    with request.server.stash.lock:
+      stash = request.server.stash.take(token)
+      if stash != None:
+        (value, client_hints_prev) = stash
+        count = int(value)
+      else:
+        count = 0
+        client_hints_prev = {}
+
+      if is_query:
+        if count < 2:
+          request.server.stash.put(token, (count, client_hints_curr))
+      else:
+        count = count + 1
+        request.server.stash.put(token, (count, client_hints_curr))
+
+    for header in client_hint_headers:
+      if client_hints_curr[header] is not None:
+        response.headers.set(header+"-recieved", client_hints_curr[header])
+      if (header in client_hints_prev) and (client_hints_prev[header] is not None):
+        response.headers.set(header+"-previous", client_hints_prev[header])
+
+    if is_query:
+      headers = [("Count", count)]
+      content = ""
+      return 200, headers, content
+    else:
+      unique_id = id_token()
+      headers = [("Content-Type", "text/html"),
+                 ("Cache-Control", "private, max-age=0, stale-while-revalidate=60"),
+                 ("Unique-Id", unique_id)]
+      content = "report('{}')".format(unique_id)
+      return 200, headers, content
\ No newline at end of file