Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / DOMException / constructor.html
blob19c65017b8f273221386ede5cf32a0e671ac9466
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>DOMException constructor</title>
5 <script src="../../../resources/testharness.js"></script>
6 <script src="../../../resources/testharnessreport.js"></script>
7 <link rel="stylesheet" href="../../../resources/testharness.css">
8 </head>
9 <body>
10 <script>
11 test(function() {
12 var ex = new DOMException();
13 assert_equals(ex.name, 'Error', 'Default name should be "Error"');
14 assert_equals(ex.message, '', 'Default message should be ""');
15 assert_equals(ex.code, 0, 'Default code should be 0');
16 }, 'new DOMException()');
18 test(function() {
19 var ex = new DOMException(null);
20 assert_equals(ex.name, 'Error', 'Default name should be "Error"');
21 assert_equals(ex.message, 'null', 'Passing null as message should be stringified to "null"');
22 assert_equals(ex.code, 0, 'Default code should be 0');
23 }, 'new DOMException(null)');
25 test(function() {
26 var ex = new DOMException(undefined);
27 assert_equals(ex.name, 'Error', 'Default name should be "Error"');
28 assert_equals(ex.message, '', 'Passing undefined as message should give default ""');
29 assert_equals(ex.code, 0, 'Default code should be 0');
30 }, 'new DOMException(undefined)');
32 test(function() {
33 var ex = new DOMException('example');
34 assert_equals(ex.name, 'Error', 'Default name should be "Error"');
35 assert_equals(ex.message, 'example', 'Passed string as message should be used');
36 assert_equals(ex.code, 0, 'Default code should be 0');
37 }, 'new DOMException(string)');
39 test(function() {
40 var ex = new DOMException('example', undefined);
41 assert_equals(ex.name, 'Error', 'Passing undefined as name should give default "Error"');
42 assert_equals(ex.message, 'example', 'Passed string as message should be used');
43 assert_equals(ex.code, 0, 'Default code should be 0');
44 }, 'new DOMException(string, undefined)');
46 test(function() {
47 var ex = new DOMException('example', null);
48 assert_equals(ex.name, 'null', 'Passing null as name should be stringified to "null"');
49 assert_equals(ex.message, 'example', 'Passed string as message should be used');
50 assert_equals(ex.code, 0, 'Default code should be 0');
51 }, 'new DOMException(string, null)');
53 test(function() {
54 var ex = new DOMException('example', 'bar');
55 assert_equals(ex.name, 'bar', 'Passed string as name should be used');
56 assert_equals(ex.message, 'example', 'Passed string as message should be used');
57 assert_equals(ex.code, 0, 'Default code should be 0');
58 }, 'new DOMException(string, string)');
61 {name: "IndexSizeError", code: 1},
62 {name: "HierarchyRequestError", code: 3},
63 {name: "WrongDocumentError", code: 4},
64 {name: "InvalidCharacterError", code: 5},
65 {name: "NoModificationAllowedError", code: 7},
66 {name: "NotFoundError", code: 8},
67 {name: "NotSupportedError", code: 9},
68 {name: "InUseAttributeError", code: 10},
69 {name: "InvalidStateError", code: 11},
70 {name: "SyntaxError", code: 12},
71 {name: "InvalidModificationError", code: 13},
72 {name: "NamespaceError", code: 14},
73 {name: "InvalidAccessError", code: 15},
74 {name: "SecurityError", code: 18},
75 {name: "NetworkError", code: 19},
76 {name: "AbortError", code: 20},
77 {name: "URLMismatchError", code: 21},
78 {name: "QuotaExceededError", code: 22},
79 {name: "TimeoutError", code: 23},
80 {name: "InvalidNodeTypeError", code: 24},
81 {name: "DataCloneError", code: 25}
82 ].forEach(function(test_case) {
83 test(function() {
84 var ex = new DOMException('example', test_case.name);
85 assert_equals(ex.name, test_case.name, 'Passed string as name should be used');
86 assert_equals(ex.message, 'example', 'Passed string as message should be used');
87 assert_equals(ex.code, test_case.code, 'Legacy code should be used for matching name');
88 }, 'Legacy code matching: new DOMException(string, "' + test_case.name + '")');
89 });
91 </script>
92 </body>
93 </html>