chromium/third_party/blink/web_tests/fast/dom/DOMException/constructor.html

<!DOCTYPE html>
<html>
<head>
<title>DOMException constructor</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<link rel="stylesheet" href="../../../resources/testharness.css">
</head>
<body>
<script>
test(function() {
    var ex = new DOMException();
    assert_equals(ex.name, 'Error', 'Default name should be "Error"');
    assert_equals(ex.message, '', 'Default message should be ""');
    assert_equals(ex.code, 0, 'Default code should be 0');
}, 'new DOMException()');

test(function() {
    var ex = new DOMException(null);
    assert_equals(ex.name, 'Error', 'Default name should be "Error"');
    assert_equals(ex.message, 'null', 'Passing null as message should be stringified to "null"');
    assert_equals(ex.code, 0, 'Default code should be 0');
}, 'new DOMException(null)');

test(function() {
    var ex = new DOMException(undefined);
    assert_equals(ex.name, 'Error', 'Default name should be "Error"');
    assert_equals(ex.message, '', 'Passing undefined as message should give default ""');
    assert_equals(ex.code, 0, 'Default code should be 0');
}, 'new DOMException(undefined)');

test(function() {
    var ex = new DOMException('example');
    assert_equals(ex.name, 'Error', 'Default name should be "Error"');
    assert_equals(ex.message, 'example', 'Passed string as message should be used');
    assert_equals(ex.code, 0, 'Default code should be 0');
}, 'new DOMException(string)');

test(function() {
    var ex = new DOMException('example', undefined);
    assert_equals(ex.name, 'Error', 'Passing undefined as name should give default "Error"');
    assert_equals(ex.message, 'example', 'Passed string as message should be used');
    assert_equals(ex.code, 0, 'Default code should be 0');
}, 'new DOMException(string, undefined)');

test(function() {
    var ex = new DOMException('example', null);
    assert_equals(ex.name, 'null', 'Passing null as name should be stringified to "null"');
    assert_equals(ex.message, 'example', 'Passed string as message should be used');
    assert_equals(ex.code, 0, 'Default code should be 0');
}, 'new DOMException(string, null)');

test(function() {
    var ex = new DOMException('example', 'bar');
    assert_equals(ex.name, 'bar', 'Passed string as name should be used');
    assert_equals(ex.message, 'example', 'Passed string as message should be used');
    assert_equals(ex.code, 0, 'Default code should be 0');
}, 'new DOMException(string, string)');

[
    {name: "IndexSizeError", code: 1},
    {name: "HierarchyRequestError", code: 3},
    {name: "WrongDocumentError", code: 4},
    {name: "InvalidCharacterError", code: 5},
    {name: "NoModificationAllowedError", code: 7},
    {name: "NotFoundError", code: 8},
    {name: "NotSupportedError", code: 9},
    {name: "InUseAttributeError", code: 10},
    {name: "InvalidStateError", code: 11},
    {name: "SyntaxError", code: 12},
    {name: "InvalidModificationError", code: 13},
    {name: "NamespaceError", code: 14},
    {name: "InvalidAccessError", code: 15},
    {name: "SecurityError", code: 18},
    {name: "NetworkError", code: 19},
    {name: "AbortError", code: 20},
    {name: "URLMismatchError", code: 21},
    {name: "QuotaExceededError", code: 22},
    {name: "TimeoutError", code: 23},
    {name: "InvalidNodeTypeError", code: 24},
    {name: "DataCloneError", code: 25}
].forEach(function(test_case) {
    test(function() {
        var ex = new DOMException('example', test_case.name);
        assert_equals(ex.name, test_case.name, 'Passed string as name should be used');
        assert_equals(ex.message, 'example', 'Passed string as message should be used');
        assert_equals(ex.code, test_case.code, 'Legacy code should be used for matching name');
    }, 'Legacy code matching: new DOMException(string, "' + test_case.name + '")');
});

</script>
</body>
</html>