content/base/test/csp/test_dual_headers_warning.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:bea79b6caa1e
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=918397
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 918397</title>
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=918397">Mozilla Bug 918397</a>
14 <p id="display"></p>
15
16 <iframe id="cspframe"></iframe>
17
18 <pre id="test">
19 <script class="testbody" type="text/javascript">
20 // Load locale strings during mochitest
21 var stringBundleService = SpecialPowers.Cc["@mozilla.org/intl/stringbundle;1"]
22 .getService(SpecialPowers.Ci.nsIStringBundleService);
23 var localizer = stringBundleService.createBundle("chrome://global/locale/security/security.properties");
24 var depreHeadersMsg = localizer.GetStringFromName("OldCSPHeaderDeprecated", 0)
25 var dualHeadersMsg = localizer.GetStringFromName("BothCSPHeadersPresent", 0)
26
27 function cleanup() {
28 SpecialPowers.postConsoleSentinel();
29 SimpleTest.finish();
30 }
31
32 // listen on the console before loading the iframe
33 SpecialPowers.registerConsoleListener(function ConsoleMsgListener(aMsg) {
34 // Note: We do not want to see the deprecation warning appear in the console.
35 // This test can only be sure that the deprecation warning does not appear
36 // iff the deprecation warning appears before the dual header warning appears
37 // in the console.
38 if (aMsg.message.indexOf(depreHeadersMsg) > -1) {
39 ok(false, "Deprecated CSP header warning should not be present.");
40 return;
41 } else if (aMsg.message.indexOf(dualHeadersMsg) > -1) {
42 ok(true, "Dual CSP header warning present.");
43 SimpleTest.executeSoon(cleanup);
44 } else {
45 // if some other console message is present, we wait
46 return;
47 }
48 });
49
50 // get ready and test
51 SimpleTest.waitForExplicitFinish();
52 SpecialPowers.pushPrefEnv(
53 {'set': [["security.csp.speccompliant", true]]},
54 function() {
55 document.getElementById('cspframe').src = 'file_dual_headers_warning.html';
56 });
57 </script>
58 </body>
59 </html>

mercurial