|
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> |
|
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"], 2); |
|
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 } else { |
|
42 // don't see the warning yet? wait. |
|
43 return; |
|
44 } |
|
45 } |
|
46 }); |
|
47 |
|
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> |