<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.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.
shouldThrowErrorName("new UIEvent('eventType', { view: testObject }).view", "TypeError");
shouldThrowErrorName("new UIEvent('eventType', { view: document }).view", "TypeError");
shouldBeNull("new UIEvent('eventType', { view: undefined }).view");
shouldBeNull("new UIEvent('eventType', { view: null }).view");
shouldThrowErrorName("new UIEvent('eventType', { view: false }).view", "TypeError");
shouldThrowErrorName("new UIEvent('eventType', { view: true }).view", "TypeError");
shouldThrowErrorName("new UIEvent('eventType', { view: '' }).view", "TypeError");
shouldThrowErrorName("new UIEvent('eventType', { view: 'chocolate' }).view", "TypeError");
shouldThrowErrorName("new UIEvent('eventType', { view: 12345 }).view", "TypeError");
shouldThrowErrorName("new UIEvent('eventType', { view: 18446744073709551615 }).view", "TypeError");
shouldThrowErrorName("new UIEvent('eventType', { view: NaN }).view", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new UIEvent('eventType', { view: {valueOf: function () { return window; } } }).view", "TypeError");
shouldThrowErrorName("new UIEvent('eventType', { get view() { return 123; } }).view", "TypeError");
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>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
