File: 304-response-should-update-csp.sub.html

package info (click to toggle)
firefox-esr 115.15.0esr-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,659,216 kB
  • sloc: cpp: 6,676,686; javascript: 5,690,965; ansic: 3,328,546; python: 1,120,594; asm: 397,163; xml: 180,531; java: 178,838; sh: 68,930; makefile: 20,999; perl: 12,595; objc: 12,561; yacc: 4,583; cs: 3,846; pascal: 2,840; lex: 1,720; ruby: 1,079; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (52 lines) | stat: -rw-r--r-- 1,916 bytes parent folder | download | duplicates (14)
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
<!DOCTYPE HTML>
<html>
<head>
    <script src='/resources/testharness.js'></script>
    <script src='/resources/testharnessreport.js'></script>
    <title>Test that a 304 response will update the CSP header</title>
</head>
<body>
  <script>
    var t1 = async_test("Test that the first frame uses nonce abc");
    var t2 = async_test("Test that the first frame does not use nonce def");

    var t3 = async_test("Test that the second frame uses nonce def");
    var t4 = async_test("Test that the second frame does not use nonce abc");

    var i1 = document.createElement('iframe');
    // We add a random parameter to avoid previous tests cached requests.
    // We want to make sure i1 gets a 200 code and i2 gets a 304 code.
    i1.src = "support/304-response.py?{{$id:uuid()}}";

    var i2 = document.createElement('iframe');
    i2.src = "support/304-response.py?{{$id}}";

    var load_second_frame = function() {
      document.body.appendChild(i2);
    }

    window.onmessage = function(e) {
      if (e.source == i1.contentWindow) {
        if (e.data == "abc_executed") { t1.done(); return; }
        if (e.data == "script-src 'nonce-abc' 'sha256-IIB78ZS1RMMrAWpsLg/RrDbVPhI14rKm3sFOeKPYulw=';") { t2.done(); return; }

        t1.step(function() { assert_unreached("Unexpected message received"); });
        t2.step(function() { assert_unreached("Unexpected message received"); });
      }

      if (e.source == i2.contentWindow) {
        if (e.data == "def_executed") { t3.done(); return; }
        if (e.data == "script-src 'nonce-def' 'sha256-IIB78ZS1RMMrAWpsLg/RrDbVPhI14rKm3sFOeKPYulw=';") { t4.done(); return; }

        t3.step(function() { assert_unreached("Unexpected message received"); });
        t4.step(function() { assert_unreached("Unexpected message received"); });
      }

    };

    i1.onload = load_second_frame;
    document.body.appendChild(i1);
  </script>
</body>

</html>