Created
December 13, 2013 18:03
-
-
Save yeukhon/7948456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> | |
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> | |
<script class="testbody" type="text/javascript"> | |
/* | |
const Cc = Components.classes; | |
const Ci = Components.interfaces; | |
const Cu = Components.utils; | |
const Cr = Components.results; | |
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | |
Cu.import("resource://gre/modules/Services.jsm"); | |
var localizer = Cu.import("resource://gre/modules/CSPUtils.jsm", {}).CSPLocalizer | |
XPCOMUtils.defineLazyGetter(localizer, "stringBundle", function() { | |
return Services.strings.createBundle("chrome://global/locale/security/security.properties"); | |
}); | |
var depreHeadersMsg = localizer.getFormatStr("OldCSPHeaderDeprecated", []); | |
var dualHeadersMsg = localizer.getFormatStr("BothCSPHeadersPresent", []); | |
*/ | |
var stringBundleService = SpecialPowers.Cc["@mozilla.org/intl/stringbundle;1"].getService(SpecialPowers.Ci.nsIStringBundleService); | |
var g_bundl = stringBundleService.createBundle("chrome://global/locale/security/security.properties"); | |
var depreHeadersMsg = g_bundl.formatStringFromName("OldCSPHeaderDeprecated", [], 0) | |
var dualHeadersMsg = g_bundl.formatStringFromName("BothCSPHeadersPresent", [], 0) | |
//g_bundl.getFormatStr("OldCSPHeaderDeprecated", []); | |
console.log(depreHeadersMsg); | |
//var depreHeaderMsg = "The X-Content-Security-Policy and X-Content-Security-Report-Only headers will be deprecated in the future." | |
//var dualHeaderMsg = "This site specified both an X-Content-Security-Policy/Report-Only header and a Content-Security-Policy/Report-Only header. The X-Content-Security-Policy/Report-Only header(s) will be ignored." | |
var cspframe = document.getElementById('cspframe'); | |
cspframe.src = "file_dual_headers_warning.html"; | |
SimpleTest.waitForExplicitFinish(); | |
function cleanup() { | |
SpecialPowers.postConsoleSentinel(); | |
SimpleTest.finish(); | |
} | |
SpecialPowers.registerConsoleListener(function ConsoleMsgListener(aMsg) { | |
// NOTE: this test is not perfect because the test assumes the ordering | |
// of the console message output: the deprecated warning comes before | |
// the dual header warning. This test will fail if the order was changed. | |
// We would love to use SimpleTest.runTestExpectingConsoleMessages | |
// to assert the number of expected console messages, but we are not able | |
// to make the function working with our test. | |
if (!aMsg.message) { | |
// if no message yet we wait | |
return; | |
} else if (aMsg.message.indexOf(depreHeadersMsg) > -1) { | |
ok(false, "Deprecated CSP header warning should not be present."); | |
return; | |
} else if (aMsg.message.indexOf(dualHeadersMsg) > -1) { | |
console.log("found dual"); | |
console.log(aMsg); | |
ok(true, "Dual CSP header warning present."); | |
SimpleTest.executeSoon(cleanup); | |
} else { | |
// if some other console message is present, we wait | |
console.log(aMsg.message); | |
return; | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment