blob: 65ae91e8a35d9316c8893cf4e1fb9b6c9af851ed [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("This tests the constructor for the MouseEvent DOM class.");
var testObject = {nyannyan: 123};
var testDiv = document.createElement("div");
var xhr = new XMLHttpRequest;
// No initializer is passed.
shouldBe("new MouseEvent('eventType').bubbles", "false");
shouldBe("new MouseEvent('eventType').cancelable", "false");
shouldBe("new MouseEvent('eventType').view", "null");
shouldBe("new MouseEvent('eventType').detail", "0");
shouldBe("new MouseEvent('eventType').screenX", "0");
shouldBe("new MouseEvent('eventType').screenY", "0");
shouldBe("new MouseEvent('eventType').clientX", "0");
shouldBe("new MouseEvent('eventType').clientY", "0");
shouldBe("new MouseEvent('eventType').ctrlKey", "false");
shouldBe("new MouseEvent('eventType').shiftKey", "false");
shouldBe("new MouseEvent('eventType').altKey", "false");
shouldBe("new MouseEvent('eventType').metaKey", "false");
shouldBe("new MouseEvent('eventType').button", "0");
shouldBe("new MouseEvent('eventType').relatedTarget", "null");
shouldBeFalse("'dataTransfer' in (new MouseEvent('eventType'))")
// bubbles is passed.
shouldBe("new MouseEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new MouseEvent('eventType', { bubbles: true }).bubbles", "true");
// cancelable is passed.
shouldBe("new MouseEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new MouseEvent('eventType', { cancelable: true }).cancelable", "true");
// view is passed.
// Window objects.
shouldBe("new MouseEvent('eventType', { view: window }).view", "window");
shouldBe("new MouseEvent('eventType', { view: this }).view", "this");
// Non-window objects.
shouldThrowErrorName("new MouseEvent('eventType', { view: testObject }).view", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { view: document }).view", "TypeError");
shouldBeNull("new MouseEvent('eventType', { view: undefined }).view");
shouldBeNull("new MouseEvent('eventType', { view: null }).view");
shouldThrowErrorName("new MouseEvent('eventType', { view: false }).view", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { view: true }).view", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { view: '' }).view", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { view: 'chocolate' }).view", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { view: 12345 }).view", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { view: 18446744073709551615 }).view", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { view: NaN }).view", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new MouseEvent('eventType', { view: {valueOf: function () { return window; } } }).view", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { get view() { return 123; } }).view", "TypeError");
shouldThrow("new MouseEvent('eventType', { get view() { throw 'MouseEvent Error'; } })");
// detail, screenX, screenY, clientX and clientY are passed.
["detail", "screenX", "screenY", "clientX", "clientY"].forEach(function (attr) {
// numbers within the long range.
shouldBe("new MouseEvent('eventType', { " + attr + ": 0 })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": -1 })." + attr, "-1");
// numbers within the long range, but outside the range of LayoutUnit.
var exponent = attr.startsWith("client") ? 25 : 31;
shouldBe("new MouseEvent('eventType', { " + attr + ": 2147483647 })." + attr, String(Math.pow(2, exponent) - 1));
shouldBe("new MouseEvent('eventType', { " + attr + ": -2147483648 })." + attr, String(-Math.pow(2, exponent)));
// numbers out of the long range.
shouldBe("new MouseEvent('eventType', { " + attr + ": 4294967295 })." + attr, "-1");
// 2^{53}-1, the largest number that can be exactly represented by double.
shouldBe("new MouseEvent('eventType', { " + attr + ": 9007199254740991 })." + attr, "-1");
// 2^{64}-1
shouldBe("new MouseEvent('eventType', { " + attr + ": 18446744073709551615 })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": 123.45 })." + attr, "123");
shouldBe("new MouseEvent('eventType', { " + attr + ": NaN })." + attr, "0");
// Non-numeric values.
shouldBe("new MouseEvent('eventType', { " + attr + ": undefined })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": null })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": '' })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": '12345' })." + attr, "12345");
shouldBe("new MouseEvent('eventType', { " + attr + ": '12345a' })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": 'abc' })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": [] })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": [12345] })." + attr, "12345");
shouldBe("new MouseEvent('eventType', { " + attr + ": [12345, 67890] })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": {} })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": {moemoe: 12345} })." + attr, "0");
shouldBe("new MouseEvent('eventType', { " + attr + ": {valueOf: function () { return 12345; }} })." + attr, "12345");
});
// ctrlKey, altKey, shiftKey and metaKey are passed.
["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach(function (attr) {
shouldBe("new MouseEvent('eventType', { " + attr + ": false })." + attr, "false");
shouldBe("new MouseEvent('eventType', { " + attr + ": true })." + attr, "true");
});
// button is passed.
// Numbers within the short range.
shouldBe("new MouseEvent('eventType', { button: 0 }).button", "0");
shouldBe("new MouseEvent('eventType', { button: -1 }).button", "-1");
shouldBe("new MouseEvent('eventType', { button: -2 }).button", "0");
shouldBe("new MouseEvent('eventType', { button: 1 }).button", "1");
shouldBe("new MouseEvent('eventType', { button: -32768 }).button", "-32768");
shouldBe("new MouseEvent('eventType', { button: 32767 }).button", "32767");
shouldBe("new MouseEvent('eventType', { button: 32768 }).button", "-32768");
shouldBe("new MouseEvent('eventType', { button: -32769 }).button", "32767");
// Numbers out of the unsigned short range.
// 2^{64}-1
shouldBe("new MouseEvent('eventType', { button: 18446744073709551615 }).button", "0");
shouldBe("new MouseEvent('eventType', { button: 12345678901234567890 }).button", "2048");
shouldBe("new MouseEvent('eventType', { button: 123.45 }).button", "123");
shouldBe("new MouseEvent('eventType', { button: NaN }).button", "0");
// Non-numeric values.
shouldBe("new MouseEvent('eventType', { button: undefined }).button", "0");
shouldBe("new MouseEvent('eventType', { button: null }).button", "0");
shouldBe("new MouseEvent('eventType', { button: '' }).button", "0");
shouldBe("new MouseEvent('eventType', { button: '12345' }).button", "12345");
shouldBe("new MouseEvent('eventType', { button: '12345a' }).button", "0");
shouldBe("new MouseEvent('eventType', { button: 'abc' }).button", "0");
shouldBe("new MouseEvent('eventType', { button: [] }).button", "0");
shouldBe("new MouseEvent('eventType', { button: [12345] }).button", "12345");
shouldBe("new MouseEvent('eventType', { button: [12345, 67890] }).button", "0");
shouldBe("new MouseEvent('eventType', { button: {} }).button", "0");
shouldBe("new MouseEvent('eventType', { button: {moemoe: 12345} }).button", "0");
shouldBe("new MouseEvent('eventType', { button: {valueOf: function () { return 12345; }} }).button", "12345");
// relatedTarget is passed.
// Valid objects.
shouldBe("new MouseEvent('eventType', { relatedTarget: testDiv }).relatedTarget", "testDiv");
shouldBe("new MouseEvent('eventType', { relatedTarget: document }).relatedTarget", "document");
shouldBe("new MouseEvent('eventType', { relatedTarget: xhr }).relatedTarget", "xhr");
shouldBe("new MouseEvent('eventType', { relatedTarget: window }).relatedTarget", "window");
// Invalid objects.
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: testObject })", "TypeError");
shouldBe("new MouseEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
shouldBe("new MouseEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: false })", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: true })", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: '' })", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: 'chocolate' })", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: 12345 })", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: 18446744073709551615 })", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: NaN })", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new MouseEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } })", "TypeError");
shouldThrowErrorName("new MouseEvent('eventType', { get relatedTarget() { return 123; } })", "TypeError");
shouldThrow("new MouseEvent('eventType', { get relatedTarget() { throw 'MouseEvent Error'; } })");
// All initializers are passed.
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).bubbles", "true");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).cancelable", "true");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).view", "window");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).detail", "111");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).screenX", "222");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).screenY", "333");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).clientX", "444");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).clientY", "555");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).ctrlKey", "true");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).shiftKey", "true");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).altKey", "true");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).metaKey", "true");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).button", "666");
shouldBe("new MouseEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, screenX: 222, screenY: 333, clientX: 444, clientY: 555, ctrlKey: true, shiftKey: true, altKey: true, metaKey: true, button: 666, relatedTarget: testDiv }).relatedTarget", "testDiv");
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>