summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/nosniff/importscripts.js
blob: 18952805bb71bb4ddb51e8630b531a3bcc75859b (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
// Testing importScripts()
function log(w) { this.postMessage(w) }
function f() { log("FAIL") }
function p() { log("PASS") }

const get_url = (mime, outcome) => {
  let url = "resources/js.py"
  if (mime != null) {
      url += "?type=" + encodeURIComponent(mime)
  }
  if (outcome) {
    url += "&outcome=p"
  }
  return url
}

[null, "", "x", "x/x", "text/html", "text/json"].forEach(function(mime) {
  try {
    importScripts(get_url(mime))
  } catch(e) {
    (e.name == "NetworkError") ? p() : log("FAIL (no NetworkError exception): " + mime)
  }

})
importScripts(get_url("text/javascript", true))
importScripts(get_url("text/ecmascript", true))
importScripts(get_url("text/ecmascript;blah", true))
log("END")