gecko-dev/testing/web-platform/tests/webstorage/length.html

32 строки
907 B
HTML

<!DOCTYPE HTML>
<mete charset=utf-8>
<title>Length</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
["localStorage", "sessionStorage"].forEach(function(name) {
test(function() {
var storage = window[name];
storage.clear();
assert_equals(storage.length, 0, "storage.length")
storage["name"] = "user1";
storage["age"] = "20";
assert_equals(storage.length, 2, "storage.length")
}, name + ".length (method access)");
test(function() {
var storage = window[name];
storage.clear();
assert_equals(storage.length, 0, "storage.length")
storage.setItem("name", "user1");
storage.setItem("age", "20");
assert_equals(storage.length, 2, "storage.length")
}, name + ".length (proprty access)");
});
</script>