11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<meta charset="utf-8"> 31cb0ef41Sopenharmony_ci<title>Event constructors</title> 41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 61cb0ef41Sopenharmony_ci<div id="log"></div> 71cb0ef41Sopenharmony_ci<script> 81cb0ef41Sopenharmony_cifunction assert_props(iface, event, defaults) { 91cb0ef41Sopenharmony_ci assert_true(event instanceof self[iface]); 101cb0ef41Sopenharmony_ci expected[iface].properties.forEach(function(p) { 111cb0ef41Sopenharmony_ci var property = p[0], value = p[defaults ? 1 : 2]; 121cb0ef41Sopenharmony_ci assert_true(property in event, 131cb0ef41Sopenharmony_ci "Event " + format_value(event) + " should have a " + 141cb0ef41Sopenharmony_ci property + " property"); 151cb0ef41Sopenharmony_ci assert_equals(event[property], value, 161cb0ef41Sopenharmony_ci "The value of the " + property + " property should be " + 171cb0ef41Sopenharmony_ci format_value(value)); 181cb0ef41Sopenharmony_ci }); 191cb0ef41Sopenharmony_ci if ("parent" in expected[iface]) { 201cb0ef41Sopenharmony_ci assert_props(expected[iface].parent, event, defaults); 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci} 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci// Class declarations don't go on the global by default, so put it there ourselves: 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciself.SubclassedEvent = class SubclassedEvent extends Event { 271cb0ef41Sopenharmony_ci constructor(name, props) { 281cb0ef41Sopenharmony_ci super(name, props); 291cb0ef41Sopenharmony_ci if (props && typeof(props) == "object" && "customProp" in props) { 301cb0ef41Sopenharmony_ci this.customProp = props.customProp; 311cb0ef41Sopenharmony_ci } else { 321cb0ef41Sopenharmony_ci this.customProp = 5; 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci get fixedProp() { 371cb0ef41Sopenharmony_ci return 17; 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci} 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_civar EventModifierInit = [ 421cb0ef41Sopenharmony_ci ["ctrlKey", false, true], 431cb0ef41Sopenharmony_ci ["shiftKey", false, true], 441cb0ef41Sopenharmony_ci ["altKey", false, true], 451cb0ef41Sopenharmony_ci ["metaKey", false, true], 461cb0ef41Sopenharmony_ci]; 471cb0ef41Sopenharmony_civar expected = { 481cb0ef41Sopenharmony_ci "Event": { 491cb0ef41Sopenharmony_ci "properties": [ 501cb0ef41Sopenharmony_ci ["bubbles", false, true], 511cb0ef41Sopenharmony_ci ["cancelable", false, true], 521cb0ef41Sopenharmony_ci ["isTrusted", false, false], 531cb0ef41Sopenharmony_ci ], 541cb0ef41Sopenharmony_ci }, 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci "UIEvent": { 571cb0ef41Sopenharmony_ci "parent": "Event", 581cb0ef41Sopenharmony_ci "properties": [ 591cb0ef41Sopenharmony_ci ["view", null, window], 601cb0ef41Sopenharmony_ci ["detail", 0, 7], 611cb0ef41Sopenharmony_ci ], 621cb0ef41Sopenharmony_ci }, 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci "FocusEvent": { 651cb0ef41Sopenharmony_ci "parent": "UIEvent", 661cb0ef41Sopenharmony_ci "properties": [ 671cb0ef41Sopenharmony_ci ["relatedTarget", null, document], 681cb0ef41Sopenharmony_ci ], 691cb0ef41Sopenharmony_ci }, 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci "MouseEvent": { 721cb0ef41Sopenharmony_ci "parent": "UIEvent", 731cb0ef41Sopenharmony_ci "properties": EventModifierInit.concat([ 741cb0ef41Sopenharmony_ci ["screenX", 0, 40], 751cb0ef41Sopenharmony_ci ["screenY", 0, 40], 761cb0ef41Sopenharmony_ci ["clientX", 0, 40], 771cb0ef41Sopenharmony_ci ["clientY", 0, 40], 781cb0ef41Sopenharmony_ci ["button", 0, 40], 791cb0ef41Sopenharmony_ci ["buttons", 0, 40], 801cb0ef41Sopenharmony_ci ["relatedTarget", null, document], 811cb0ef41Sopenharmony_ci ]), 821cb0ef41Sopenharmony_ci }, 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ci "WheelEvent": { 851cb0ef41Sopenharmony_ci "parent": "MouseEvent", 861cb0ef41Sopenharmony_ci "properties": [ 871cb0ef41Sopenharmony_ci ["deltaX", 0.0, 3.1], 881cb0ef41Sopenharmony_ci ["deltaY", 0.0, 3.1], 891cb0ef41Sopenharmony_ci ["deltaZ", 0.0, 3.1], 901cb0ef41Sopenharmony_ci ["deltaMode", 0, 40], 911cb0ef41Sopenharmony_ci ], 921cb0ef41Sopenharmony_ci }, 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci "KeyboardEvent": { 951cb0ef41Sopenharmony_ci "parent": "UIEvent", 961cb0ef41Sopenharmony_ci "properties": EventModifierInit.concat([ 971cb0ef41Sopenharmony_ci ["key", "", "string"], 981cb0ef41Sopenharmony_ci ["code", "", "string"], 991cb0ef41Sopenharmony_ci ["location", 0, 7], 1001cb0ef41Sopenharmony_ci ["repeat", false, true], 1011cb0ef41Sopenharmony_ci ["isComposing", false, true], 1021cb0ef41Sopenharmony_ci ["charCode", 0, 7], 1031cb0ef41Sopenharmony_ci ["keyCode", 0, 7], 1041cb0ef41Sopenharmony_ci ["which", 0, 7], 1051cb0ef41Sopenharmony_ci ]), 1061cb0ef41Sopenharmony_ci }, 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci "CompositionEvent": { 1091cb0ef41Sopenharmony_ci "parent": "UIEvent", 1101cb0ef41Sopenharmony_ci "properties": [ 1111cb0ef41Sopenharmony_ci ["data", "", "string"], 1121cb0ef41Sopenharmony_ci ], 1131cb0ef41Sopenharmony_ci }, 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci "SubclassedEvent": { 1161cb0ef41Sopenharmony_ci "parent": "Event", 1171cb0ef41Sopenharmony_ci "properties": [ 1181cb0ef41Sopenharmony_ci ["customProp", 5, 8], 1191cb0ef41Sopenharmony_ci ["fixedProp", 17, 17], 1201cb0ef41Sopenharmony_ci ], 1211cb0ef41Sopenharmony_ci }, 1221cb0ef41Sopenharmony_ci}; 1231cb0ef41Sopenharmony_ci 1241cb0ef41Sopenharmony_ciObject.keys(expected).forEach(function(iface) { 1251cb0ef41Sopenharmony_ci test(function() { 1261cb0ef41Sopenharmony_ci var event = new self[iface]("type"); 1271cb0ef41Sopenharmony_ci assert_props(iface, event, true); 1281cb0ef41Sopenharmony_ci }, iface + " constructor (no argument)"); 1291cb0ef41Sopenharmony_ci 1301cb0ef41Sopenharmony_ci test(function() { 1311cb0ef41Sopenharmony_ci var event = new self[iface]("type", undefined); 1321cb0ef41Sopenharmony_ci assert_props(iface, event, true); 1331cb0ef41Sopenharmony_ci }, iface + " constructor (undefined argument)"); 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci test(function() { 1361cb0ef41Sopenharmony_ci var event = new self[iface]("type", null); 1371cb0ef41Sopenharmony_ci assert_props(iface, event, true); 1381cb0ef41Sopenharmony_ci }, iface + " constructor (null argument)"); 1391cb0ef41Sopenharmony_ci 1401cb0ef41Sopenharmony_ci test(function() { 1411cb0ef41Sopenharmony_ci var event = new self[iface]("type", {}); 1421cb0ef41Sopenharmony_ci assert_props(iface, event, true); 1431cb0ef41Sopenharmony_ci }, iface + " constructor (empty argument)"); 1441cb0ef41Sopenharmony_ci 1451cb0ef41Sopenharmony_ci test(function() { 1461cb0ef41Sopenharmony_ci var dictionary = {}; 1471cb0ef41Sopenharmony_ci expected[iface].properties.forEach(function(p) { 1481cb0ef41Sopenharmony_ci var property = p[0], value = p[1]; 1491cb0ef41Sopenharmony_ci dictionary[property] = value; 1501cb0ef41Sopenharmony_ci }); 1511cb0ef41Sopenharmony_ci var event = new self[iface]("type", dictionary); 1521cb0ef41Sopenharmony_ci assert_props(iface, event, true); 1531cb0ef41Sopenharmony_ci }, iface + " constructor (argument with default values)"); 1541cb0ef41Sopenharmony_ci 1551cb0ef41Sopenharmony_ci test(function() { 1561cb0ef41Sopenharmony_ci function fill_in(iface, dictionary) { 1571cb0ef41Sopenharmony_ci if ("parent" in expected[iface]) { 1581cb0ef41Sopenharmony_ci fill_in(expected[iface].parent, dictionary) 1591cb0ef41Sopenharmony_ci } 1601cb0ef41Sopenharmony_ci expected[iface].properties.forEach(function(p) { 1611cb0ef41Sopenharmony_ci var property = p[0], value = p[2]; 1621cb0ef41Sopenharmony_ci dictionary[property] = value; 1631cb0ef41Sopenharmony_ci }); 1641cb0ef41Sopenharmony_ci } 1651cb0ef41Sopenharmony_ci 1661cb0ef41Sopenharmony_ci var dictionary = {}; 1671cb0ef41Sopenharmony_ci fill_in(iface, dictionary); 1681cb0ef41Sopenharmony_ci 1691cb0ef41Sopenharmony_ci var event = new self[iface]("type", dictionary); 1701cb0ef41Sopenharmony_ci assert_props(iface, event, false); 1711cb0ef41Sopenharmony_ci }, iface + " constructor (argument with non-default values)"); 1721cb0ef41Sopenharmony_ci}); 1731cb0ef41Sopenharmony_ci 1741cb0ef41Sopenharmony_citest(function () { 1751cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 1761cb0ef41Sopenharmony_ci new UIEvent("x", { view: 7 }) 1771cb0ef41Sopenharmony_ci }); 1781cb0ef41Sopenharmony_ci}, "UIEvent constructor (view argument with wrong type)") 1791cb0ef41Sopenharmony_ci</script> 180