Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align Fetch Request tests with WebKit ones #2549

Merged
merged 2 commits into from Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion fetch/api/request/request-clone.sub.html
Expand Up @@ -11,7 +11,7 @@
</head>
<body>
<script>
var headers = new Headers( {"name":"value"} );
var headers = new Headers({"name" : "value"});
var emptyHeaders = new Headers();

var initValuesDict = {"method" : "POST",
Expand Down Expand Up @@ -43,6 +43,21 @@
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>
18 changes: 18 additions & 0 deletions fetch/api/request/request-consume.html
Expand Up @@ -84,6 +84,24 @@
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": value});
return promise_rejects(test, new SyntaxError(), request.json());
}, "Trying to consume bad JSON text as JSON: '" + value + "'");
});
</script>
</body>
</html>
7 changes: 5 additions & 2 deletions fetch/api/request/request-init-002.html
Expand Up @@ -29,14 +29,17 @@
assert_throws(new TypeError(),
function() { new Request("", {"method": "GET", "body": body}); }
);
assert_throws(new TypeError(),
function() { new Request("", {"method": "HEAD", "body": body}); }
);
var reqHeaders = request.headers;
var mime = reqHeaders.get("Content-Type");
assert_true(mime && mime.search(bodyType) > -1, "Content-Type header should be \"" + bodyType + "\", not \"" + mime + "\"");
return request.text().then(function(bodyAsText) {
//not equals: cannot guess formData exact value
assert_true( bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify request body");
});
}, "Initialize Response's body with " + bodyType);
}, "Initialize Request's body with " + bodyType);
}

var blob = new Blob(["This is a blob"], {type: "application/octet-binary"});
Expand All @@ -55,7 +58,7 @@
} else {
promise_test(function(test) {
return Promise.reject("URLSearchParams not supported");
}, "Initialize Response's body with application/x-www-form-urlencoded;charset=UTF-8");
}, "Initialize Request's body with application/x-www-form-urlencoded;charset=UTF-8");
}
</script>
</body>
Expand Down
8 changes: 5 additions & 3 deletions fetch/api/request/request-structure.html
Expand Up @@ -51,7 +51,7 @@
break;

case "headers":
request.headers = new Headers ( {"name":"value"} );
request.headers = new Headers ({"name":"value"});
assert_false(request.headers.has("name"), "Headers attribute is read only");
return;
break;
Expand Down Expand Up @@ -117,16 +117,18 @@
"Attribute " + attributeToCheck + " is read only. Default value is " + defaultValue);
}

for (var idx in methods)
for (var idx in methods) {
test(function() {
assert_true(methods[idx] in request, "request has " + methods[idx] + " method");
}, "Request has " + methods[idx] + " method");
}

for (var idx in attributes)
for (var idx in attributes) {
test(function() {
assert_true(attributes[idx] in request, "request has " + attributes[idx] + " attribute");
IsreadOnly(request, attributes[idx]);
}, "Check " + attributes[idx] + " attribute");
}
</script>
</body>
</html>