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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/basic/scheme-data.js

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 if (this.document === undefined) {
2 importScripts("/resources/testharness.js");
3 importScripts("../resources/utils.js");
4 }
5
6 function checkFetchResponse(url, data, mime, fetchMode, method) {
7 var cut = (url.length >= 40) ? "[...]" : "";
8 desc = "Fetching " + (method ? "[" + method + "] " : "") + url.substring(0, 40 ) + cut + " is OK";
9 var init = {"method": method || "GET"};
10 if (fetchMode) {
11 init.mode = fetchMode;
12 desc += " (" + fetchMode + ")";
13 }
14 promise_test(function(test) {
15 return fetch(url, init).then(function(resp) {
16 assert_equals(resp.status, 200, "HTTP status is 200");
17 assert_equals(resp.statusText, "OK", "HTTP statusText is OK");
18 assert_equals(resp.type, "basic", "response type is basic");
19 assert_equals(resp.headers.get("Content-Type"), mime, "Content-Type is " + resp.headers.get("Content-Type"));
20 return resp.text();
21 }).then(function(body) {
22 assert_equals(body, data, "Response's body is correct");
23 });
24 }, desc);
25 }
26
27 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;c harset=US-ASCII");
28 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;c harset=US-ASCII", "same-origin");
29 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;c harset=US-ASCII", "cors");
30 checkFetchResponse("data:text/plain;base64,cmVzcG9uc2UncyBib2R5", "response's bo dy", "text/plain");
31 checkFetchResponse("data:image/png;base64,cmVzcG9uc2UncyBib2R5",
32 "response's body",
33 "image/png");
34 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;c harset=US-ASCII", null, "POST");
35 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;c harset=US-ASCII", null, "HEAD");
36
37 function checkKoUrl(url, method, desc) {
38 var cut = (url.length >= 40) ? "[...]" : "";
39 desc = "Fetching [" + method + "] " + url.substring(0, 45) + cut + " is KO"
40 promise_test(function(test) {
41 return promise_rejects(test, new TypeError(), fetch(url, {"method": method}) );
42 }, desc);
43 }
44
45 checkKoUrl("data:notAdataUrl.com", "GET");
46
47 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698