summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/basic/mode-same-origin.any.js
blob: 1457702f1b163b9ceaa9058e9f6f1db102ffcfc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// META: script=../resources/utils.js
// META: script=/common/get-host-info.sub.js

function fetchSameOrigin(url, shouldPass) {
  promise_test(function(test) {
    if (shouldPass)
      return fetch(url , {"mode": "same-origin"}).then(function(resp) {
        assert_equals(resp.status, 200, "HTTP status is 200");
        assert_equals(resp.type, "basic", "response type is basic");
      });
    else
      return promise_rejects_js(test, TypeError, fetch(url, {mode: "same-origin"}));
  }, "Fetch "+ url + " with same-origin mode");
}

var host_info = get_host_info();

fetchSameOrigin(RESOURCES_DIR + "top.txt", true);
fetchSameOrigin(host_info.HTTP_ORIGIN + "/fetch/api/resources/top.txt", true);
fetchSameOrigin(host_info.HTTPS_ORIGIN + "/fetch/api/resources/top.txt", false);
fetchSameOrigin(host_info.HTTP_REMOTE_ORIGIN + "/fetch/api/resources/top.txt", false);

var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py?location=";

fetchSameOrigin(redirPath + RESOURCES_DIR + "top.txt", true);
fetchSameOrigin(redirPath + host_info.HTTP_ORIGIN + "/fetch/api/resources/top.txt", true);
fetchSameOrigin(redirPath + host_info.HTTPS_ORIGIN + "/fetch/api/resources/top.txt", false);
fetchSameOrigin(redirPath + host_info.HTTP_REMOTE_ORIGIN + "/fetch/api/resources/top.txt", false);