blob: 03f8b5b2e27c368c6d171d881b180cc3034374b5 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>
description("This tests the constructor for the UIEvent DOM class.");
var testObject = {nyannyan: 123};
// No initializer is passed.
shouldBe("new UIEvent('eventType').bubbles", "false");
shouldBe("new UIEvent('eventType').cancelable", "false");
shouldBe("new UIEvent('eventType').view", "null");
shouldBe("new UIEvent('eventType').detail", "0");
// bubbles is passed.
shouldBe("new UIEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new UIEvent('eventType', { bubbles: true }).bubbles", "true");
// cancelable is passed.
shouldBe("new UIEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new UIEvent('eventType', { cancelable: true }).cancelable", "true");
// view is passed.
// Window objects.
shouldBe("new UIEvent('eventType', { view: window }).view", "window");
shouldBe("new UIEvent('eventType', { view: this }).view", "this");
// Non-window objects.
shouldThrow("new UIEvent('eventType', { view: testObject }).view");
shouldThrow("new UIEvent('eventType', { view: document }).view");
shouldBe("new UIEvent('eventType', { view: undefined }).view", "null");
shouldBe("new UIEvent('eventType', { view: null }).view", "null");
shouldThrow("new UIEvent('eventType', { view: false }).view");
shouldThrow("new UIEvent('eventType', { view: true }).view");
shouldThrow("new UIEvent('eventType', { view: '' }).view");
shouldThrow("new UIEvent('eventType', { view: 'chocolate' }).view");
shouldThrow("new UIEvent('eventType', { view: 12345 }).view");
shouldThrow("new UIEvent('eventType', { view: 18446744073709551615 }).view");
shouldThrow("new UIEvent('eventType', { view: NaN }).view");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrow("new UIEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window");
shouldBe("new UIEvent('eventType', { get view() { return window; } }).view", "window");
shouldThrow("new UIEvent('eventType', { get view() { return 123; } }).view");
shouldThrow("new UIEvent('eventType', { get view() { throw 'UIEvent Error'; } })");
// detail is passed.
// numbers within the long range.
shouldBe("new UIEvent('eventType', { detail: 0 }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: 2147483647 }).detail", "2147483647");
shouldBe("new UIEvent('eventType', { detail: -1 }).detail", "-1");
shouldBe("new UIEvent('eventType', { detail: -2147483648 }).detail", "-2147483648");
// numbers out of the long range.
shouldBe("new UIEvent('eventType', { detail: 4294967295 }).detail", "-1");
// 2^{53}-1, the largest number that can be exactly represented by double.
shouldBe("new UIEvent('eventType', { detail: 9007199254740991 }).detail", "-1");
// 2^{64}-1
shouldBe("new UIEvent('eventType', { detail: 18446744073709551615 }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: 123.45 }).detail", "123");
shouldBe("new UIEvent('eventType', { detail: NaN }).detail", "0");
// Non-numeric values.
shouldBe("new UIEvent('eventType', { detail: undefined }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: null }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: '' }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: '12345' }).detail", "12345");
shouldBe("new UIEvent('eventType', { detail: '12345a' }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: 'abc' }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: [] }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: [12345] }).detail", "12345");
shouldBe("new UIEvent('eventType', { detail: [12345, 67890] }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: {} }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: {moemoe: 12345} }).detail", "0");
shouldBe("new UIEvent('eventType', { detail: {valueOf: function () { return 12345; }} }).detail", "12345");
// All initializers are passed.
shouldBe("new UIEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 123 }).bubbles", "true");
shouldBe("new UIEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 123 }).cancelable", "true");
shouldBe("new UIEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 123 }).view", "window");
shouldBe("new UIEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 123 }).detail", "123");
</script>
</body>
</html>