storage_local_key.html
<!DOCTYPE HTML>
<html>
<head>
<title>Web Storage</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>storage_local_key</h1>
<div id="log"></div>
<script>
test(function() {
localStorage.clear();
localStorage.setItem("name", "user1");
localStorage.setItem("age", "20");
localStorage.setItem("a", "1");
localStorage.setItem("b", "2");
var keys = ["name", "age", "a", "b"];
function doTest(index) {
test(function() {
var key = localStorage.key(index);
assert_not_equals(key, null);
assert_true(keys.indexOf(key) >= 0,
"Unexpected key " + key + " found.");
}, "key(" + index + ") should return the right thing.");
}
for (var i = 0; i < keys.length; ++i) {
doTest(i);
doTest(i + 0x100000000);
}
test(function() {
assert_equals(localStorage.key(-1), null, "localStorage.key(-1)");
assert_equals(localStorage.key(4), null, "localStorage.key(4)");
}, "key() should return null for out-of-range arguments.");
});
</script>
</body>
</html>