summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/fetch/importscript-mixedcontent/https_test.js
blob: 138ca768aa83e1b74bbd8348b44c5aeb1b21571c (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
29
30
31
function sendResponseToParent(response) {
  return `
    <!DOCTYPE html>
    <script>
      window.parent.postMessage({status: "done", data: "${response}"}, "*");
    </script>
  `;
}

self.addEventListener("fetch", function (event) {
  if (event.request.url.includes("index.html")) {
    var response = "good";
    try {
      importScripts("http://example.org/tests/dom/workers/test/foreign.js");
    } catch (e) {
      dump("Got error " + e + " when importing the script\n");
    }
    if (response === "good") {
      try {
        importScripts("/tests/dom/workers/test/redirect_to_foreign.sjs");
      } catch (e) {
        dump("Got error " + e + " when importing the script\n");
      }
    }
    event.respondWith(
      new Response(sendResponseToParent(response), {
        headers: { "Content-Type": "text/html" },
      })
    );
  }
});