summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/file_reloadInFreshProcess.sjs
blob: 97e0bcc582e5ff75f65314405b34ec68fc165a7f (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"use strict";

const TESTFRAME_QUERY_LARGE_ALLOCATION_WITH_NO_CSP =
 `<!DOCTYPE HTML>
  <html>
  <head>
    <title>Bug 1555050 - Test CSP Navigation using ReloadInFreshProcess</title>
  </head>
  <body>
    testframe<br/>
    <script>
      // we have to use noopener otherwise the window is not the only window in the tabgroup which is needed
      // for "Large-Allocation" to succeed
      window.open("http://test1.example.com/tests/dom/security/test/csp/file_reloadInFreshProcess.sjs?largeAllocation_with_no_csp", "_blank", "noopener");
    </script>
  </body>
  </html>`;

const TESTFRAME_QUERY_LARGE_ALLOCATION_WITH_CSP =
 `<!DOCTYPE HTML>
  <html>
  <head>
    <title>Bug 1555050 - Test CSP Navigation using ReloadInFreshProcess</title>
  </head>
  <body>
    testframe<br/>
    <script>
      // we have to use noopener otherwise the window is not the only window in the tabgroup which is needed
      // for "Large-Allocation" to succeed
      window.open("http://test2.example.com/tests/dom/security/test/csp/file_reloadInFreshProcess.sjs?largeAllocation_with_csp", "_blank", "noopener");
    </script>
  </body>
  </html>`;

const LARGE_ALLOCATION = 
 `<!DOCTYPE HTML>
  <html>
  <head>
    <title>Bug 1555050 - Test CSP Navigation using ReloadInFreshProcess</title>
  </head>
  <body>
    largeAllocation<br/>
    <script>
      window.close();
    </script>
  </body>
  </html>`;

function handleRequest(request, response)
{
  // avoid confusing cache behaviors
  response.setHeader("Cache-Control", "no-cache", false);
 
  var queryString = request.queryString;

  if (queryString == "testframe_with_csp") {
    response.setHeader("Content-Security-Policy", "upgrade-insecure-requests", false);     
    response.write(TESTFRAME_QUERY_LARGE_ALLOCATION_WITH_NO_CSP);
    return;
  }

  if (queryString == "testframe_with_no_csp") {
    response.write(TESTFRAME_QUERY_LARGE_ALLOCATION_WITH_CSP);
    return;
  }

  if (queryString == "largeAllocation_with_csp") {
    response.setHeader("Content-Security-Policy", "upgrade-insecure-requests", false);   
    response.setHeader("Large-Allocation", "0", false);
    response.write(LARGE_ALLOCATION);
    return;
  }

  if (queryString == "largeAllocation_with_no_csp") {
    response.setHeader("Large-Allocation", "0", false);
    response.write(LARGE_ALLOCATION);
    return;
  }

  // we should never get here, but just in case return something unexpected
  response.write("do'h");
}