|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <head> |
|
3 <title>localStorage basic test</title> |
|
4 |
|
5 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
|
7 |
|
8 <script type="text/javascript"> |
|
9 |
|
10 function startTest() |
|
11 { |
|
12 var url = "http://example.com/tests/dom/tests/mochitest/localstorage/frameChromeSlave.html"; |
|
13 var ios = Components.classes["@mozilla.org/network/io-service;1"] |
|
14 .getService(Components.interfaces.nsIIOService); |
|
15 var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] |
|
16 .getService(Components.interfaces.nsIScriptSecurityManager); |
|
17 var dsm = Components.classes["@mozilla.org/dom/localStorage-manager;1"] |
|
18 .getService(Components.interfaces.nsIDOMStorageManager); |
|
19 |
|
20 var uri = ios.newURI(url, "", null); |
|
21 var principal = ssm.getNoAppCodebasePrincipal(uri); |
|
22 var storage = dsm.createStorage(principal, ""); |
|
23 |
|
24 storage.setItem("chromekey", "chromevalue"); |
|
25 |
|
26 var aframe = document.getElementById("aframe"); |
|
27 aframe.onload = function() |
|
28 { |
|
29 is(storage.getItem("chromekey"), "chromevalue"); |
|
30 is(aframe.contentDocument.getElementById("data").innerHTML, "chromevalue"); |
|
31 SimpleTest.finish(); |
|
32 } |
|
33 aframe.src = "http://example.com/tests/dom/tests/mochitest/localstorage/frameChromeSlave.html"; |
|
34 |
|
35 // Additionally check that we do not crash when we access the localStorage |
|
36 // object in the owning chrome window (but we should throw). See bug 485396. |
|
37 var exceptionCaught = false; |
|
38 try { |
|
39 localStorage; |
|
40 } |
|
41 catch (e) { |
|
42 is(e.result, Components.results.NS_ERROR_NOT_AVAILABLE, |
|
43 "Testing that we get the expected exception."); |
|
44 exceptionCaught = true; |
|
45 } |
|
46 is(exceptionCaught, true, "Testing that an exception was thrown."); |
|
47 } |
|
48 |
|
49 SimpleTest.waitForExplicitFinish(); |
|
50 |
|
51 </script> |
|
52 |
|
53 </head> |
|
54 |
|
55 <body onload="startTest();"> |
|
56 <iframe src="" id="aframe"></iframe> |
|
57 </body> |
|
58 </html> |