<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<script>

description("This tests the constructor for the CloseEvent DOM class.");

// No initializer is passed.
shouldBe("new CloseEvent('eventType').bubbles", "false");
shouldBe("new CloseEvent('eventType').cancelable", "false");
shouldBe("new CloseEvent('eventType').wasClean", "false");
shouldBe("new CloseEvent('eventType').code", "0");
shouldBeEqualToString("new CloseEvent('eventType').reason", "");

// bubbles is passed.
shouldBe("new CloseEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new CloseEvent('eventType', { bubbles: true }).bubbles", "true");

// cancelable is passed.
shouldBe("new CloseEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new CloseEvent('eventType', { cancelable: true }).cancelable", "true");

// wasClean is passed.
shouldBe("new CloseEvent('eventType', { wasClean: false }).wasClean", "false");
shouldBe("new CloseEvent('eventType', { wasClean: true }).wasClean", "true");

// reason is passed.
// Strings.
shouldBeEqualToString("new CloseEvent('eventType', { reason: 'koakuma' }).reason", "koakuma");
shouldBeEqualToString("new CloseEvent('eventType', { reason: '' }).reason", "");

// Non-strings.
shouldBeEqualToString("new CloseEvent('eventType', { reason: undefined }).reason", "");
shouldBeEqualToString("new CloseEvent('eventType', { reason: null }).reason", "null");
shouldBeEqualToString("new CloseEvent('eventType', { reason: false }).reason", "false");
shouldBeEqualToString("new CloseEvent('eventType', { reason: true }).reason", "true");
shouldBeEqualToString("new CloseEvent('eventType', { reason: 12345 }).reason", "12345");
shouldBeEqualToString("new CloseEvent('eventType', { reason: 18446744073709551615 }).reason", "18446744073709552000");
shouldBeEqualToString("new CloseEvent('eventType', { reason: NaN }).reason", "NaN");
shouldBeEqualToString("new CloseEvent('eventType', { reason: [] }).reason", "");
shouldBeEqualToString("new CloseEvent('eventType', { reason: [1, 2, 3] }).reason", "1,2,3");
shouldBeEqualToString("new CloseEvent('eventType', { reason: {koakuma: 12345} }).reason", "[object Object]");
shouldBeEqualToString("new CloseEvent('eventType', { reason: {valueOf: function () { return 'koakuma'; } } }).reason", "[object Object]");

// code is passed.
// Numbers within the unsigned short range.
shouldBe("new CloseEvent('eventType', { code: 0 }).code", "0");
shouldBe("new CloseEvent('eventType', { code: 1 }).code", "1");
shouldBe("new CloseEvent('eventType', { code: 65534 }).code", "65534");
shouldBe("new CloseEvent('eventType', { code: 65535 }).code", "65535");

// Numbers out of the unsigned short range.
// 2^{53}-1, the largest number that can be exactly represented by double.
shouldBe("new CloseEvent('eventType', { code: 9007199254740991 }).code", "65535");
// 2^{64}-1
shouldBe("new CloseEvent('eventType', { code: 18446744073709551615 }).code", "0");
shouldBe("new CloseEvent('eventType', { code: 12345678901234567890 }).code", "2048");
shouldBe("new CloseEvent('eventType', { code: -1 }).code", "65535");
shouldBe("new CloseEvent('eventType', { code: 123.45 }).code", "123");
shouldBe("new CloseEvent('eventType', { code: NaN }).code", "0");

// Non-numeric values.
shouldBe("new CloseEvent('eventType', { code: undefined }).code", "0");
shouldBe("new CloseEvent('eventType', { code: null }).code", "0");
shouldBe("new CloseEvent('eventType', { code: '' }).code", "0");
shouldBe("new CloseEvent('eventType', { code: '12345' }).code", "12345");
shouldBe("new CloseEvent('eventType', { code: '12345a' }).code", "0");
shouldBe("new CloseEvent('eventType', { code: 'abc' }).code", "0");
shouldBe("new CloseEvent('eventType', { code: [] }).code", "0");
shouldBe("new CloseEvent('eventType', { code: [12345] }).code", "12345");
shouldBe("new CloseEvent('eventType', { code: [12345, 67890] }).code", "0");
shouldBe("new CloseEvent('eventType', { code: {} }).code", "0");
shouldBe("new CloseEvent('eventType', { code: {moemoe: 12345} }).code", "0");
shouldBe("new CloseEvent('eventType', { code: {valueOf: function () { return 12345; }} }).code", "12345");

// All initializers are passed.
shouldBe("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).bubbles", "true");
shouldBe("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).cancelable", "true");
shouldBe("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).wasClean", "true");
shouldBe("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).code", "12345");
shouldBeEqualToString("new CloseEvent('eventType', { bubbles: true, cancelable: true, wasClean: true, code : 12345, reason: 'koakuma' }).reason", "koakuma");
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
