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

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

// No initializer passed.
shouldBe("new CustomEvent('eventType').bubbles", "false");
shouldBe("new CustomEvent('eventType').cancelable", "false");
shouldBeNull("new CustomEvent('eventType').detail");

// Bubbles and cancelable true, details is missing.
shouldBe("new CustomEvent('eventType', { bubbles: true, cancelable: true }).bubbles", "true");
shouldBe("new CustomEvent('eventType', { bubbles: true, cancelable: true }).cancelable", "true");
shouldBeNull("new CustomEvent('eventType', { bubbles: true, cancelable: true }).detail");

// Detail is a number
shouldBe("new CustomEvent('eventType', { detail: 10 }).detail", "10");

// Detail is a string
shouldBe("new CustomEvent('eventType', { detail: \'string\' }).detail", "'string'");

// Detail is an object
var detailObject = { };
shouldBe("new CustomEvent('eventType', { detail: detailObject }).detail", "detailObject");

// Detail is a DOM object
shouldBe("new CustomEvent('eventType', { detail: document }).detail", "document");

// Detail is undefined.
shouldBeNull("new CustomEvent('eventType', { detail: undefined }).detail");

// Detail is null.
shouldBeNull("new CustomEvent('eventType', { detail: null }).detail");

// Detail is a getter.
shouldBe("new CustomEvent('eventType', { get detail() { return true; } }).detail", "true");

// Detail throws an exeception.
shouldThrow("new CustomEvent('eventType', { get detail() { throw 'Custom Error'; } })");

// try initCustomEvent
var event = document.createEvent('CustomEvent');
event.initCustomEvent('eventType', true, false, detailObject);
shouldBe("event.detail", "detailObject");

</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
