1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/localstorage/test_localStorageFromChrome.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 +<title>localStorage basic test</title> 1.7 + 1.8 +<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.9 +<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.10 + 1.11 +<script type="text/javascript"> 1.12 + 1.13 +function startTest() 1.14 +{ 1.15 + var url = "http://example.com/tests/dom/tests/mochitest/localstorage/frameChromeSlave.html"; 1.16 + var ios = Components.classes["@mozilla.org/network/io-service;1"] 1.17 + .getService(Components.interfaces.nsIIOService); 1.18 + var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] 1.19 + .getService(Components.interfaces.nsIScriptSecurityManager); 1.20 + var dsm = Components.classes["@mozilla.org/dom/localStorage-manager;1"] 1.21 + .getService(Components.interfaces.nsIDOMStorageManager); 1.22 + 1.23 + var uri = ios.newURI(url, "", null); 1.24 + var principal = ssm.getNoAppCodebasePrincipal(uri); 1.25 + var storage = dsm.createStorage(principal, ""); 1.26 + 1.27 + storage.setItem("chromekey", "chromevalue"); 1.28 + 1.29 + var aframe = document.getElementById("aframe"); 1.30 + aframe.onload = function() 1.31 + { 1.32 + is(storage.getItem("chromekey"), "chromevalue"); 1.33 + is(aframe.contentDocument.getElementById("data").innerHTML, "chromevalue"); 1.34 + SimpleTest.finish(); 1.35 + } 1.36 + aframe.src = "http://example.com/tests/dom/tests/mochitest/localstorage/frameChromeSlave.html"; 1.37 + 1.38 + // Additionally check that we do not crash when we access the localStorage 1.39 + // object in the owning chrome window (but we should throw). See bug 485396. 1.40 + var exceptionCaught = false; 1.41 + try { 1.42 + localStorage; 1.43 + } 1.44 + catch (e) { 1.45 + is(e.result, Components.results.NS_ERROR_NOT_AVAILABLE, 1.46 + "Testing that we get the expected exception."); 1.47 + exceptionCaught = true; 1.48 + } 1.49 + is(exceptionCaught, true, "Testing that an exception was thrown."); 1.50 +} 1.51 + 1.52 +SimpleTest.waitForExplicitFinish(); 1.53 + 1.54 +</script> 1.55 + 1.56 +</head> 1.57 + 1.58 +<body onload="startTest();"> 1.59 + <iframe src="" id="aframe"></iframe> 1.60 +</body> 1.61 +</html>