content/base/test/csp/test_self_none_as_hostname_confusion.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=587377
     5 -->
     6 <head>
     7   <meta charset="utf-8">
     8   <title>Test for Bug 587377</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=587377">Mozilla Bug 587377</a>
    14 <p id="display"></p>
    16 <iframe id="cspframe"></iframe>
    18 <pre id="test">
    20 <script class="testbody" type="text/javascript">
    21 // Load locale string during mochitest
    22 var stringBundleService = SpecialPowers.Cc["@mozilla.org/intl/stringbundle;1"]
    23                           .getService(SpecialPowers.Ci.nsIStringBundleService);
    24 var localizer = stringBundleService.createBundle("chrome://global/locale/security/csp.properties");
    25 var confusionMsg = localizer.formatStringFromName("hostNameMightBeKeyword", ["SELF", "self"], 2);
    27 function cleanup() {
    28   SpecialPowers.postConsoleSentinel();
    29   SimpleTest.finish();
    30 };
    32 // To prevent the test from asserting twice and calling SimpleTest.finish() twice,
    33 // startTest will be marked false as soon as the confusionMsg is detected.
    34 startTest = false;
    35 SpecialPowers.registerConsoleListener(function ConsoleMsgListener(aMsg) {
    36   if (startTest) {
    37     if (aMsg.message.indexOf(confusionMsg) > -1) {
    38       startTest = false;
    39       ok(true, "CSP header with a hostname similar to keyword should be warned");
    40       SimpleTest.executeSoon(cleanup);
    41     } else {
    42       // don't see the warning yet? wait.
    43       return;
    44     }
    45   }
    46 });
    48 // set up and start testing
    49 SimpleTest.waitForExplicitFinish();
    50 SpecialPowers.pushPrefEnv(
    51   {'set': [["security.csp.speccompliant", true]]},
    52   function() {
    53     document.getElementById('cspframe').src = 'file_self_none_as_hostname_confusion.html';
    54     startTest = true;
    55 });
    56 </script>
    57 </pre>
    58 </body>
    59 </html>

mercurial