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/dom/events/Event-subclasses-constructors.html | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.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/dom/events/Event-subclasses-constructors.html')
-rw-r--r-- | testing/web-platform/tests/dom/events/Event-subclasses-constructors.html | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/events/Event-subclasses-constructors.html b/testing/web-platform/tests/dom/events/Event-subclasses-constructors.html new file mode 100644 index 0000000000..08a5ded011 --- /dev/null +++ b/testing/web-platform/tests/dom/events/Event-subclasses-constructors.html @@ -0,0 +1,179 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Event constructors</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +function assert_props(iface, event, defaults) { + assert_true(event instanceof self[iface]); + expected[iface].properties.forEach(function(p) { + var property = p[0], value = p[defaults ? 1 : 2]; + assert_true(property in event, + "Event " + format_value(event) + " should have a " + + property + " property"); + assert_equals(event[property], value, + "The value of the " + property + " property should be " + + format_value(value)); + }); + if ("parent" in expected[iface]) { + assert_props(expected[iface].parent, event, defaults); + } +} + +// Class declarations don't go on the global by default, so put it there ourselves: + +self.SubclassedEvent = class SubclassedEvent extends Event { + constructor(name, props) { + super(name, props); + if (props && typeof(props) == "object" && "customProp" in props) { + this.customProp = props.customProp; + } else { + this.customProp = 5; + } + } + + get fixedProp() { + return 17; + } +} + +var EventModifierInit = [ + ["ctrlKey", false, true], + ["shiftKey", false, true], + ["altKey", false, true], + ["metaKey", false, true], +]; +var expected = { + "Event": { + "properties": [ + ["bubbles", false, true], + ["cancelable", false, true], + ["isTrusted", false, false], + ], + }, + + "UIEvent": { + "parent": "Event", + "properties": [ + ["view", null, window], + ["detail", 0, 7], + ], + }, + + "FocusEvent": { + "parent": "UIEvent", + "properties": [ + ["relatedTarget", null, document], + ], + }, + + "MouseEvent": { + "parent": "UIEvent", + "properties": EventModifierInit.concat([ + ["screenX", 0, 40], + ["screenY", 0, 40], + ["clientX", 0, 40], + ["clientY", 0, 40], + ["button", 0, 40], + ["buttons", 0, 40], + ["relatedTarget", null, document], + ]), + }, + + "WheelEvent": { + "parent": "MouseEvent", + "properties": [ + ["deltaX", 0.0, 3.1], + ["deltaY", 0.0, 3.1], + ["deltaZ", 0.0, 3.1], + ["deltaMode", 0, 40], + ], + }, + + "KeyboardEvent": { + "parent": "UIEvent", + "properties": EventModifierInit.concat([ + ["key", "", "string"], + ["code", "", "string"], + ["location", 0, 7], + ["repeat", false, true], + ["isComposing", false, true], + ["charCode", 0, 7], + ["keyCode", 0, 7], + ["which", 0, 7], + ]), + }, + + "CompositionEvent": { + "parent": "UIEvent", + "properties": [ + ["data", "", "string"], + ], + }, + + "SubclassedEvent": { + "parent": "Event", + "properties": [ + ["customProp", 5, 8], + ["fixedProp", 17, 17], + ], + }, +}; + +Object.keys(expected).forEach(function(iface) { + test(function() { + var event = new self[iface]("type"); + assert_props(iface, event, true); + }, iface + " constructor (no argument)"); + + test(function() { + var event = new self[iface]("type", undefined); + assert_props(iface, event, true); + }, iface + " constructor (undefined argument)"); + + test(function() { + var event = new self[iface]("type", null); + assert_props(iface, event, true); + }, iface + " constructor (null argument)"); + + test(function() { + var event = new self[iface]("type", {}); + assert_props(iface, event, true); + }, iface + " constructor (empty argument)"); + + test(function() { + var dictionary = {}; + expected[iface].properties.forEach(function(p) { + var property = p[0], value = p[1]; + dictionary[property] = value; + }); + var event = new self[iface]("type", dictionary); + assert_props(iface, event, true); + }, iface + " constructor (argument with default values)"); + + test(function() { + function fill_in(iface, dictionary) { + if ("parent" in expected[iface]) { + fill_in(expected[iface].parent, dictionary) + } + expected[iface].properties.forEach(function(p) { + var property = p[0], value = p[2]; + dictionary[property] = value; + }); + } + + var dictionary = {}; + fill_in(iface, dictionary); + + var event = new self[iface]("type", dictionary); + assert_props(iface, event, false); + }, iface + " constructor (argument with non-default values)"); +}); + +test(function () { + assert_throws_js(TypeError, function() { + new UIEvent("x", { view: 7 }) + }); +}, "UIEvent constructor (view argument with wrong type)") +</script> |