summaryrefslogtreecommitdiffstats
path: root/dom/security/test/sri/test_csp_directive_style_imports.html
blob: f293e24121e370cd64e282b7284b8ed4b44fa83e (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
<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for SRI require-sri-for CSP directive</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1265318">Mozilla Bug 1265318</a><br>
<iframe style="width:200px;height:200px;" id="test_frame"></iframe><br>
</body>
<script type="application/javascript">
  var finished = 0;
  SpecialPowers.setBoolPref("security.csp.experimentalEnabled", true);
  SimpleTest.waitForExplicitFinish();
  function handler(event) {
    console.log(event);
    switch (event.data) {
      case 'finish':
        // need finish message from iframe_require-sri-for_main onload event and
        // from iframe_require-sri-for_no_csp, which spawns a Worker
        var importText = frame.contentDocument.getElementById('text-for-import-test');
        var importColor = frame.contentWindow.getComputedStyle(importText, null).getPropertyValue('color');
        ok(importColor == 'rgb(0, 0, 255)', "The import should not work without integrity. The text is now red, but should not.");
        removeEventListener('message', handler);
        SimpleTest.finish();
        break;
      default:
        ok(false, 'Something is wrong here');
        break;
    }
  }
  addEventListener("message", handler);
  // This frame has a CSP that requires SRI
  var frame = document.getElementById("test_frame");
  frame.src = "iframe_csp_directive_style_imports.html";
</script>
</html>