diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike.html | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike.html')
-rw-r--r-- | testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike.html | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike.html b/testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike.html new file mode 100644 index 0000000000..d8bbe4731f --- /dev/null +++ b/testing/web-platform/tests/css/css-highlight-api/HighlightRegistry-maplike.html @@ -0,0 +1,75 @@ +<!doctype html> +<title>HighlightRegistry has a maplike interface</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> +<script> + 'use strict'; + + test(() => { + assert_not_equals(window.HighlightRegistry, undefined, 'HighlightRegistry is in window'); + assert_equals(typeof HighlightRegistry, 'function', 'HighlightRegistry is a function'); + assert_throws_js(TypeError, function () { var x = new HighlightRegistry(); }, + 'HighlightRegistry constructor throws'); + + assert_not_equals(CSS.highlights, undefined, 'CSS.highlights exists'); + assert_equals(CSS.highlights.__proto__, window.HighlightRegistry.prototype, + 'CSS.highlights and window.HighlightRegistry have same prototype'); + + assert_equals(CSS.highlights.size, 0, 'HighlightRegistry starts empty'); + }, 'HighlightRegistry initializes as it should.'); + + test(() => { + let name1 = "example1"; + let name2 = "example2"; + let h1 = new Highlight(); + let h2 = new Highlight(); + + assert_false(CSS.highlights.has(name1), 'HighlightRegistry.has returns false when it doesn\'t have the key which is called with as argument.'); + CSS.highlights.set(name1, h1); + assert_true(CSS.highlights.has(name1), 'HighlightRegistry.has returns true when it has the key which is called with as argument.'); + assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size is 1 after only inserting 1 key.'); + + assert_false(CSS.highlights.delete(name2), 'HighlightRegistry.delete returns false when trying to delete an key that is not in the map.'); + assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size stays the same after trying to delete a non-existing key.'); + + CSS.highlights.set(name2, h2); + assert_true(CSS.highlights.has(name1), 'HighlightRegistry.has returns true when it is called with the key inserted first'); + assert_true(CSS.highlights.has(name2), 'HighlightRegistry.has returns true when it is called with the key inserted second'); + assert_equals(CSS.highlights.get(name1), h1, 'HighlightRegistry.get returns the first Highlight when it is called with the key inserted first'); + assert_equals(CSS.highlights.get(name2), h2, 'HighlightRegistry.get returns the second Highlight when it is called with the key inserted second'); + assert_equals(CSS.highlights.size, 2, 'HighlightRegistry.size is 2 after only inserting two different keys.'); + + assert_true(CSS.highlights.delete(name2), 'HighlightRegistry.delete returns true when trying to delete a key that is in the group.'); + assert_true(CSS.highlights.has(name1), 'HighlightRegistry.has returns true when it is called with the key inserted first'); + assert_false(CSS.highlights.has(name2), 'HighlightRegistry.has returns true when it is called with the key that was deleted'); + assert_equals(CSS.highlights.get(name1), h1, 'HighlightRegistry.get still returns the first Highlight when it is called with the key inserted first'); + assert_equals(CSS.highlights.get(name2), undefined, 'HighlightRegistry.get returns undefined when it is called with a key that was deleted'); + assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size decreases in 1 after deleting an existing key.'); + + assert_false(CSS.highlights.delete(name2), 'HighlightRegistry.delete returns false when trying to delete a key that was already deleted.'); + assert_true(CSS.highlights.has(name1), 'HighlightRegistry.has returns true when it is called with the key inserted first'); + assert_false(CSS.highlights.has(name2), 'HighlightRegistry.has returns false when it is called with a key that was deleted twice'); + assert_equals(CSS.highlights.get(name1), h1, 'HighlightRegistry.get still returns the first Highlight when it is called with the key inserted first'); + assert_equals(CSS.highlights.get(name2), undefined, 'HighlightRegistry.get still returns undefined when it is called with a key that was deleted'); + assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size stays the same after trying to delete the same key for a second time.'); + + assert_true(CSS.highlights.delete(name1), 'HighlightRegistry.delete returns true when trying to delete the remaining key'); + assert_false(CSS.highlights.has(name1), 'HighlightRegistry.has returns false when it is called with the key inserted first and then deleted'); + assert_false(CSS.highlights.has(name2), 'HighlightRegistry.has returns false when it is called with the key inserted second and then deleted'); + assert_equals(CSS.highlights.get(name1), undefined, 'HighlightRegistry.get returns undefined when it is called with a key that was deleted'); + assert_equals(CSS.highlights.get(name2), undefined, 'HighlightRegistry.get returns undefined when it is called with a key that was deleted'); + assert_equals(CSS.highlights.size, 0, 'HighlightRegistry.size decreases in 1 after deleting an existing key.'); + + CSS.highlights.set(name1, h1); + CSS.highlights.set(name1, h2); + assert_equals(CSS.highlights.size, 1, 'HighlightRegistry.size keeps the same after an insertion of a Highlight with an existing name'); + assert_equals(CSS.highlights.get(name1), h2, 'The Highlight inserted with the same name as an existing one was effectively inserted into the registry'); + + CSS.highlights.clear(); + assert_equals(CSS.highlights.size, 0, 'HighlightRegistry.clear empties the map.'); + CSS.highlights.clear(); + assert_equals(CSS.highlights.size, 0, 'HighlightRegistry.clear called with an empty registry keeps it empty.'); + }, 'HighlightRegistry has a maplike interface.'); + +</script> |