blob: ac40f1abecfdaa686d9e8f353c1c40c8c6d97bc2 [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 WheelEvent DOM class.");
var testObject = {nyannyan: 123};
var testDiv = document.createElement("div");
var xhr = new XMLHttpRequest;
// No initializer is passed.
shouldBe("new WheelEvent('eventType').bubbles", "false");
shouldBe("new WheelEvent('eventType').cancelable", "false");
shouldBe("new WheelEvent('eventType').view", "null");
shouldBe("new WheelEvent('eventType').detail", "0");
shouldBe("new WheelEvent('eventType').screenX", "0");
shouldBe("new WheelEvent('eventType').screenY", "0");
shouldBe("new WheelEvent('eventType').clientX", "0");
shouldBe("new WheelEvent('eventType').clientY", "0");
shouldBe("new WheelEvent('eventType').ctrlKey", "false");
shouldBe("new WheelEvent('eventType').shiftKey", "false");
shouldBe("new WheelEvent('eventType').altKey", "false");
shouldBe("new WheelEvent('eventType').metaKey", "false");
shouldBe("new WheelEvent('eventType').button", "0");
shouldBe("new WheelEvent('eventType').relatedTarget", "null");
shouldBe("new WheelEvent('eventType').wheelDeltaX", "0");
shouldBe("new WheelEvent('eventType').wheelDeltaY", "0");
shouldBe("new WheelEvent('eventType').deltaMode", "WheelEvent.DOM_DELTA_PIXEL");
// bubbles is passed.
shouldBe("new WheelEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new WheelEvent('eventType', { bubbles: true }).bubbles", "true");
// cancelable is passed.
shouldBe("new WheelEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new WheelEvent('eventType', { cancelable: true }).cancelable", "true");
// view is passed.
// Window objects.
shouldBe("new WheelEvent('eventType', { view: window }).view", "window");
shouldBe("new WheelEvent('eventType', { view: this }).view", "this");
// Non-window objects.
shouldThrowErrorName("new WheelEvent('eventType', { view: testObject }).view", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { view: document }).view", "TypeError");
shouldBeNull("new WheelEvent('eventType', { view: undefined }).view");
shouldBeNull("new WheelEvent('eventType', { view: null }).view");
shouldThrowErrorName("new WheelEvent('eventType', { view: false }).view", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { view: true }).view", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { view: '' }).view", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { view: 'chocolate' }).view", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { view: 12345 }).view", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { view: 18446744073709551615 }).view", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { view: NaN }).view", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new WheelEvent('eventType', { view: {valueOf: function () { return window; } } }).view", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { get view() { return 123; } }).view", "TypeError");
shouldThrow("new WheelEvent('eventType', { get view() { throw 'WheelEvent Error'; } })");
// detail, screenX, screenY, clientX and clientY are passed.
["detail", "screenX", "screenY", "clientX", "clientY", "wheelDeltaX", "wheelDeltaY"].forEach(function (attr) {
// numbers within the long range.
shouldBe("new WheelEvent('eventType', { " + attr + ": 0 })." + attr, "0");
shouldBe("new WheelEvent('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 WheelEvent('eventType', { " + attr + ": 2147483647 })." + attr, String(Math.pow(2, exponent) - 1));
shouldBe("new WheelEvent('eventType', { " + attr + ": -2147483648 })." + attr, String(-Math.pow(2, exponent)));
// numbers out of the long range.
shouldBe("new WheelEvent('eventType', { " + attr + ": 4294967295 })." + attr, "-1");
// 2^{53}-1, the largest number that can be exactly represented by double.
shouldBe("new WheelEvent('eventType', { " + attr + ": 9007199254740991 })." + attr, "-1");
// 2^{64}-1
shouldBe("new WheelEvent('eventType', { " + attr + ": 18446744073709551615 })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": 123.45 })." + attr, "123");
shouldBe("new WheelEvent('eventType', { " + attr + ": NaN })." + attr, "0");
// Non-numeric values.
shouldBe("new WheelEvent('eventType', { " + attr + ": undefined })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": null })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": '' })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": '12345' })." + attr, "12345");
shouldBe("new WheelEvent('eventType', { " + attr + ": '12345a' })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": 'abc' })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": [] })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": [12345] })." + attr, "12345");
shouldBe("new WheelEvent('eventType', { " + attr + ": [12345, 67890] })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": {} })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": {moemoe: 12345} })." + attr, "0");
shouldBe("new WheelEvent('eventType', { " + attr + ": {valueOf: function () { return 12345; }} })." + attr, "12345");
});
// deltaMode is passed.
// numbers within the unsigned long range.
shouldBe("new WheelEvent('eventType', { deltaMode: 0 }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: 1 }).deltaMode", "1");
shouldBe("new WheelEvent('eventType', { deltaMode: 4294967294 }).deltaMode", "4294967294");
shouldBe("new WheelEvent('eventType', { deltaMode: 4294967295 }).deltaMode", "4294967295");
shouldBe("new WheelEvent('eventType', { deltaMode: WheelEvent.DOM_DELTA_PIXEL }).deltaMode", "WheelEvent.DOM_DELTA_PIXEL");
shouldBe("new WheelEvent('eventType', { deltaMode: WheelEvent.DOM_DELTA_LINE }).deltaMode", "WheelEvent.DOM_DELTA_LINE");
shouldBe("new WheelEvent('eventType', { deltaMode: WheelEvent.DOM_DELTA_PAGE }).deltaMode", "WheelEvent.DOM_DELTA_PAGE");
// numbers out of the unsigned long range.
// 2^{53}-1, the largest number that can be exactly represented by double.
shouldBe("new WheelEvent('eventType', { deltaMode: 9007199254740991 }).deltaMode", "4294967295");
// 2^{64}-1
shouldBe("new WheelEvent('eventType', { deltaMode: 18446744073709551615 }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: 12345678901234567890 }).deltaMode", "3944679424");
shouldBe("new WheelEvent('eventType', { deltaMode: -1 }).deltaMode", "4294967295");
shouldBe("new WheelEvent('eventType', { deltaMode: 123.45 }).deltaMode", "123");
shouldBe("new WheelEvent('eventType', { deltaMode: NaN }).deltaMode", "0");
// Non-numeric values.
shouldBe("new WheelEvent('eventType', { deltaMode: undefined }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: null }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: '' }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: '12345' }).deltaMode", "12345");
shouldBe("new WheelEvent('eventType', { deltaMode: '12345a' }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: 'abc' }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: [] }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: [12345] }).deltaMode", "12345");
shouldBe("new WheelEvent('eventType', { deltaMode: [12345, 67890] }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: {} }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: {moemoe: 12345} }).deltaMode", "0");
shouldBe("new WheelEvent('eventType', { deltaMode: {valueOf: function () { return 12345; }} }).deltaMode", "12345");
// ctrlKey, altKey, shiftKey and metaKey are passed.
["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach(function (attr) {
shouldBe("new WheelEvent('eventType', { " + attr + ": false })." + attr, "false");
shouldBe("new WheelEvent('eventType', { " + attr + ": true })." + attr, "true");
});
// button is passed.
// Numbers within the unsigned short range.
shouldBe("new WheelEvent('eventType', { button: 0 }).button", "0");
shouldBe("new WheelEvent('eventType', { button: 1 }).button", "1");
shouldBe("new WheelEvent('eventType', { button: 65534 }).button", "65534");
// Numbers that are equal to ((unsigned short)-1) should be treated as 0.
shouldBe("new WheelEvent('eventType', { button: 65535 }).button", "0");
shouldBe("new WheelEvent('eventType', { button: 9007199254740991 }).button", "0");
shouldBe("new WheelEvent('eventType', { button: -1 }).button", "0");
// Numbers out of the unsigned short range.
// 2^{64}-1
shouldBe("new WheelEvent('eventType', { button: 18446744073709551615 }).button", "0");
shouldBe("new WheelEvent('eventType', { button: 12345678901234567890 }).button", "2048");
shouldBe("new WheelEvent('eventType', { button: 123.45 }).button", "123");
shouldBe("new WheelEvent('eventType', { button: NaN }).button", "0");
// Non-numeric values.
shouldBe("new WheelEvent('eventType', { button: undefined }).button", "0");
shouldBe("new WheelEvent('eventType', { button: null }).button", "0");
shouldBe("new WheelEvent('eventType', { button: '' }).button", "0");
shouldBe("new WheelEvent('eventType', { button: '12345' }).button", "12345");
shouldBe("new WheelEvent('eventType', { button: '12345a' }).button", "0");
shouldBe("new WheelEvent('eventType', { button: 'abc' }).button", "0");
shouldBe("new WheelEvent('eventType', { button: [] }).button", "0");
shouldBe("new WheelEvent('eventType', { button: [12345] }).button", "12345");
shouldBe("new WheelEvent('eventType', { button: [12345, 67890] }).button", "0");
shouldBe("new WheelEvent('eventType', { button: {} }).button", "0");
shouldBe("new WheelEvent('eventType', { button: {moemoe: 12345} }).button", "0");
shouldBe("new WheelEvent('eventType', { button: {valueOf: function () { return 12345; }} }).button", "12345");
// relatedTarget is passed.
// Valid objects.
shouldBe("new WheelEvent('eventType', { relatedTarget: testDiv }).relatedTarget", "testDiv");
shouldBe("new WheelEvent('eventType', { relatedTarget: document }).relatedTarget", "document");
shouldBe("new WheelEvent('eventType', { relatedTarget: xhr }).relatedTarget", "xhr");
// Invalid objects.
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: testObject })", "TypeError");
shouldBe("new WheelEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
shouldBe("new WheelEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: false })", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: true })", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: '' })", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: 'chocolate' })", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: 12345 })", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: 18446744073709551615 })", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: NaN })", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new WheelEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } })", "TypeError");
shouldThrowErrorName("new WheelEvent('eventType', { get relatedTarget() { return 123; } }).relatedTarget", "TypeError");
shouldThrow("new WheelEvent('eventType', { get relatedTarget() { throw 'WheelEvent Error'; } })");
// All initializers are passed.
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).bubbles", "true");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).cancelable", "true");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).view", "window");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).detail", "111");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).screenX", "222");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).screenY", "333");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).clientX", "444");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).clientY", "555");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).ctrlKey", "true");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).shiftKey", "true");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).altKey", "true");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).metaKey", "true");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).button", "666");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).relatedTarget", "testDiv");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).wheelDeltaX", "777");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).wheelDeltaY", "888");
shouldBe("new WheelEvent('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, wheelDeltaX: 777, wheelDeltaY: 888, deltaMode: WheelEvent.DOM_DELTA_PAGE }).deltaMode", "WheelEvent.DOM_DELTA_PAGE");
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>