summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/nosniff/importscripts.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/fetch/nosniff/importscripts.js')
-rw-r--r--testing/web-platform/tests/fetch/nosniff/importscripts.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/nosniff/importscripts.js b/testing/web-platform/tests/fetch/nosniff/importscripts.js
new file mode 100644
index 0000000000..18952805bb
--- /dev/null
+++ b/testing/web-platform/tests/fetch/nosniff/importscripts.js
@@ -0,0 +1,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")