1 <html> 2 <head> 3 <script src="resources/clearLocalStorage.js"></script> 4 <script> 5 6 if (window.layoutTestController) 7 layoutTestController.dumpAsText(); 8 9 function log(a) 10 { 11 document.getElementById("logger").innerHTML += a + "<br>"; 12 } 13 14 function runTest() 15 { 16 if (!window.localStorage) { 17 log("window.localStorage DOES NOT exist"); 18 return; 19 } 20 21 log("Length is " + localStorage.length); 22 log("Value for FOO is " + localStorage.getItem("FOO")); 23 24 localStorage.setItem("FOO", "BAR"); 25 26 log("Length is " + localStorage.length); 27 log("Value for FOO is " + localStorage.getItem("FOO")); 28 log("Key for index 0 is " + localStorage.key(0)); 29 log("Key for index 1 is " + localStorage.key(1)); 30 log("Key for index -1 is " + localStorage.key(-1)); 31 32 localStorage.setItem("FOO", "BAZ"); 33 34 log("Length is " + localStorage.length); 35 log("Value for FOO is " + localStorage.getItem("FOO")); 36 37 localStorage.removeItem("FOO"); 38 39 log("Length is " + localStorage.length); 40 log("Value for FOO is " + localStorage.getItem("FOO")); 41 } 42 43 </script> 44 </head> 45 <body onload="runTest();"> 46 This test tries simple operations on localStorage<br> 47 <div id="logger"></div> 48 </body> 49 </html> 50