summaryrefslogtreecommitdiffstats
path: root/netwerk/test/mochitests/web_packaged_app.sjs
blob: 506f7e08d19f5d991a6634583443c32e4f7c5211 (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
function handleRequest(request, response) {
  response.setHeader("Content-Type", "application/package", false);
  response.write(octetStreamData.getData());
}

// The package content
// getData formats it as described at http://www.w3.org/TR/web-packaging/#streamable-package-format
var octetStreamData = {
  content: [
    {
      headers: ["Content-Location: /index.html", "Content-Type: text/html"],
      data:
        "<html>\r\n  <head>\r\n    <script> alert('OK: hello'); alert('DONE'); </script>\r\n</head>\r\n  Web Packaged App Index\r\n</html>\r\n",
      type: "text/html",
    },
    {
      headers: [
        "Content-Location: /scripts/app.js",
        "Content-Type: text/javascript",
      ],
      data: "module Math from '/scripts/helpers/math.js';\r\n...\r\n",
      type: "text/javascript",
    },
    {
      headers: [
        "Content-Location: /scripts/helpers/math.js",
        "Content-Type: text/javascript",
      ],
      data: "export function sum(nums) { ... }\r\n...\r\n",
      type: "text/javascript",
    },
  ],
  token: "gc0pJq0M:08jU534c0p",
  getData() {
    var str = "";
    for (var i in this.content) {
      str += "--" + this.token + "\r\n";
      for (var j in this.content[i].headers) {
        str += this.content[i].headers[j] + "\r\n";
      }
      str += "\r\n";
      str += this.content[i].data + "\r\n";
    }

    str += "--" + this.token + "--";
    return str;
  },
};