Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/response/response-init-002.html

Issue 2778753002: Import //fetch from Web Platform Tests. (Closed)
Patch Set: Baselines. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Response init: body and headers</title>
6 <meta name="help" href="https://fetch.spec.whatwg.org/#response">
7 <meta name="help" href="https://fetch.spec.whatwg.org/#concept-response">
8 <meta name="author" title="Canon Research France" href="https://www.crf.cano n.fr">
9 <script src="/resources/testharness.js"></script>
10 <script src="/resources/testharnessreport.js"></script>
11 </head>
12 <body>
13 <script src="../resources/utils.js"></script>
14 <script>
15 test(function() {
16 var headerDict = {"name1": "value1",
17 "name2": "value2",
18 "name3": "value3"
19 };
20 var headers = new Headers(headerDict);
21 var response = new Response("", { "headers" : headers })
22 for (var name in headerDict) {
23 assert_equals(response.headers.get(name), headerDict[name],
24 "response's headers has " + name + " : " + headerDict[name]);
25 }
26 }, "Initialize Response with headers values");
27
28 function checkResponseInit(body, bodyType, expectedTextBody) {
29 promise_test(function(test) {
30 var response = new Response(body);
31 var resHeaders = response.headers;
32 var mime = resHeaders.get("Content-Type");
33 assert_true(mime && mime.search(bodyType) > -1, "Content-Type header s hould be \"" + bodyType + "\" ");
34 return response.text().then(function(bodyAsText) {
35 //not equals: cannot guess formData exact value
36 assert_true(bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify response body");
37 });
38 }, "Initialize Response's body with " + bodyType);
39 }
40
41 var blob = new Blob(["This is a blob"], {type: "application/octet-binary"} );
42 var formaData = new FormData();
43 formaData.append("name", "value");
44 var urlSearchParams = "URLSearchParams are not supported";
45 //avoid test timeout if not implemented
46 if (window.URLSearchParams)
47 urlSearchParams = new URLSearchParams("name=value");
48 var usvString = "This is a USVString"
49
50 checkResponseInit(blob, "application/octet-binary", "This is a blob");
51 checkResponseInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\n value");
52 checkResponseInit(urlSearchParams, "application/x-www-form-urlencoded;char set=UTF-8", "name=value");
53 checkResponseInit(usvString, "text/plain;charset=UTF-8", "This is a USVStr ing");
54
55 promise_test(function(test) {
56 var body = "This is response body";
57 var response = new Response(body);
58 return validateStreamFromString(response.body.getReader(), body);
59 }, "Read Response's body as readableStream");
60
61 promise_test(function(test) {
62 var response = new Response("This is my fork", {"headers" : [["Content-T ype", ""]]});
63 return response.blob().then(function(blob) {
64 assert_equals(blob.type, "", "Blob type should be the empty string");
65 });
66 }, "Testing empty Response Content-Type header");
67
68 </script>
69 </body>
70 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698