blob: 0b381c4db3e0ed94c6454ca31330d577320eea57 [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 KeyboardEvent DOM class.");
var testObject = {nyannyan: 123};
// No initializer is passed.
shouldBe("new KeyboardEvent('eventType').bubbles", "false");
shouldBe("new KeyboardEvent('eventType').cancelable", "false");
shouldBe("new KeyboardEvent('eventType').view", "null");
shouldBe("new KeyboardEvent('eventType').detail", "0");
shouldBeEqualToString("new KeyboardEvent('eventType').keyIdentifier", "");
shouldBe("new KeyboardEvent('eventType').location", "0");
shouldBe("new KeyboardEvent('eventType').ctrlKey", "false");
shouldBe("new KeyboardEvent('eventType').altKey", "false");
shouldBe("new KeyboardEvent('eventType').shiftKey", "false");
shouldBe("new KeyboardEvent('eventType').metaKey", "false");
// bubbles is passed.
shouldBe("new KeyboardEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new KeyboardEvent('eventType', { bubbles: true }).bubbles", "true");
// cancelable is passed.
shouldBe("new KeyboardEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new KeyboardEvent('eventType', { cancelable: true }).cancelable", "true");
// view is passed.
// Window objects.
shouldBe("new KeyboardEvent('eventType', { view: window }).view", "window");
shouldBe("new KeyboardEvent('eventType', { view: this }).view", "this");
// repeat is passed.
shouldBe("new KeyboardEvent('eventType', { }).repeat", "false");
shouldBe("new KeyboardEvent('eventType', { repeat: false }).repeat", "false");
shouldBe("new KeyboardEvent('eventType', { repeat: true }).repeat", "true");
// isCompositing is passed.
shouldBe("new KeyboardEvent('eventType', { }).isComposing", "false");
shouldBe("new KeyboardEvent('eventType', { isComposing: false }).isComposing", "false");
shouldBe("new KeyboardEvent('eventType', { isComposing: true }).isComposing", "true");
// Non-window objects.
shouldThrowErrorName("new KeyboardEvent('eventType', { view: testObject }).view", "TypeError");
shouldThrowErrorName("new KeyboardEvent('eventType', { view: document }).view", "TypeError");
shouldBeNull("new KeyboardEvent('eventType', { view: undefined }).view");
shouldBeNull("new KeyboardEvent('eventType', { view: null }).view");
shouldThrowErrorName("new KeyboardEvent('eventType', { view: false }).view", "TypeError");
shouldThrowErrorName("new KeyboardEvent('eventType', { view: true }).view", "TypeError");
shouldThrowErrorName("new KeyboardEvent('eventType', { view: '' }).view", "TypeError");
shouldThrowErrorName("new KeyboardEvent('eventType', { view: 'chocolate' }).view", "TypeError");
shouldThrowErrorName("new KeyboardEvent('eventType', { view: 12345 }).view", "TypeError");
shouldThrowErrorName("new KeyboardEvent('eventType', { view: 18446744073709551615 }).view", "TypeError");
shouldThrowErrorName("new KeyboardEvent('eventType', { view: NaN }).view", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new KeyboardEvent('eventType', { view: {valueOf: function () { return window; } } }).view", "TypeError");
shouldThrowErrorName("new KeyboardEvent('eventType', { get view() { return 123; } }).view", "TypeError");
shouldThrow("new KeyboardEvent('eventType', { get view() { throw 'KeyboardEvent Error'; } })");
// keyIdentifier is passed.
// Strings.
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: 'koakuma' }).keyIdentifier", "koakuma");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: '' }).keyIdentifier", "");
// Non-strings.
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: undefined }).keyIdentifier", "");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: null }).keyIdentifier", "null");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: false }).keyIdentifier", "false");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: true }).keyIdentifier", "true");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: 12345 }).keyIdentifier", "12345");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: 18446744073709551615 }).keyIdentifier", "18446744073709552000");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: NaN }).keyIdentifier", "NaN");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: [] }).keyIdentifier", "");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: [1, 2, 3] }).keyIdentifier", "1,2,3");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: {koakuma: 12345} }).keyIdentifier", "[object Object]");
shouldBeEqualToString("new KeyboardEvent('eventType', { keyIdentifier: {valueOf: function () { return 'koakuma'; } } }).keyIdentifier", "[object Object]");
// location / keyLocation is passed.
["location", "keyLocation"].forEach(function (propertyName) {
// numbers within the unsigned long range.
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": KeyboardEvent.DOM_KEY_LOCATION_STANDARD })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": KeyboardEvent.DOM_KEY_LOCATION_LEFT })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": 4294967294 })." + propertyName, "4294967294");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": 4294967295 })." + propertyName, "4294967295");
// numbers out of the unsigned long range.
// 2^{53}-1, the largest number that can be exactly represented by double.
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": 9007199254740991 })." + propertyName, "4294967295");
// 2^{64}-1
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": 18446744073709551615 })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": 12345678901234567890 })." + propertyName, "3944679424");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": -1 })." + propertyName, "4294967295");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": 123.45 })." + propertyName, "123");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": NaN })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
// Non-numeric values.
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": undefined })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": null })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": '' })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": '12345' })." + propertyName, "12345");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": '12345a' })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": 'abc' })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": [] })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": [12345] })." + propertyName, "12345");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": [12345, 67890] })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": {} })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": {moemoe: 12345} })." + propertyName, "KeyboardEvent.DOM_KEY_LOCATION_STANDARD");
shouldBe("new KeyboardEvent('eventType', { " + propertyName + ": {valueOf: function () { return 12345; }} })." + propertyName, "12345");
});
shouldBe("new KeyboardEvent('eventType', { keyLocation: KeyboardEvent.DOM_KEY_LOCATION_LEFT }).location", "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
shouldBe("new KeyboardEvent('eventType', { location: KeyboardEvent.DOM_KEY_LOCATION_LEFT }).keyLocation", "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
// ctrlKey, altKey, shiftKey and metaKey are passed.
["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach(function (attr) {
shouldBe("new KeyboardEvent('eventType', { " + attr + ": false })." + attr, "false");
shouldBe("new KeyboardEvent('eventType', { " + attr + ": true })." + attr, "true");
});
shouldBeTrue("new KeyboardEvent('eventType', { modifierAltGraph: true }).getModifierState('AltGraph')");
shouldBeTrue("new KeyboardEvent('eventType', { modifierCapsLock: true }).getModifierState('CapsLock')");
// All initializers are passed.
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).bubbles", "true");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).cancelable", "true");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).view", "window");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).detail", "111");
shouldBeEqualToString("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).key", "a");
shouldBeEqualToString("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).code", "KeyA");
shouldBeEqualToString("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).keyIdentifier", "chocolate");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).location", "222");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).ctrlKey", "true");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).altKey", "true");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).shiftKey", "true");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, key: 'a', code: 'KeyA', keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true }).metaKey", "true");
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>