scheme-data.any.js (2055B)
1 // META: global=window,worker 2 // META: script=../resources/utils.js 3 4 function checkFetchResponse(url, data, mime, fetchMode, method) { 5 var cut = (url.length >= 40) ? "[...]" : ""; 6 var desc = "Fetching " + (method ? "[" + method + "] " : "") + url.substring(0, 40) + cut + " is OK"; 7 var init = {"method": method || "GET"}; 8 if (fetchMode) { 9 init.mode = fetchMode; 10 desc += " (" + fetchMode + ")"; 11 } 12 promise_test(function(test) { 13 return fetch(url, init).then(function(resp) { 14 assert_equals(resp.status, 200, "HTTP status is 200"); 15 assert_equals(resp.statusText, "OK", "HTTP statusText is OK"); 16 assert_equals(resp.type, "basic", "response type is basic"); 17 assert_equals(resp.headers.get("Content-Type"), mime, "Content-Type is " + resp.headers.get("Content-Type")); 18 return resp.text(); 19 }).then(function(body) { 20 assert_equals(body, data, "Response's body is correct"); 21 }); 22 }, desc); 23 } 24 25 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII"); 26 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", "same-origin"); 27 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", "cors"); 28 checkFetchResponse("data:text/plain;base64,cmVzcG9uc2UncyBib2R5", "response's body", "text/plain"); 29 checkFetchResponse("data:image/png;base64,cmVzcG9uc2UncyBib2R5", 30 "response's body", 31 "image/png"); 32 checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", null, "POST"); 33 checkFetchResponse("data:,response%27s%20body", "", "text/plain;charset=US-ASCII", null, "HEAD"); 34 35 function checkKoUrl(url, method, desc) { 36 var cut = (url.length >= 40) ? "[...]" : ""; 37 desc = "Fetching [" + method + "] " + url.substring(0, 45) + cut + " is KO" 38 promise_test(function(test) { 39 return promise_rejects_js(test, TypeError, fetch(url, {"method": method})); 40 }, desc); 41 } 42 43 checkKoUrl("data:notAdataUrl.com", "GET");