summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webstorage/storage_enumerate.window.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/webstorage/storage_enumerate.window.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webstorage/storage_enumerate.window.js')
-rw-r--r--testing/web-platform/tests/webstorage/storage_enumerate.window.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webstorage/storage_enumerate.window.js b/testing/web-platform/tests/webstorage/storage_enumerate.window.js
new file mode 100644
index 0000000000..fcc71e1c9e
--- /dev/null
+++ b/testing/web-platform/tests/webstorage/storage_enumerate.window.js
@@ -0,0 +1,55 @@
+["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";
+
+ const enumeratedArray = Object.keys(storage);
+ enumeratedArray.sort(); // Storage order is implementation-defined.
+
+ const expectArray = ["alpha", "bar", "batman", "foo", "fu", "zeta"];
+ assert_array_equals(enumeratedArray, expectArray);
+
+ // 'prototypeTestKey' is not an actual storage key, it is just a
+ // property set on Storage's prototype object.
+ assert_equals(storage.length, 6);
+ assert_equals(storage.getItem("prototypeTestKey"), null);
+ assert_equals(storage.prototypeTestKey, "prototypeTestValue");
+ }, 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");
+});