summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/test/xpcshell/test_WeakMapMap.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/client/shared/test/xpcshell/test_WeakMapMap.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/shared/test/xpcshell/test_WeakMapMap.js')
-rw-r--r--devtools/client/shared/test/xpcshell/test_WeakMapMap.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/devtools/client/shared/test/xpcshell/test_WeakMapMap.js b/devtools/client/shared/test/xpcshell/test_WeakMapMap.js
new file mode 100644
index 0000000000..f1103ab8f6
--- /dev/null
+++ b/devtools/client/shared/test/xpcshell/test_WeakMapMap.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test WeakMapMap.
+
+"use strict";
+
+const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
+const WeakMapMap = require("devtools/client/shared/WeakMapMap");
+
+const myWeakMapMap = new WeakMapMap();
+const key = { randomObject: true };
+
+// eslint-disable-next-line
+function run_test() {
+ test_set();
+ test_has();
+ test_get();
+ test_delete();
+ test_clear();
+}
+
+function test_set() {
+ // myWeakMapMap.set
+ myWeakMapMap.set(key, "text1", "value1");
+ myWeakMapMap.set(key, "text2", "value2");
+ myWeakMapMap.set(key, "text3", "value3");
+}
+
+function test_has() {
+ // myWeakMapMap.has
+ ok(myWeakMapMap.has(key, "text1"), "text1 exists");
+ ok(myWeakMapMap.has(key, "text2"), "text2 exists");
+ ok(myWeakMapMap.has(key, "text3"), "text3 exists");
+ ok(!myWeakMapMap.has(key, "notakey"), "notakey does not exist");
+}
+
+function test_get() {
+ // myWeakMapMap.get
+ const value1 = myWeakMapMap.get(key, "text1");
+ equal(value1, "value1", "test value1");
+
+ const value2 = myWeakMapMap.get(key, "text2");
+ equal(value2, "value2", "test value2");
+
+ const value3 = myWeakMapMap.get(key, "text3");
+ equal(value3, "value3", "test value3");
+
+ const value4 = myWeakMapMap.get(key, "notakey");
+ equal(value4, undefined, "test value4");
+}
+
+function test_delete() {
+ // myWeakMapMap.delete
+ myWeakMapMap.delete(key, "text2");
+
+ // Check that the correct entry was deleted
+ ok(myWeakMapMap.has(key, "text1"), "text1 exists");
+ ok(!myWeakMapMap.has(key, "text2"), "text2 no longer exists");
+ ok(myWeakMapMap.has(key, "text3"), "text3 exists");
+}
+
+function test_clear() {
+ // myWeakMapMap.clear
+ myWeakMapMap.clear();
+
+ // Ensure myWeakMapMap was properly cleared
+ ok(!myWeakMapMap.has(key, "text1"), "text1 no longer exists");
+ ok(!myWeakMapMap.has(key, "text3"), "text3 no longer exists");
+}