mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 05:39:41 +02:00
MozReview-Commit-ID: GmGgeZxHy0j --HG-- rename : testing/web-platform/tests/content-security-policy/media-src/media-src-7_1_2.html.sub.headers => testing/web-platform/tests/content-security-policy/media-src/media-src-7_1_2.sub.html.sub.headers rename : testing/web-platform/tests/content-security-policy/media-src/media-src-7_2_2.html.sub.headers => testing/web-platform/tests/content-security-policy/media-src/media-src-7_2_2.sub.html.sub.headers rename : testing/web-platform/tests/content-security-policy/media-src/media-src-7_3_2.html.sub.headers => testing/web-platform/tests/content-security-policy/media-src/media-src-7_3_2.sub.html.sub.headers rename : testing/web-platform/tests/html/browsers/windows/nested-browsing-contexts/test.html => testing/web-platform/tests/html/browsers/windows/nested-browsing-contexts/resources/frameElement-nested-frame.html rename : testing/web-platform/tests/html/browsers/windows/nested-browsing-contexts/testcase3.html => testing/web-platform/tests/html/browsers/windows/nested-browsing-contexts/resources/frameElement-window-post.html rename : testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/PresentationAvailability_onchange-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onmessage-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_onmessage-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_send-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/PresentationConnection_send-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_error.html => testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_error.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_onconnectionavailable-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_onconnectionavailable-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_error.html => testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_error.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_success.html => testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_sandboxing_success.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_success.html => testing/web-platform/tests/presentation-api/controlling-ua/PresentationRequest_success.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest_success-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/defaultRequest_success-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/getAvailability.html => testing/web-platform/tests/presentation-api/controlling-ua/getAvailability.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/getAvailability_sandboxing_success.html => testing/web-platform/tests/presentation-api/controlling-ua/getAvailability_sandboxing_success.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_notfound_error.html => testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_notfound_error.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_sandboxing_success.html => testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_sandboxing_success.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_success-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/reconnectToPresentation_success-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotallowed-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotallowed-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotfound-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_displaynotfound-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_error.html => testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_error.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_sandboxing_success-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_sandboxing_success-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_success-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_success-manual.https.html rename : testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_unsettledpromise-manual.html => testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_unsettledpromise-manual.https.html rename : testing/web-platform/tests/presentation-api/receiving-ua/idlharness-manual.html => testing/web-platform/tests/presentation-api/receiving-ua/idlharness-manual.https.html rename : testing/web-platform/tests/presentation-api/receiving-ua/support/idlharness_receiving-ua.html => testing/web-platform/tests/presentation-api/receiving-ua/support/idlharness_receiving-ua.https.html rename : testing/web-platform/tests/webdriver/util/http_request.py => testing/web-platform/tests/webdriver/support/http_request.py
81 lines
4.9 KiB
JavaScript
81 lines
4.9 KiB
JavaScript
// META: script=../resources/utils.js
|
|
|
|
function checkContentType(contentType, body)
|
|
{
|
|
if (self.FormData && body instanceof self.FormData) {
|
|
assert_true(contentType.startsWith("multipart/form-data; boundary="), "Request should have header content-type starting with multipart/form-data; boundary=, but got " + contentType);
|
|
return;
|
|
}
|
|
|
|
var expectedContentType = "text/plain;charset=UTF-8";
|
|
if(body === null || body instanceof ArrayBuffer || body.buffer instanceof ArrayBuffer)
|
|
expectedContentType = null;
|
|
else if (body instanceof Blob)
|
|
expectedContentType = body.type ? body.type : null;
|
|
else if (body instanceof URLSearchParams)
|
|
expectedContentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
|
|
|
assert_equals(contentType , expectedContentType, "Request should have header content-type: " + expectedContentType);
|
|
}
|
|
|
|
function requestHeaders(desc, url, method, body, expectedOrigin, expectedContentLength) {
|
|
var urlParameters = "?headers=origin|user-agent|accept-charset|content-length|content-type";
|
|
var requestInit = {"method": method}
|
|
promise_test(function(test){
|
|
if (typeof body === "function")
|
|
body = body();
|
|
if (body)
|
|
requestInit["body"] = body;
|
|
return fetch(url + urlParameters, requestInit).then(function(resp) {
|
|
assert_equals(resp.status, 200, "HTTP status is 200");
|
|
assert_equals(resp.type , "basic", "Response's type is basic");
|
|
assert_true(resp.headers.has("x-request-user-agent"), "Request has header user-agent");
|
|
assert_false(resp.headers.has("accept-charset"), "Request has header accept-charset");
|
|
assert_equals(resp.headers.get("x-request-origin") , expectedOrigin, "Request should have header origin: " + expectedOrigin);
|
|
if (expectedContentLength !== undefined)
|
|
assert_equals(resp.headers.get("x-request-content-length") , expectedContentLength, "Request should have header content-length: " + expectedContentLength);
|
|
checkContentType(resp.headers.get("x-request-content-type"), body);
|
|
});
|
|
}, desc);
|
|
}
|
|
|
|
var url = RESOURCES_DIR + "inspect-headers.py"
|
|
|
|
requestHeaders("Fetch with GET", url, "GET", null, null, null);
|
|
requestHeaders("Fetch with HEAD", url, "HEAD", null, null, null);
|
|
requestHeaders("Fetch with PUT without body", url, "POST", null, location.origin, "0");
|
|
requestHeaders("Fetch with PUT with body", url, "PUT", "Request's body", location.origin, "14");
|
|
requestHeaders("Fetch with POST without body", url, "POST", null, location.origin, "0");
|
|
requestHeaders("Fetch with POST with text body", url, "POST", "Request's body", location.origin, "14");
|
|
requestHeaders("Fetch with POST with FormData body", url, "POST", function() { return new FormData(); }, location.origin);
|
|
requestHeaders("Fetch with POST with URLSearchParams body", url, "POST", function() { return new URLSearchParams("name=value"); }, location.origin, "10");
|
|
requestHeaders("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), location.origin, "4");
|
|
requestHeaders("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), location.origin, "4");
|
|
requestHeaders("Fetch with POST with Uint8Array body", url, "POST", new Uint8Array(4), location.origin, "4");
|
|
requestHeaders("Fetch with POST with Int8Array body", url, "POST", new Int8Array(4), location.origin, "4");
|
|
requestHeaders("Fetch with POST with Float32Array body", url, "POST", new Float32Array(1), location.origin, "4");
|
|
requestHeaders("Fetch with POST with Float64Array body", url, "POST", new Float64Array(1), location.origin, "8");
|
|
requestHeaders("Fetch with POST with DataView body", url, "POST", new DataView(new ArrayBuffer(8), 0, 4), location.origin, "4");
|
|
requestHeaders("Fetch with POST with Blob body with mime type", url, "POST", new Blob(["Test"], { type: "text/maybe" }), location.origin, "4");
|
|
requestHeaders("Fetch with Chicken", url, "Chicken", null, location.origin, null);
|
|
requestHeaders("Fetch with Chicken with body", url, "Chicken", "Request's body", location.origin, "14");
|
|
|
|
function requestOriginHeader(method, mode, needsOrigin) {
|
|
promise_test(function(test){
|
|
return fetch(url + "?headers=origin", {method:method, mode:mode}).then(function(resp) {
|
|
assert_equals(resp.status, 200, "HTTP status is 200");
|
|
assert_equals(resp.type , "basic", "Response's type is basic");
|
|
if(needsOrigin)
|
|
assert_equals(resp.headers.get("x-request-origin") , location.origin, "Request should have an Origin header with origin: " + location.origin);
|
|
else
|
|
assert_equals(resp.headers.get("x-request-origin"), null, "Request should not have an Origin header")
|
|
});
|
|
}, "Fetch with " + method + " and mode \"" + mode + "\" " + (needsOrigin ? "needs" : "does not need") + " an Origin header");
|
|
}
|
|
|
|
requestOriginHeader("GET", "cors", false);
|
|
requestOriginHeader("POST", "same-origin", true);
|
|
requestOriginHeader("POST", "no-cors", true);
|
|
requestOriginHeader("PUT", "same-origin", true);
|
|
requestOriginHeader("TacO", "same-origin", true);
|
|
requestOriginHeader("TacO", "cors", true);
|