test_self_none_as_hostname_confusion.html (1752B)
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 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> 15 16 <iframe id="cspframe"></iframe> 17 18 <pre id="test"> 19 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"]); 26 27 function cleanup() { 28 SpecialPowers.postConsoleSentinel(); 29 SimpleTest.finish(); 30 }; 31 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 } 42 // Otherwise, the warning hasn't happened yet so we wait. 43 } 44 }); 45 46 // set up and start testing 47 SimpleTest.waitForExplicitFinish(); 48 document.getElementById('cspframe').src = 'file_self_none_as_hostname_confusion.html'; 49 startTest = true; 50 </script> 51 </pre> 52 </body> 53 </html>