1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body{
font-family: Helvetica, Sans-serif;
font-size: 13px;
}
.red{
background: red;
color: white;
}
.green{
background: green;
color: white;
}
.yellow{
background: yellow url(ajax-loader.gif) no-repeat 3px center;
}
.black{
background: black;
color: white;
}
ul{
padding:0;
list-style: none;
margin: 10 0;
}
li{
padding: 5px 25px;
margin: 0 0 1px 0;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
<script src="../jstorage.js"></script>
<script>
var tests = [
{
id: "test1",
name: "localStorage polyfill getter/setter"
},
{
id: "test2",
name: "localStorage polyfill setItem/getItem"
},
{
id: "test3",
name: "localStorage polyfill removeItem"
},
{
id: "test4",
name: "localStorage polyfill length"
},
{
id: "test5",
name: "localStorage polyfill key(n)"
},
{
id: "test6",
name: "localStorage polyfill clear"
},
{
id: "test7",
name: "sessionStorage polyfill getter/setter"
},
{
id: "test8",
name: "sessionStorage polyfill setItem/getItem"
},
{
id: "test9",
name: "sessionStorage polyfill removeItem"
},
{
id: "test10",
name: "sessionStorage polyfill length"
},
{
id: "test11",
name: "sessionStorage polyfill key(n)"
},
{
id: "test12",
name: "sessionStorage polyfill clear"
},
{
id: "test13",
name: "jStorage set/get JSON types"
},
{
id: "test14",
name: "jStorage set/get XML"
},
{
id: "test15",
name: "jStorage set with TTL option"
},
{
id: "test16",
name: "jStorage setTTL"
},
{
id: "test17",
name: "jStorage delete key"
},
{
id: "test18",
name: "jStorage flush/index"
},
{
id: "test19",
name: "jStorage listenKeyChange"
},
{
id: "test20",
name: "jStorage publish/subscribe"
}
],
test,
succeeded = 0,
failed = 0;
function runTests(){
$.jStorage.flush();
localStorage.clear();
sessionStorage.clear();
if(!tests.length){
alert("All tests ready, "+succeeded + " succeeded, "+failed+ " failed");
return;
}
test = tests.shift();
if(!test){
return runTests();
}
test.li = document.createElement("li");
test.li.innerHTML = test.name+ " running";
test.li.className = "yellow";
document.getElementById("results").appendChild(test.li);
createIframe(test.id+"_setup.html");
test.timeout = setTimeout(testFail, 4000);
};
function createIframe(url){
test.iframe = document.createElement("iframe");
test.iframe.style.position = "absolute";
test.iframe.style.left = "-1000px";
test.iframe.style.top = "-1000px";
test.iframe.src = url;
document.body.appendChild(test.iframe);
}
function testFail(){
clearTimeout(test.timeout);
if(test && test.iframe){
test.iframe.parentNode.removeChild(test.iframe);
test.li.className = "black";
test.li.innerHTML = test.name+" timeout";
}
failed++;
runTests();
}
function setupReady(){
clearTimeout(test.timeout);
test.timeout = setTimeout(testFail, 4000);
test.iframe.parentNode.removeChild(test.iframe);
createIframe(test.id+"_run.html");
}
function testReady(success){
clearTimeout(test.timeout);
test.iframe.parentNode.removeChild(test.iframe);
test.li.className = success ? "green" : "red";
if(success){
test.li.innerHTML = test.name+" succeeded";
succeeded++;
}else{
test.li.innerHTML = test.name+" failed";
failed++;
}
runTests();
}
</script>
</head>
<body>
<h1>jStorage tests</h1>
<ul id="results"></ul>
<script>runTests();</script>
</body>
</html>
|