Bug 1462837 [wpt PR 11081] - Add web platform test for Accept-CH-Lifetime header for client hints, a=testonly
authorTarun Bansal <tbansal@chromium.org>
Fri, 06 Jul 2018 13:53:56 +0000
changeset 425823 a395b17a56c54aa7a52e77bef61425d38936af05
parent 425822 50747b1f5cd5d0870d475441565d8599f8d345ce
child 425824 1b677f686d7d874f7329b39ef866d009cc81b6a7
push id34267
push userrgurzau@mozilla.com
push dateWed, 11 Jul 2018 22:05:21 +0000
treeherdermozilla-central@3aca103e4915 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1462837, 11081, 817049, 1066919, 566359
milestone63.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 1462837 [wpt PR 11081] - Add web platform test for Accept-CH-Lifetime header for client hints, a=testonly Automatic update from web-platform-testsAdd web platform test for Accept-CH-Lifetime header for client hints Bug: 817049 Change-Id: Ic58e5688b0bb14803a9b6f01100500dd567b9fbc Reviewed-on: https://chromium-review.googlesource.com/1066919 Commit-Queue: Tarun Bansal <tbansal@chromium.org> Reviewed-by: Philip J├Ągenstedt <foolip@chromium.org> Cr-Commit-Position: refs/heads/master@{#566359} -- wpt-commits: 67ad035decf7726544cdd3ee877da1a29d37e41b wpt-pr: 11081
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/client-hints/accept_ch.tentative.https.html
testing/web-platform/tests/client-hints/accept_ch_lifetime.tentative.https.html
testing/web-platform/tests/client-hints/resources/accept_ch.html
testing/web-platform/tests/client-hints/resources/accept_ch.html.headers
testing/web-platform/tests/client-hints/resources/accept_ch_lifetime.html
testing/web-platform/tests/client-hints/resources/accept_ch_lifetime.html.headers
testing/web-platform/tests/client-hints/resources/do_not_expect_client_hints_headers.html
testing/web-platform/tests/client-hints/resources/expect_client_hints_headers.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -193339,16 +193339,46 @@
      {}
     ]
    ],
    "client-hints/echo_client_hints_received.py": [
     [
      {}
     ]
    ],
+   "client-hints/resources/accept_ch.html": [
+    [
+     {}
+    ]
+   ],
+   "client-hints/resources/accept_ch.html.headers": [
+    [
+     {}
+    ]
+   ],
+   "client-hints/resources/accept_ch_lifetime.html": [
+    [
+     {}
+    ]
+   ],
+   "client-hints/resources/accept_ch_lifetime.html.headers": [
+    [
+     {}
+    ]
+   ],
+   "client-hints/resources/do_not_expect_client_hints_headers.html": [
+    [
+     {}
+    ]
+   ],
+   "client-hints/resources/expect_client_hints_headers.html": [
+    [
+     {}
+    ]
+   ],
    "clipboard-apis/OWNERS": [
     [
      {}
     ]
    ],
    "common/OWNERS": [
     [
      {}
@@ -312403,16 +312433,28 @@
     ]
    ],
    "client-hints/accept_ch.sub.https.html": [
     [
      "/client-hints/accept_ch.sub.https.html",
      {}
     ]
    ],
+   "client-hints/accept_ch.tentative.https.html": [
+    [
+     "/client-hints/accept_ch.tentative.https.html",
+     {}
+    ]
+   ],
+   "client-hints/accept_ch_lifetime.tentative.https.html": [
+    [
+     "/client-hints/accept_ch_lifetime.tentative.https.html",
+     {}
+    ]
+   ],
    "client-hints/accept_ch_malformed_header.https.html": [
     [
      "/client-hints/accept_ch_malformed_header.https.html",
      {}
     ]
    ],
    "clipboard-apis/async-interfaces.https.html": [
     [
@@ -416896,28 +416938,60 @@
   "client-hints/accept_ch.sub.https.html": [
    "8cfb7a9f11cbd19f2e3965c27af394fca31e1654",
    "testharness"
   ],
   "client-hints/accept_ch.sub.https.html.headers": [
    "23aaa612f1b6ee417d31faec8399248c9bc7cffc",
    "support"
   ],
+  "client-hints/accept_ch.tentative.https.html": [
+   "342de3ae30d962249bc0c282aac5b6e4192badfd",
+   "testharness"
+  ],
+  "client-hints/accept_ch_lifetime.tentative.https.html": [
+   "58a6a6dafb4a6a3e8daa8742a1da137399353370",
+   "testharness"
+  ],
   "client-hints/accept_ch_malformed_header.https.html": [
    "fb5fa5837d4e3379384b6f409cd42c748dfa145f",
    "testharness"
   ],
   "client-hints/accept_ch_malformed_header.https.html.headers": [
    "e57611a23dbd0763e1d318af602f05a2593b149e",
    "support"
   ],
   "client-hints/echo_client_hints_received.py": [
    "a69e980bffe7bd97aaaffde6bbec85df36b164c4",
    "support"
   ],
+  "client-hints/resources/accept_ch.html": [
+   "a0a6d53c0c859bb62d38f1ad3a4eeac0abd50823",
+   "support"
+  ],
+  "client-hints/resources/accept_ch.html.headers": [
+   "5e8beefae60a740d780c333e8df38c62350c345d",
+   "support"
+  ],
+  "client-hints/resources/accept_ch_lifetime.html": [
+   "ddafc53ea37b3f557b518e65181fdafc161cde49",
+   "support"
+  ],
+  "client-hints/resources/accept_ch_lifetime.html.headers": [
+   "6e96c4ec282ce390e9becb2c50944031fb36f4a0",
+   "support"
+  ],
+  "client-hints/resources/do_not_expect_client_hints_headers.html": [
+   "f48190cb980ceef479f6858cd6cc121d136c52a3",
+   "support"
+  ],
+  "client-hints/resources/expect_client_hints_headers.html": [
+   "88247405d94960fc58d49b0969f5c9357ee84fad",
+   "support"
+  ],
   "clipboard-apis/OWNERS": [
    "bae753666bda85e9805a5e2fad80ba71459b8aba",
    "support"
   ],
   "clipboard-apis/async-interfaces.https.html": [
    "ffc8726b7afa6dc3e58745bd0dac525a570970ef",
    "testharness"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/accept_ch.tentative.https.html
@@ -0,0 +1,59 @@
+<html>
+<title>Accept-CH test</title>
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<div id=test>
+    <p>Apart from this webpage, the test opens another html web page. One test
+    is run in this web page, and another in the second web page.
+</div>
+
+<script>
+
+// This test fetches resources/accept_ch.html. The response headers to
+// that webpage contains only the Accept-CH header. Due to the missing
+// Accept-CH-Lifetime header, the user-agent should not persist origin
+// preferences for the client hints specified in Accept-CH header.
+
+// Next, to verify that the origin preferences were not persisted by the user
+// agent, this test fetches resources/do_not_expect_client_hints_headers.html
+// in a new window. Fetching of
+// resources/do_not_expect_client_hints_headers.html
+// verifies that the user agent does not send the client hints in the request
+// headers.
+
+// Verify the initial state to make sure that the browser does not have client
+// hints preferences cached from a previous run of the test.
+
+// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
+// is resolved.
+promise_test(t => {
+  return fetch("echo_client_hints_received.py").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 that the browser does not have client hints preferences cached");
+
+promise_test(t => {
+  return fetch("resources/accept_ch.html").then(r => {
+    assert_equals(r.status, 200)
+    assert_false(r.headers.has("device-memory-received"), "device-memory-received");
+
+    // Open a new window.
+    window.open("resources/do_not_expect_client_hints_headers.html");
+  });
+}, "Test receiving Accept-CH header");
+
+async_test(t => {
+window.addEventListener('message', function(event) {
+  t.done();
+})
+}, "Loading of resources/do_not_expect_client_hints_headers.html did not finish.");
+
+</script>
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/accept_ch_lifetime.tentative.https.html
@@ -0,0 +1,60 @@
+<html>
+<title>Accept-CH-Lifetime test</title>
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<div id=test>
+    <p>Apart from this webpage, the test opens another html web page. One test
+    is run in this web page, and another in the second web page.
+</div>
+
+<script>
+
+// This test fetches resources/accept_ch_lifetime.html. The response headers to
+// that webpage contain Accept-CH and Accept-CH-Lifetime headers.
+// Fetching that webpage should cause the user-agent to persist origin
+// preferences for the client hints specified in Accept-CH header for a
+// duration specified in the Accept-CH-Lifetime header.
+
+// Next, to verify if the origin preferences were persisted by the user
+// agent, this test fetches resources/expect_client_hints_headers.html
+// in a new window. Fetching of resources/expect_client_hints_headers.html
+// verifies that the user agent actually sends the client hints in the request
+// headers.
+
+// Verify the initial state to make sure that the browser does not have client
+// hints preferences cached from a previous run of the test.
+
+// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
+// is resolved.
+promise_test(t => {
+  return fetch("echo_client_hints_received.py").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 that the browser does not have client hints preferences cached");
+
+promise_test(t => {
+  return fetch("resources/accept_ch_lifetime.html").then(r => {
+    assert_equals(r.status, 200)
+    assert_false(r.headers.has("device-memory-received"), "device-memory-received");
+
+    // Open a new window.
+    window.open("resources/expect_client_hints_headers.html");
+  });
+}, "Test receiving Accept-CH-Lifetime header");
+
+async_test(t => {
+window.addEventListener('message', function(event) {
+  t.done();
+})
+}, "Loading of resources/expect_client_hints_headers.html did not finish.");
+
+
+</script>
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/resources/accept_ch.html
@@ -0,0 +1,10 @@
+<html>
+<body>
+
+<!-- An empty webpage whose response headers include only the
+Accept-CH header. Fetching this webpage should not cause
+user-agent to persist origin preferences for the client hints
+specified in the Accept-CH header.-->
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/resources/accept_ch.html.headers
@@ -0,0 +1,1 @@
+Accept-CH: device-memory
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/resources/accept_ch_lifetime.html
@@ -0,0 +1,11 @@
+<html>
+<body>
+
+<!-- An empty webpage whose response headers include Accept-CH
+and Accept-CH-Lifetime header. Fetching this webpage should cause
+user-agent to persist origin preferences for the client hints
+specified in the Accept-CH header for a duration specified in
+the Accept-CH-Lifetime header.-->
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/resources/accept_ch_lifetime.html.headers
@@ -0,0 +1,2 @@
+Accept-CH: device-memory
+Accept-CH-Lifetime: 20
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/resources/do_not_expect_client_hints_headers.html
@@ -0,0 +1,28 @@
+<html>
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+
+// This test checks if browser attaches the device-memory client hint in the
+// HTTP request headers.
+
+// echo_client_hints_received.py sets the response headers depending on the set
+// of client hints it receives in the request headers.
+
+promise_test(t => {
+  return fetch("../echo_client_hints_received.py").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");
+    window.top.opener.postMessage('PASS', '*');
+  });
+}, "Test if device-memory header was not sent by the browser");
+
+
+</script>
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/resources/expect_client_hints_headers.html
@@ -0,0 +1,28 @@
+<html>
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+
+// This test checks if browser attaches the device-memory client hint in the
+// HTTP request headers.
+
+// echo_client_hints_received.py sets the response headers depending on the set
+// of client hints it receives in the request headers.
+
+promise_test(t => {
+  return fetch("../echo_client_hints_received.py").then(r => {
+    assert_equals(r.status, 200)
+    // Verify that the browser included client hints in the request headers when
+    // fetching echo_client_hints_received.py.
+    assert_true(r.headers.has("device-memory-received"), "device-memory-received");
+    window.top.opener.postMessage('PASS', '*');
+  });
+}, "Test if device-memory header was sent by the browser");
+
+
+</script>
+
+</body>
+</html>