summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/content-security-policy/reporting/report-only-cross-origin-frame.sub.html
blob: 3e47e810e9aaec01172de060c9f9c9c050c331c6 (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
<!DOCTYPE html>
<html>
<head>
  <title>Cross origin iframes have their URI censored</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <!-- CSP headers
Content-Security-Policy: script-src 'self' 'unsafe-inline'
Content-Security-Policy-Report-Only: frame-src 'none'; script-src 'self' 'unsafe-inline'; report-uri /reporting/resources/report.py?op=put&reportID=$id
-->
</head>
<body>
  <script>
    let iframe = document.createElement('iframe');
    iframe.src = "http://{{domains[www1]}}:{{ports[http][0]}}" +
                 "/content-security-policy/support/postmessage-pass.html";

    let test_load_event = async_test("The load event triggers");
    iframe.onload = test_load_event.step_func_done();

    let test_iframe_allowed = async_test("The iframe is allowed to load.");
    window.addEventListener("message", test_iframe_allowed.step_func(event => {
      if (event.source === iframe.contentWindow) {
        assert_equals(event.data, "PASS");
        test_iframe_allowed.done();
      }
    }));

    let test_spv = async_test("The securitypolicyviolation is triggered.");
    window.addEventListener("securitypolicyviolation",
                            test_spv.step_func_done(e => {
      assert_equals(e.blockedURI,
                    "http://{{domains[www1]}}:{{ports[http][0]}}");
    }));

    document.body.appendChild(iframe);
  </script>

  <!-- Ensure that we get the censored URI (without the full path) here: -->
  <script async defer src='../support/checkReport.sub.js?reportField=blocked-uri&reportValue=http://{{domains[www1]}}:{{ports[http][0]}}'></script>
</body>
</html>