[Fetch API] SubresourceLoader::checkRedirectionCrossOriginAccessControl should not...
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / fetch / api / basic / mode-same-origin.js
1 if (this.document === undefined) {
2   importScripts("/resources/testharness.js");
3   importScripts("../resources/utils.js");
4   importScripts("../resources/get-host-info.sub.js")
5 }
6
7 function fetchSameOrigin(url, shouldPass) {
8   promise_test(function(test) {
9     if (shouldPass)
10       return fetch(url , {"mode": "same-origin"}).then(function(resp) {
11         assert_equals(resp.status, 200, "HTTP status is 200");
12         assert_equals(resp.type, "basic", "response type is basic");
13       });
14     else
15       return promise_rejects(test, new TypeError, fetch(url, {mode: "same-origin"}));
16   }, "Fetch "+ url + " with same-origin mode");
17 }
18
19 var host_info = get_host_info();
20
21 fetchSameOrigin(RESOURCES_DIR + "top.txt", true);
22 fetchSameOrigin(host_info.HTTP_ORIGIN + "/fetch/api/resources/top.txt", true);
23 fetchSameOrigin(host_info.HTTPS_ORIGIN + "/fetch/api/resources/top.txt", false);
24 fetchSameOrigin(host_info.HTTP_REMOTE_ORIGIN + "/fetch/api/resources/top.txt", false);
25
26 var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py?location=";
27
28 fetchSameOrigin(redirPath + RESOURCES_DIR + "top.txt", true);
29 fetchSameOrigin(redirPath + host_info.HTTP_ORIGIN + "/fetch/api/resources/top.txt", true);
30 fetchSameOrigin(redirPath + host_info.HTTPS_ORIGIN + "/fetch/api/resources/top.txt", false);
31 fetchSameOrigin(redirPath + host_info.HTTP_REMOTE_ORIGIN + "/fetch/api/resources/top.txt", false);
32
33 done();
34