Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[Fetch API] Implement Fetch API Request
https://bugs.webkit.org/show_bug.cgi?id=153437 LayoutTests/imported/w3c: Reviewed by Darin Adler. * web-platform-tests/fetch/api/headers/headers-basic.html: * web-platform-tests/fetch/api/request/request-clone.sub-expected.txt: Added. * web-platform-tests/fetch/api/request/request-clone.sub.html: Added. * web-platform-tests/fetch/api/request/request-consume-expected.txt: Added. * web-platform-tests/fetch/api/request/request-consume.html: Added. * web-platform-tests/fetch/api/request/request-disturbed-expected.txt: Added. * web-platform-tests/fetch/api/request/request-disturbed.html: Added. * web-platform-tests/fetch/api/request/request-error-expected.txt: Added. * web-platform-tests/fetch/api/request/request-error.html: Added. * web-platform-tests/fetch/api/request/request-headers-expected.txt: Added. * web-platform-tests/fetch/api/request/request-headers.html: Added. * web-platform-tests/fetch/api/request/request-idl-expected.txt: Added. * web-platform-tests/fetch/api/request/request-idl.html: Added. * web-platform-tests/fetch/api/request/request-init-001.sub-expected.txt: Added. * web-platform-tests/fetch/api/request/request-init-001.sub.html: Added. * web-platform-tests/fetch/api/request/request-init-002-expected.txt: Added. * web-platform-tests/fetch/api/request/request-init-002.html: Added. * web-platform-tests/fetch/api/request/request-init-003.sub-expected.txt: Added. * web-platform-tests/fetch/api/request/request-init-003.sub.html: Added. * web-platform-tests/fetch/api/request/request-structure-expected.txt: Added. * web-platform-tests/fetch/api/request/request-structure.html: Added. * web-platform-tests/fetch/api/resources/authentication.py: Added. (main): * web-platform-tests/fetch/api/resources/clean-stash.py: Added. (main): * web-platform-tests/fetch/api/resources/inspect-headers.py: Added. (main): * web-platform-tests/fetch/api/resources/method.py: Added. (main): * web-platform-tests/fetch/api/resources/preflight.py: Added. (main): * web-platform-tests/fetch/api/resources/redirect.py: Added. (main): * web-platform-tests/fetch/api/resources/top.txt: Added. * web-platform-tests/fetch/api/resources/trickle.py: Added. (main): * web-platform-tests/fetch/api/resources/utils.js: Added. (catch): (dirname): (checkRequest): (readTextStream): Source/WebCore: Added support for Fetch Request and Body. Body is sharing functionality between Request and Response. Conversion between various body types are not implemented yet. Added a FetchOptions class. Options in this class are partially redundant with ResourceLoaderOptions. Fixing bug in Headers constructor. Making error reporting in case of modifying headers compliant with the spec. Reviewed by Darin Adler. Tests: imported/w3c/web-platform-tests/fetch/api/request/request-clone.sub.html imported/w3c/web-platform-tests/fetch/api/request/request-consume.html imported/w3c/web-platform-tests/fetch/api/request/request-disturbed.html imported/w3c/web-platform-tests/fetch/api/request/request-error.html imported/w3c/web-platform-tests/fetch/api/request/request-headers.html imported/w3c/web-platform-tests/fetch/api/request/request-idl.html imported/w3c/web-platform-tests/fetch/api/request/request-init-001.sub.html imported/w3c/web-platform-tests/fetch/api/request/request-init-002.html imported/w3c/web-platform-tests/fetch/api/request/request-init-003.sub.html imported/w3c/web-platform-tests/fetch/api/request/request-structure.html * CMakeLists.txt: * DerivedSources.cpp: * DerivedSources.make: * Modules/fetch/FetchBody.cpp: Added. (WebCore::FetchBody::initBody): (WebCore::FetchBody::clear): (WebCore::FetchBody::processIfEmptyOrDisturbed): (WebCore::FetchBody::arrayBuffer): (WebCore::FetchBody::formData): (WebCore::FetchBody::blob): (WebCore::FetchBody::text): (WebCore::FetchBody::json): * Modules/fetch/FetchBody.h: Added. (WebCore::FetchBody::~FetchBody): (WebCore::FetchBody::isEmpty): (WebCore::FetchBody::isDisturbed): (WebCore::FetchBody::setDisturbed): (WebCore::FetchBody::setMimeType): (WebCore::FetchBody::mimeType): * Modules/fetch/FetchBody.idl: Added. * Modules/fetch/FetchHeaders.cpp: (WebCore::canWriteHeader): (WebCore::FetchHeaders::append): (WebCore::FetchHeaders::remove): (WebCore::FetchHeaders::set): (WebCore::FetchHeaders::fill): Helper routine implementing https://fetch.spec.whatwg.org/#concept-headers-fill * Modules/fetch/FetchHeaders.h: Adding header getter/setter for FetchRequest. (WebCore::FetchHeaders::fastGet): (WebCore::FetchHeaders::fastSet): * Modules/fetch/FetchHeaders.js: Fixing bug in constructor (covered by modified headers-basc.html test). (initializeFetchHeaders): * Modules/fetch/FetchOptions.h: Added. (WebCore::FetchOptions::FetchOptions): (WebCore::FetchOptions::type): (WebCore::FetchOptions::destination): (WebCore::FetchOptions::mode): (WebCore::FetchOptions::credentials): (WebCore::FetchOptions::cache): (WebCore::FetchOptions::redirect): (WebCore::FetchOptions::referrerPolicy): (WebCore::FetchOptions::setType): (WebCore::FetchOptions::setDestination): (WebCore::FetchOptions::setMode): (WebCore::FetchOptions::setCredentials): (WebCore::FetchOptions::setCache): (WebCore::FetchOptions::setRedirect): (WebCore::FetchOptions::setReferrerPolicy): * Modules/fetch/FetchRequest.cpp: Added. (WebCore::FetchRequest::create): (WebCore::FetchRequest::FetchRequest): (WebCore::FetchRequest::init): (WebCore::FetchRequest::setReferrer): (WebCore::FetchRequest::setReferrerPolicy): (WebCore::FetchRequest::setMode): (WebCore::FetchRequest::setCredentials): (WebCore::FetchRequest::setCache): (WebCore::FetchRequest::setRedirect): (WebCore::FetchRequest::type): (WebCore::FetchRequest::destination): (WebCore::FetchRequest::referrerPolicy): (WebCore::FetchRequest::referrer): (WebCore::FetchRequest::mode): (WebCore::FetchRequest::credentials): (WebCore::FetchRequest::cache): (WebCore::FetchRequest::redirect): (WebCore::FetchRequest::setMethod): (WebCore::FetchRequest::clone): * Modules/fetch/FetchRequest.h: Added. (WebCore::FetchRequest::method): (WebCore::FetchRequest::url): (WebCore::FetchRequest::integrity): (WebCore::FetchRequest::headers): * Modules/fetch/FetchRequest.idl: Added. * WebCore.xcodeproj/project.pbxproj: * bindings/js/Dictionary.h: (WebCore::Dictionary::execState): * bindings/js/JSDictionary.cpp: (WebCore::JSDictionary::convertValue): * bindings/js/JSDictionary.h: (WebCore::JSDictionary::get): LayoutTests: Reviewed by Darin Adler. * js/dom/global-constructors-attributes-dedicated-worker-expected.txt: * js/dom/global-constructors-attributes-expected.txt: * platform/efl/js/dom/global-constructors-attributes-dedicated-worker-expected.txt: * platform/efl/js/dom/global-constructors-attributes-expected.txt: * platform/gtk/js/dom/global-constructors-attributes-expected.txt: * platform/mac-mavericks/js/dom/global-constructors-attributes-expected.txt: * platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt: * platform/mac/js/dom/global-constructors-attributes-expected.txt: * platform/win/js/dom/global-constructors-attributes-expected.txt: Canonical link: https://commits.webkit.org/171821@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195954 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
2,758 additions
and 12 deletions.
- +17 −0 LayoutTests/ChangeLog
- +49 −0 LayoutTests/imported/w3c/ChangeLog
- +1 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/headers-basic.html
- +4 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-clone.sub-expected.txt
- +63 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-clone.sub.html
- +15 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-expected.txt
- +107 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html
- +7 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt
- +55 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed.html
- +17 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-error-expected.txt
- +75 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-error.html
- +56 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-headers-expected.txt
- +150 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-headers.html
- +52 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-idl-expected.txt
- +85 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-idl.html
- +36 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-001.sub-expected.txt
- +90 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-001.sub.html
- +7 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002-expected.txt
- +65 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-002.html
- +6 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-003.sub-expected.txt
- +84 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-init-003.sub.html
- +21 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-structure-expected.txt
- +134 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-structure.html
- +15 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/authentication.py
- +6 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/clean-stash.py
- +22 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/inspect-headers.py
- +11 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/method.py
- +56 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/preflight.py
- +48 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/redirect.py
- +1 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/top.txt
- +12 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/trickle.py
- +66 −0 LayoutTests/imported/w3c/web-platform-tests/fetch/api/resources/utils.js
- +5 −0 LayoutTests/js/dom/global-constructors-attributes-dedicated-worker-expected.txt
- +5 −0 LayoutTests/js/dom/global-constructors-attributes-expected.txt
- +5 −0 LayoutTests/platform/efl/js/dom/global-constructors-attributes-dedicated-worker-expected.txt
- +5 −0 LayoutTests/platform/efl/js/dom/global-constructors-attributes-expected.txt
- +5 −0 LayoutTests/platform/gtk/js/dom/global-constructors-attributes-expected.txt
- +5 −0 LayoutTests/platform/mac-mavericks/js/dom/global-constructors-attributes-expected.txt
- +5 −0 LayoutTests/platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt
- +5 −0 LayoutTests/platform/mac/js/dom/global-constructors-attributes-expected.txt
- +5 −0 LayoutTests/platform/win/js/dom/global-constructors-attributes-expected.txt
- +4 −0 Source/WebCore/CMakeLists.txt
- +108 −0 Source/WebCore/ChangeLog
- +2 −0 Source/WebCore/DerivedSources.cpp
- +2 −0 Source/WebCore/DerivedSources.make
- +181 −0 Source/WebCore/Modules/fetch/FetchBody.cpp
- +98 −0 Source/WebCore/Modules/fetch/FetchBody.h
- +42 −0 Source/WebCore/Modules/fetch/FetchBody.idl
- +28 −12 Source/WebCore/Modules/fetch/FetchHeaders.cpp
- +6 −0 Source/WebCore/Modules/fetch/FetchHeaders.h
- +1 −0 Source/WebCore/Modules/fetch/FetchHeaders.js
- +132 −0 Source/WebCore/Modules/fetch/FetchOptions.h
- +451 −0 Source/WebCore/Modules/fetch/FetchRequest.cpp
- +104 −0 Source/WebCore/Modules/fetch/FetchRequest.h
- +64 −0 Source/WebCore/Modules/fetch/FetchRequest.idl
- +34 −0 Source/WebCore/WebCore.xcodeproj/project.pbxproj
- +2 −0 Source/WebCore/bindings/js/Dictionary.h
- +11 −0 Source/WebCore/bindings/js/JSDictionary.cpp
- +10 −0 Source/WebCore/bindings/js/JSDictionary.h
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,4 @@ | ||
|
||
FAIL Check cloning a request ExpectedValuesDict["headers"].keys is not a function. (In 'ExpectedValuesDict["headers"].keys()', 'ExpectedValuesDict["headers"].keys' is undefined) | ||
PASS Check cloning a request copies the headers | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,63 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Request clone</title> | ||
<meta name="help" href="https://fetch.spec.whatwg.org/#request"> | ||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="../resources/utils.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
var headers = new Headers( {"name" : "value"} ); | ||
var emptyHeaders = new Headers(); | ||
|
||
var initValuesDict = {"method" : "POST", | ||
"referrer" : "http://{{host}}:{{ports[http][0]}}/", | ||
"referrerPolicy" : "origin-only", | ||
"mode" : "same-origin", | ||
"credentials" : "include", | ||
"cache" : "no-cache", | ||
"redirect" : "error", | ||
"integrity" : "Request's Integrity", | ||
"headers" : headers, | ||
"body" : "Request's body" | ||
}; | ||
|
||
var expectedInitialized = {"method" : "POST", | ||
"referrer" : "http://{{host}}:{{ports[http][0]}}/", | ||
"referrerPolicy" : "origin-only", | ||
"mode" : "same-origin", | ||
"credentials" : "include", | ||
"cache" : "no-cache", | ||
"redirect" : "error", | ||
"integrity" : "Request's Integrity", | ||
"headers" : headers, | ||
"body" : "Request's body" | ||
}; | ||
|
||
test(function() { | ||
var RequestInitialized = new Request("", initValuesDict); | ||
var requestToCheck = RequestInitialized.clone(); | ||
checkRequest(requestToCheck, expectedInitialized); | ||
}, "Check cloning a request"); | ||
|
||
test(function() { | ||
var initialRequest = new Request("", {"headers" : new Headers({"a": "1", "b" : "2"})}); | ||
var request = initialRequest.clone(); | ||
assert_equals(request.headers.get("a"), "1", "cloned request should have header 'a'"); | ||
assert_equals(request.headers.get("b"), "2", "cloned request should have header 'b'"); | ||
|
||
initialRequest.headers.delete("a"); | ||
assert_equals(request.headers.get("a"), "1", "cloned request should still have header 'a'"); | ||
|
||
request.headers.delete("a"); | ||
assert_equals(initialRequest.headers.get("b"), "2", "initial request should have header 'b'"); | ||
|
||
}, "Check cloning a request copies the headers"); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,15 @@ | ||
|
||
PASS Consume request's body as text | ||
FAIL Consume request's body as blob promise_test: Unhandled rejection with value: undefined | ||
PASS Consume request's body as arrayBuffer | ||
PASS Consume request's body as json | ||
FAIL Consume request's body as formData promise_test: Unhandled rejection with value: undefined | ||
PASS Consume JSON from text: '"null"' | ||
PASS Consume JSON from text: '"1"' | ||
PASS Consume JSON from text: '"true"' | ||
PASS Consume JSON from text: '"\"string\""' | ||
PASS Trying to consume bad JSON text as JSON: 'undefined' | ||
PASS Trying to consume bad JSON text as JSON: '{' | ||
PASS Trying to consume bad JSON text as JSON: 'a' | ||
PASS Trying to consume bad JSON text as JSON: '[' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,107 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Request consume</title> | ||
<meta name="help" href="https://fetch.spec.whatwg.org/#request"> | ||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin"> | ||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
function checkBodyText(request, expectedBody) { | ||
return request.text().then( function(bodyAsText) { | ||
assert_equals(bodyAsText, expectedBody, "Retrieve and verify request's body"); | ||
assert_true(request.bodyUsed, "body as text: bodyUsed turned true"); | ||
}); | ||
} | ||
|
||
function checkBodyBlob(request, expectedBody) { | ||
return request.blob().then(function(bodyAsBlob) { | ||
var promise = new Promise(function (resolve, reject) { | ||
var reader = new FileReader(); | ||
reader.onload = function(evt) { | ||
resolve(reader.result) | ||
}; | ||
reader.onerror = function() { | ||
reject("Blob's reader failed"); | ||
}; | ||
reader.readAsText(bodyAsBlob); | ||
}); | ||
return promise.then(function(body) { | ||
assert_equals(body, expectedBody, "Retrieve and verify request's body"); | ||
assert_true(request.bodyUsed, "body as blob: bodyUsed turned true"); | ||
}); | ||
}); | ||
} | ||
|
||
<!-- Taken from https://developers.google.com --> | ||
function str2ab(str) { | ||
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char | ||
var bufView = new Uint16Array(buf); | ||
for (var i=0, strLen=str.length; i < strLen; i++) { | ||
bufView[i] = str.charCodeAt(i); | ||
} | ||
return buf; | ||
} | ||
|
||
function checkBodyArrayBuffer(request, expectedBody) { | ||
return request.arrayBuffer().then( function(bodyAsArrayBuffer) { | ||
assert_array_equals(bodyAsArrayBuffer, str2ab(expectedBody), "Retrieve and verify request's body"); | ||
assert_true(request.bodyUsed, "body as arrayBuffer: bodyUsed turned true"); | ||
}); | ||
} | ||
|
||
function checkBodyJSON(request, expectedBody) { | ||
return request.json().then(function(bodyAsJSON) { | ||
var strBody = JSON.stringify(bodyAsJSON) | ||
assert_equals(strBody, expectedBody, "Retrieve and verify request's body"); | ||
assert_true(request.bodyUsed, "body as json: bodyUsed turned true"); | ||
}); | ||
} | ||
|
||
function checkBodyFormData(request, expectedBody) { | ||
return request.formData().then(function(bodyAsFormData) { | ||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData"); | ||
assert_true(request.bodyUsed, "body as formData: bodyUsed turned true"); | ||
}); | ||
} | ||
|
||
function checkRequestBody(body, bodyType, checkFunction) { | ||
promise_test(function(test) { | ||
var request = new Request("", {"method": "POST", "body": body }); | ||
assert_false(request.bodyUsed, "bodyUsed is false at init"); | ||
return checkFunction(request, body); | ||
}, "Consume request's body as " + bodyType); | ||
} | ||
|
||
var formData = new FormData(); | ||
formData.append("name", "value") | ||
checkRequestBody("This is request's body", "text", checkBodyText); | ||
checkRequestBody("This is request's body", "blob", checkBodyBlob); | ||
checkRequestBody("This is request's body", "arrayBuffer", checkBodyArrayBuffer); | ||
checkRequestBody(JSON.stringify("This is request's body"), "json", checkBodyJSON); | ||
checkRequestBody(formData, "formData", checkBodyFormData); | ||
|
||
var goodJSONValues = ["null", "1", "true", "\"string\""]; | ||
goodJSONValues.forEach(function(value) { | ||
promise_test(function(test) { | ||
var request = new Request("", {"method": "POST", "body": value}); | ||
return request.json().then(function(v) { | ||
assert_equals(v, JSON.parse(value)); | ||
}); | ||
}, "Consume JSON from text: '" + JSON.stringify(value) + "'"); | ||
}); | ||
|
||
var badJSONValues = ["undefined", "{", "a", "["]; | ||
badJSONValues.forEach(function(value) { | ||
promise_test(function(test) { | ||
var request = new Request("", {"method": "POST", "body": "{"}); | ||
return promise_rejects(test, new SyntaxError(), request.json()); | ||
}, "Trying to consume bad JSON text as JSON: '" + value + "'"); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,7 @@ | ||
|
||
PASS Request without body cannot be disturbed | ||
PASS Check cloning a disturbed request | ||
PASS Check creating a new request from a disturbed request | ||
PASS Input request used for creating new request became disturbed | ||
PASS Check consuming a disturbed request | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,55 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Request disturbed</title> | ||
<meta name="help" href="https://fetch.spec.whatwg.org/#request"> | ||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin"> | ||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
var initValuesDict = {"method" : "POST", | ||
"body" : "Request's body" | ||
}; | ||
|
||
var noBodyConsumed = new Request(""); | ||
noBodyConsumed.blob(); | ||
var bodyConsumed = new Request("", initValuesDict); | ||
bodyConsumed.blob(); | ||
|
||
test(function() { | ||
assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request is not disturbed"); | ||
try { | ||
noBodyConsumed.clone(); | ||
} catch (e) { | ||
assert_unreached("Can use request not disturbed for creating or cloning request"); | ||
} | ||
}, "Request without body cannot be disturbed"); | ||
|
||
test(function() { | ||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed"); | ||
assert_throws(new TypeError(), function() { bodyConsumed.clone(); }); | ||
}, "Check cloning a disturbed request"); | ||
|
||
test(function() { | ||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed"); | ||
assert_throws(new TypeError(), function() { new Request(bodyConsumed); }); | ||
}, "Check creating a new request from a disturbed request"); | ||
|
||
test(function() { | ||
var bodyRequest = new Request("", initValuesDict); | ||
assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed"); | ||
var requestFromRequest = new Request(bodyRequest); | ||
assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed"); | ||
}, "Input request used for creating new request became disturbed"); | ||
|
||
promise_test(function(test) { | ||
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed"); | ||
return promise_rejects(test, new TypeError(), bodyConsumed.blob()); | ||
}, "Check consuming a disturbed request"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,17 @@ | ||
|
||
PASS RequestInit's window is not null | ||
PASS Input URL is not valid | ||
PASS Input URL has credentials | ||
PASS RequestInit's mode is navigate | ||
PASS RequestInit's referrer is invalid | ||
PASS RequestInit's referrer has invalid origin | ||
PASS RequestInit's method is invalid | ||
PASS RequestInit's method is forbidden | ||
PASS RequestInit's mode is no-cors and method is not simple | ||
PASS RequestInit's mode is no-cors and integrity is not empty | ||
PASS Bad referrerPolicy init parameter value | ||
PASS Bad mode init parameter value | ||
PASS Bad credentials init parameter value | ||
PASS Bad cache init parameter value | ||
PASS Bad redirect init parameter value | ||
|
Oops, something went wrong.