summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/test_self_none_as_hostname_confusion.html
blob: 5f6958220ed31ef87eebad882ab2eb11594b8ade (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=587377
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 587377</title>
  <script 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=587377">Mozilla Bug 587377</a>
<p id="display"></p>

<iframe id="cspframe"></iframe>

<pre id="test">

<script class="testbody" type="text/javascript">
// Load locale string during mochitest
var stringBundleService = SpecialPowers.Cc["@mozilla.org/intl/stringbundle;1"]
                          .getService(SpecialPowers.Ci.nsIStringBundleService);
var localizer = stringBundleService.createBundle("chrome://global/locale/security/csp.properties");
var confusionMsg = localizer.formatStringFromName("hostNameMightBeKeyword", ["SELF", "self"]);

function cleanup() {
  SpecialPowers.postConsoleSentinel();
  SimpleTest.finish();
};

// To prevent the test from asserting twice and calling SimpleTest.finish() twice,
// startTest will be marked false as soon as the confusionMsg is detected.
startTest = false;
SpecialPowers.registerConsoleListener(function ConsoleMsgListener(aMsg) {
  if (startTest) {
    if (aMsg.message.indexOf(confusionMsg) > -1) {
      startTest = false;
      ok(true, "CSP header with a hostname similar to keyword should be warned");
      SimpleTest.executeSoon(cleanup);
    }
    // Otherwise, the warning hasn't happened yet so we wait.
  }
});

// set up and start testing
SimpleTest.waitForExplicitFinish();
document.getElementById('cspframe').src = 'file_self_none_as_hostname_confusion.html';
startTest = true;
</script>
</pre>
</body>
</html>