summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html')
-rw-r--r--testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html61
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html b/testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html
new file mode 100644
index 0000000000..3b38bd8f16
--- /dev/null
+++ b/testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.html
@@ -0,0 +1,61 @@
+<!doctype html>
+<title>HighlightRegistry is a maplike interface that works as expected even if Map.prototype is tampered</title>
+<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<body>
+<script>
+"use strict";
+
+function tamperMapPrototype() {
+ delete Map.prototype.size;
+
+ Map.prototype.entries = null;
+ Map.prototype.forEach = undefined;
+ Map.prototype.get = "foo";
+ Map.prototype.has = 0;
+ Map.prototype.keys = Symbol();
+ Map.prototype.values = 1;
+ Map.prototype[Symbol.iterator] = true;
+ Map.prototype.clear = false;
+ Map.prototype.delete = "";
+ Map.prototype.set = 3.14;
+
+ Object.freeze(Map.prototype);
+}
+
+test(() => {
+ tamperMapPrototype();
+
+ const highlight = new Highlight(new StaticRange({startContainer: document.body, endContainer: document.body, startOffset: 0, endOffset: 0}));
+ const highlightRegister = new HighlightRegister();
+
+ assert_equals(highlightRegister.size, 0);
+ highlightRegister.set("foo", highlight);
+ assert_equals(highlightRegister.size, 1);
+
+ assert_true(highlightRegister.has("foo"));
+ assert_equals([...highlightRegister.entries()][0][0], "foo");
+
+ highlightRegister.clear();
+ assert_equals(highlightRegister.size, 0);
+ assert_equals(highlightRegister.get("foo"), undefined);
+
+ highlightRegister.set("bar", highlight);
+ assert_equals(highlightRegister.get("bar"), highlight);
+ assert_equals([...highlightRegister][0][1], highlight);
+
+ highlightRegister.delete("bar");
+ assert_equals(highlightRegister.size, 0);
+ assert_false(highlightRegister.has("bar"));
+
+ highlightRegister.set("baz", highlight);
+ assert_equals([...highlightRegister.keys()][0], "baz");
+ assert_equals([...highlightRegister.values()][0], highlight);
+
+ let callbackCalled = false;
+ highlightRegister.forEach(() => { callbackCalled = true; });
+ assert_true(callbackCalled);
+}, "HighlightRegistry is a maplike interface that works as expected even if Map.prototype is tampered.");
+</script>