mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-28 13:40:17 -10:00
69 lines
2.2 KiB
HTML
69 lines
2.2 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>WebStorage Test: Storage - enumerate and built-in properties</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="log"></div>
|
|
<script>
|
|
["localStorage", "sessionStorage"].forEach(function(name) {
|
|
test(function() {
|
|
assert_true(name in window, name + " exist");
|
|
|
|
var storage = window[name];
|
|
storage.clear();
|
|
|
|
Storage.prototype.prototypeTestKey = "prototypeTestValue";
|
|
storage.foo = "bar";
|
|
storage.fu = "baz";
|
|
storage.batman = "bin suparman";
|
|
storage.bar = "foo";
|
|
storage.alpha = "beta";
|
|
storage.zeta = "gamma";
|
|
|
|
var enumeratedArray = new Array();
|
|
for (var n in storage)
|
|
enumeratedArray.push(n);
|
|
|
|
// Sort the array, since the storage order isn't guaranteed
|
|
enumeratedArray.sort();
|
|
|
|
var expectArray = ["alpha", "bar", "batman", "foo", "fu", "prototypeTestKey", "zeta"];
|
|
assert_array_equals(enumeratedArray, expectArray);
|
|
|
|
}, name + ": enumerate a Storage object and get only the keys as a result and the built-in properties of the Storage object should be ignored");
|
|
|
|
test(function() {
|
|
const storage = window[name];
|
|
storage.clear();
|
|
|
|
storage.setItem("foo", "bar");
|
|
storage.baz = "quux";
|
|
storage.setItem(0, "alpha");
|
|
storage[42] = "beta";
|
|
|
|
for (let prop in storage) {
|
|
if (!storage.hasOwnProperty(prop))
|
|
continue;
|
|
const desc = Object.getOwnPropertyDescriptor(storage, prop);
|
|
assert_true(desc.configurable);
|
|
assert_true(desc.enumerable);
|
|
assert_true(desc.writable);
|
|
}
|
|
|
|
const keys = Object.keys(storage);
|
|
keys.sort(); // Storage order is implementation-defined.
|
|
assert_array_equals(keys, ["0", "42", "baz", "foo"]);
|
|
|
|
const values = Object.values(storage);
|
|
values.sort(); // Storage order is implementation-defined.
|
|
assert_array_equals(values, ["alpha", "bar", "beta", "quux"]);
|
|
}, name + ": test enumeration of numeric and non-numeric keys");
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|