зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1672934 [wpt PR 26214] - [beacon] Fix ArrayBuffer and URLSearchParams data, a=testonly
Automatic update from web-platform-tests [beacon] Fix ArrayBuffer and URLSearchParams data `navigator.sendBeacon()` was not handling DOMArrayBuffer and URLSearchParams inputs properly, resulting in failing WPTs related to the sent Content-Type, as well as in the wrong data sent in the case of DOMArrayBuffers. This CL fixes that. Bug: 876671 Change-Id: I17674b3041aa0f0bdbd1a570ab34be48b0dd98b4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489986 Commit-Queue: Yoav Weiss <yoavweiss@chromium.org> Reviewed-by: Adam Rice <ricea@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Cr-Commit-Position: refs/heads/master@{#820134} -- wpt-commits: 4a65f5002f1e2e778f62a9b99f4298dc8948f26c wpt-pr: 26214
This commit is contained in:
Родитель
9700d1f887
Коммит
839746390a
|
@ -12,13 +12,13 @@
|
||||||
<script>
|
<script>
|
||||||
const RESOURCES_DIR = "/beacon/resources/";
|
const RESOURCES_DIR = "/beacon/resources/";
|
||||||
|
|
||||||
function testContentTypeHeader(what, contentType, title) {
|
function testContentTypeAndBody(what, expected, title) {
|
||||||
function wait(ms) {
|
function wait(ms) {
|
||||||
return new Promise(resolve => step_timeout(resolve, ms));
|
return new Promise(resolve => step_timeout(resolve, ms));
|
||||||
}
|
}
|
||||||
promise_test(async t => {
|
promise_test(async t => {
|
||||||
const id = self.token();
|
const id = self.token();
|
||||||
const testUrl = new Request(RESOURCES_DIR + "content-type.py?cmd=put&id=" + id).url;
|
const testUrl = new Request(RESOURCES_DIR + "content-type-and-body.py?cmd=put&id=" + id).url;
|
||||||
assert_equals(performance.getEntriesByName(testUrl).length, 0);
|
assert_equals(performance.getEntriesByName(testUrl).length, 0);
|
||||||
assert_true(navigator.sendBeacon(testUrl, what), "SendBeacon Succeeded");
|
assert_true(navigator.sendBeacon(testUrl, what), "SendBeacon Succeeded");
|
||||||
|
|
||||||
|
@ -26,13 +26,17 @@ function testContentTypeHeader(what, contentType, title) {
|
||||||
await wait(50);
|
await wait(50);
|
||||||
} while (performance.getEntriesByName(testUrl).length === 0);
|
} while (performance.getEntriesByName(testUrl).length === 0);
|
||||||
assert_equals(performance.getEntriesByName(testUrl).length, 1);
|
assert_equals(performance.getEntriesByName(testUrl).length, 1);
|
||||||
const checkUrl = RESOURCES_DIR + "content-type.py?cmd=get&id=" + id;
|
const checkUrl = RESOURCES_DIR + "content-type-and-body.py?cmd=get&id=" + id;
|
||||||
const response = await fetch(checkUrl);
|
const response = await fetch(checkUrl);
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
if (contentType === "multipart/form-data") {
|
if (expected.startsWith("multipart/form-data")) {
|
||||||
|
const split = expected.split(":");
|
||||||
|
const contentType = split[0];
|
||||||
|
const contentDisposition = "Content-Disposition: form-data; name=\"" + split[1] + "\"; filename=\"blob\"";
|
||||||
assert_true(text.startsWith(contentType), "Correct Content-Type header result");
|
assert_true(text.startsWith(contentType), "Correct Content-Type header result");
|
||||||
|
assert_true(text.includes(contentDisposition), "Body included value");
|
||||||
} else {
|
} else {
|
||||||
assert_equals(text, contentType, "Correct Content-Type header result");
|
assert_equals(text, expected, "Correct Content-Type header result");
|
||||||
}
|
}
|
||||||
}, "Test content-type header for a body " + title);
|
}, "Test content-type header for a body " + title);
|
||||||
}
|
}
|
||||||
|
@ -74,12 +78,12 @@ function stringToURLSearchParams(input)
|
||||||
return new URLSearchParams(input);
|
return new URLSearchParams(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
testContentTypeHeader("hi!", "text/plain;charset=UTF-8", "string");
|
testContentTypeAndBody("hi!", "text/plain;charset=UTF-8: hi!", "string");
|
||||||
testContentTypeHeader(stringToArrayBufferView("123"), "", "ArrayBufferView");
|
testContentTypeAndBody(stringToArrayBufferView("123"), ": 1\0" + "2\0" + "3\0", "ArrayBufferView");
|
||||||
testContentTypeHeader(stringToArrayBuffer("123"), "", "ArrayBuffer");
|
testContentTypeAndBody(stringToArrayBuffer("123"), ": 1\0" + "2\0" + "3\0", "ArrayBuffer");
|
||||||
testContentTypeHeader(stringToBlob("123"), "text/plain", "Blob");
|
testContentTypeAndBody(stringToBlob("123"), "text/plain: 123", "Blob");
|
||||||
testContentTypeHeader(stringToFormData("qwerty"), "multipart/form-data", "FormData");
|
testContentTypeAndBody(stringToFormData("qwerty"), "multipart/form-data:qwerty", "FormData");
|
||||||
testContentTypeHeader(stringToURLSearchParams("key1=value1&key2=value2"), "application/x-www-form-urlencoded;charset=UTF-8", "URLSearchParams");
|
testContentTypeAndBody(stringToURLSearchParams("key1=value1&key2=value2"), "application/x-www-form-urlencoded;charset=UTF-8: key1=value1&key2=value2", "URLSearchParams");
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -2,7 +2,7 @@ def main(request, response):
|
||||||
command = request.GET.first(b"cmd").lower()
|
command = request.GET.first(b"cmd").lower()
|
||||||
test_id = request.GET.first(b"id")
|
test_id = request.GET.first(b"id")
|
||||||
if command == b"put":
|
if command == b"put":
|
||||||
request.server.stash.put(test_id, request.headers.get(b"Content-Type", b""))
|
request.server.stash.put(test_id, request.headers.get(b"Content-Type", b"") + ": " + request.body)
|
||||||
return [(b"Content-Type", b"text/plain")], u""
|
return [(b"Content-Type", b"text/plain")], u""
|
||||||
|
|
||||||
if command == b"get":
|
if command == b"get":
|
Загрузка…
Ссылка в новой задаче