Bug 1451598 [wpt PR 10326] - Add tests to check that the User-Agent header is set for XHR requests, a=testonly
authorBehind The Math <info@behindthemath.io>
Mon, 09 Apr 2018 22:10:53 +0000
changeset 467282 b41dda24827687462fef6c89dc212f5242e39897
parent 467281 f6383fc3805613678892a7636e33bf5a4005c704
child 467283 78401ceeed7cca57a887ee5d3ea65e4d4cf23bd3
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
bugs1451598, 10326
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 1451598 [wpt PR 10326] - Add tests to check that the User-Agent header is set for XHR requests, a=testonly Automatic update from web-platform-testsAdd tests to check that the User-Agent header is set for XHR requests wpt-commits: c6247d29cf2f5e767983783f316080973d956fa3 wpt-pr: 10326 wpt-commits: c6247d29cf2f5e767983783f316080973d956fa3 wpt-pr: 10326
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/xhr/header-user-agent-async.htm
testing/web-platform/tests/xhr/header-user-agent-sync.htm
testing/web-platform/tests/xhr/resources/header-user-agent.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -299509,16 +299509,21 @@
      {}
     ]
    ],
    "xhr/resources/header-content-length.asis": [
     [
      {}
     ]
    ],
+   "xhr/resources/header-user-agent.py": [
+    [
+     {}
+    ]
+   ],
    "xhr/resources/headers-basic.asis": [
     [
      {}
     ]
    ],
    "xhr/resources/headers.asis": [
     [
      {}
@@ -372423,16 +372428,28 @@
     ]
    ],
    "xhr/getresponseheader-unsent-opened-state.htm": [
     [
      "/xhr/getresponseheader-unsent-opened-state.htm",
      {}
     ]
    ],
+   "xhr/header-user-agent-async.htm": [
+    [
+     "/xhr/header-user-agent-async.htm",
+     {}
+    ]
+   ],
+   "xhr/header-user-agent-sync.htm": [
+    [
+     "/xhr/header-user-agent-sync.htm",
+     {}
+    ]
+   ],
    "xhr/headers-normalize-response.htm": [
     [
      "/xhr/headers-normalize-response.htm",
      {}
     ]
    ],
    "xhr/historical.html": [
     [
@@ -611704,16 +611721,24 @@
   "xhr/getresponseheader-special-characters.htm": [
    "c1bbb4ca38e62b9775baaf05593ebcc20e5301f8",
    "testharness"
   ],
   "xhr/getresponseheader-unsent-opened-state.htm": [
    "9a27f71e6e5738d2625ed30f91f3d514fc3646e8",
    "testharness"
   ],
+  "xhr/header-user-agent-async.htm": [
+   "07833728cf33836e854681d8e53c2b5357f8f810",
+   "testharness"
+  ],
+  "xhr/header-user-agent-sync.htm": [
+   "e7f02cf698647785d332e4ad517ff0df357eea70",
+   "testharness"
+  ],
   "xhr/headers-normalize-response.htm": [
    "eb7c4df4a878181161f356cfaed84e37ccd6f772",
    "testharness"
   ],
   "xhr/historical.html": [
    "1cb82348a9d6f3be34da762267cce7389f715f7c",
    "testharness"
   ],
@@ -612108,16 +612133,20 @@
   "xhr/resources/gzip.py": [
    "a259f50e91a706acf4d9d0be8a01bd046544ea55",
    "support"
   ],
   "xhr/resources/header-content-length.asis": [
    "a191134704e09ff9bb6591dc8c6aa78307edf6c9",
    "support"
   ],
+  "xhr/resources/header-user-agent.py": [
+   "26af60bcffd2c78dd7ee89a98a02fde12aee41a9",
+   "support"
+  ],
   "xhr/resources/headers-basic.asis": [
    "718e90fc73ec596127d26fba5433c5355e93fa3f",
    "support"
   ],
   "xhr/resources/headers.asis": [
    "4f704b9f6f89a0152443a08eb7adf84415009ad1",
    "support"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/xhr/header-user-agent-async.htm
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>Test that async requests (both OPTIONS preflight and regular) are sent with the User-Agent header</title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/common/get-host-info.sub.js"></script>
+</head>
+<body>
+<script type="text/javascript">
+  async_test((test) => {
+    let xhr = new XMLHttpRequest;
+    xhr.open("GET", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/header-user-agent.py");
+    xhr.setRequestHeader("x-test", "foobar");
+
+    xhr.onerror = test.unreached_func("Unexpected error");
+
+    xhr.onload = test.step_func_done(() => {
+      assert_equals(xhr.responseText, "PASS");
+    });
+
+    xhr.send();
+  }, "Async request has User-Agent header");
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/xhr/header-user-agent-sync.htm
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>Test that sync requests (both OPTIONS preflight and regular) are sent with the User-Agent header</title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/common/get-host-info.sub.js"></script>
+</head>
+<body>
+<script type="text/javascript">
+  test(function() {
+    let xhr = new XMLHttpRequest;
+    xhr.open("post", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/header-user-agent.py", false);
+    xhr.setRequestHeader("x-test", "foobar");
+    xhr.send();
+    assert_equals(xhr.responseText, "PASS");
+  }, "Sync request has User-Agent header");
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/xhr/resources/header-user-agent.py
@@ -0,0 +1,15 @@
+def main(request, response):
+    response.headers.set("Access-Control-Allow-Origin", "*")
+    response.headers.set("Access-Control-Max-Age", 0)
+    response.headers.set('Access-Control-Allow-Headers', "x-test")
+
+    if request.method == "OPTIONS":
+        if not request.headers.get("User-Agent"):
+            response.content = "FAIL: User-Agent header missing in preflight request."
+            response.status = 400
+    else:
+        if request.headers.get("User-Agent"):
+            response.content = "PASS"
+        else:
+            response.content = "FAIL: User-Agent header missing in request"
+            response.status = 400