content/base/test/csp/test_dual_headers_warning.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/csp/test_dual_headers_warning.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=918397
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 918397</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=918397">Mozilla Bug 918397</a>
    1.17 +<p id="display"></p>
    1.18 +
    1.19 +<iframe id="cspframe"></iframe>
    1.20 +
    1.21 +<pre id="test">
    1.22 +<script class="testbody" type="text/javascript">
    1.23 +// Load locale strings during mochitest
    1.24 +var stringBundleService = SpecialPowers.Cc["@mozilla.org/intl/stringbundle;1"]
    1.25 +                          .getService(SpecialPowers.Ci.nsIStringBundleService);
    1.26 +var localizer = stringBundleService.createBundle("chrome://global/locale/security/security.properties");
    1.27 +var depreHeadersMsg = localizer.GetStringFromName("OldCSPHeaderDeprecated", 0)
    1.28 +var dualHeadersMsg = localizer.GetStringFromName("BothCSPHeadersPresent", 0)
    1.29 +
    1.30 +function cleanup() {
    1.31 +  SpecialPowers.postConsoleSentinel();
    1.32 +  SimpleTest.finish();
    1.33 +}
    1.34 +
    1.35 +// listen on the console before loading the iframe
    1.36 +SpecialPowers.registerConsoleListener(function ConsoleMsgListener(aMsg) {
    1.37 +  // Note: We do not want to see the deprecation warning appear in the console.
    1.38 +  // This test can only be sure that the deprecation warning does not appear
    1.39 +  // iff the deprecation warning appears before the dual header warning appears
    1.40 +  // in the console.
    1.41 +  if (aMsg.message.indexOf(depreHeadersMsg) > -1) {
    1.42 +    ok(false, "Deprecated CSP header warning should not be present.");
    1.43 +    return;
    1.44 +  } else if (aMsg.message.indexOf(dualHeadersMsg) > -1) {
    1.45 +    ok(true, "Dual CSP header warning present.");
    1.46 +    SimpleTest.executeSoon(cleanup);
    1.47 +  } else {
    1.48 +    // if some other console message is present, we wait
    1.49 +    return;
    1.50 +  }
    1.51 +});
    1.52 +
    1.53 +// get ready and test
    1.54 +SimpleTest.waitForExplicitFinish();
    1.55 +SpecialPowers.pushPrefEnv(
    1.56 +  {'set': [["security.csp.speccompliant", true]]},
    1.57 +  function() {
    1.58 +    document.getElementById('cspframe').src = 'file_dual_headers_warning.html';
    1.59 +});
    1.60 +</script>
    1.61 +</body>
    1.62 +</html>

mercurial