gecko/dom/tests/mochitest/bugs/iframe_bug463000.html

153 lines
3.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Child window for the private browsing test</title>
<script type="application/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
var _PBSvc = null;
function get_PBSvc() {
if (_PBSvc)
return _PBSvc;
try {
_PBSvc = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
return _PBSvc;
} catch (e) {}
return null;
}
function run()
{
var storage;
var message = "child-response";
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
prefBranch.setBoolPref("browser.privatebrowsing.keep_current_session", true);
var pb = get_PBSvc();
// The private browsing service might not be available
if (pb) {
try {
storage = globalStorage["example.org"];
}
catch (ex) {
message += "\n failed globalStorage[\"example.org\"]";
}
// save Pair-A
try {
storage.key1 = "value-1";
}
catch (ex) {
message += "\n failed to store Pair-A";
}
// ensure that Pair-A exists
try {
if (storage.key1 != "value-1")
throw "error";
}
catch (ex) {
if (ex == "error")
message += "\n Pair-A was not saved correctly";
else
message += "\n Unexpected exception encountered while checking Pair-A: " + ex;
}
// enter the private browsing mode
try {
pb.privateBrowsingEnabled = true;
}
catch (ex) {
message += "\n failed to enter the private browsing mode";
}
// ensure that Pair-A does not exist
try {
// because of bug 426436, |typeof storage.key1 != "undefined"| wouldn't work here
if (storage.key1 != "")
throw "error";
}
catch (ex) {
if (ex == "error")
message += "\n Pair-A existed unexpectedly";
else
message += "\n Unexpected exception encountered while checking Pair-A (2): " + ex;
}
// attempt to save Pair-B
try {
storage.key2 = "value-2";
}
catch (ex) {
message += "\n failed to store Pair-B";
}
// ensure that Pair-B exists
try {
if (storage.key2 != "value-2")
throw "error";
}
catch (ex) {
if (ex == "error")
message += "\n Pair-B was not retrieved correctly";
else
message += "\n Unexpected exception encountered while checking Pair-B: " + ex;
}
// exit the private browsing mode
try {
pb.privateBrowsingEnabled = false;
}
catch (ex) {
message += "\n failed to exit the private browsing mode";
}
// ensure that Pair-A exists
try {
if (storage.key1 != "value-1")
throw "error";
}
catch (ex) {
if (ex == "error")
message += "\n Pair-A was not retrieved correctly";
else
message += "\n Unexpected exception encountered while checking Pair-A (3): " + ex;
}
// ensure that Pair-B does not exist
try {
// because of bug 426436, |typeof storage.key2 != "undefined"| wouldn't work here
if (storage.key2 != "")
throw "error";
}
catch (ex) {
if (ex == "error")
message += "\n Pair-B existed unexpectedly";
else
message += "\n Unexpected exception encountered while checking Pair-B (2): " + ex;
}
}
prefBranch.clearUserPref("browser.privatebrowsing.keep_current_session");
window.parent.postMessage(message, "http://localhost:8888");
}
window.addEventListener("load", run, false);
</script>
</head>
<body>
</body>
</html>