summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/xslt_worker.js
blob: d7e6eea12946ff2e86d1b0560d2c5a4ab6cbf976 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var testType = "synthetic";

var xslt =
  '<?xml version="1.0"?> ' +
  '<xsl:stylesheet version="1.0"' +
  '   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
  '  <xsl:template match="node()|@*">' +
  "    <xsl:copy>" +
  '      <xsl:apply-templates select="node()|@*"/>' +
  "    </xsl:copy>" +
  "  </xsl:template>" +
  '  <xsl:template match="Error"/>' +
  "</xsl:stylesheet>";

onfetch = function (event) {
  if (event.request.url.includes("test.xsl")) {
    if (testType == "synthetic") {
      if (event.request.mode != "cors") {
        event.respondWith(Response.error());
        return;
      }

      event.respondWith(
        Promise.resolve(
          new Response(xslt, {
            headers: { "Content-Type": "application/xslt+xml" },
          })
        )
      );
    } else if (testType == "cors") {
      if (event.request.mode != "cors") {
        event.respondWith(Response.error());
        return;
      }

      var url =
        "http://example.com/tests/dom/serviceworkers/test/xslt/xslt.sjs?" +
        escape(xslt);
      event.respondWith(fetch(url, { mode: "cors" }));
    } else if (testType == "opaque") {
      if (event.request.mode != "cors") {
        event.respondWith(Response.error());
        return;
      }

      var url =
        "http://example.com/tests/dom/serviceworkers/test/xslt/xslt.sjs?" +
        escape(xslt);
      event.respondWith(fetch(url, { mode: "no-cors" }));
    } else {
      event.respondWith(Response.error());
    }
  }
};

onmessage = function (event) {
  testType = event.data;
};