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

    (() => {
        description("This tests the constructor for the OverconstrainedErrorEvent DOM class.");

        if (!window.OverconstrainedErrorEvent) {
            testFailed('window.OverconstrainedErrorEvent not defined!');
            finishJSTest();
            return;
        } 

        // No initializer is passed.
        shouldBe("new OverconstrainedErrorEvent('eventType').bubbles", "false");
        shouldBe("new OverconstrainedErrorEvent('eventType').cancelable", "false");
        shouldBeNull("new OverconstrainedErrorEvent('eventType').error", null);

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

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

        // error is passed.
        shouldBeEqualToString("new OverconstrainedErrorEvent('eventType', { error: new OverconstrainedError() }).error.constraint", "");
        shouldBeEqualToString("new OverconstrainedErrorEvent('eventType', { error: new OverconstrainedError() }).error.message", "");
        shouldBeEqualToString("new OverconstrainedErrorEvent('eventType', { error: new OverconstrainedError('width') }).error.constraint", "width");
        shouldBeEqualToString("new OverconstrainedErrorEvent('eventType', { error: new OverconstrainedError('fred', 'unsupported constraint') }).error.message", "unsupported constraint");

        shouldBeUndefined("new OverconstrainedErrorEvent('eventType', { error: null }).reason");
        shouldThrowErrorName("new OverconstrainedErrorEvent('eventType', { error: 'fake error' })", "TypeError");
        shouldThrowErrorName("new OverconstrainedErrorEvent('eventType', { error: [] })", "TypeError");

        // All initializers are passed.
        shouldBe("new OverconstrainedErrorEvent('eventType', { bubbles: true, cancelable: true, error: new OverconstrainedError() }).bubbles", "true");
        shouldBe("new OverconstrainedErrorEvent('eventType', { bubbles: true, cancelable: true, error: new OverconstrainedError() }).cancelable", "true");
        shouldBeEqualToString("new OverconstrainedErrorEvent('eventType', { bubbles: true, cancelable: true, error: new OverconstrainedError('bogus') }).error.constraint", "bogus");
    })();

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