| OLD | NEW |
| 1 description("createDocument tests modeled after createElementNS tests from mozil
la which were attached to webkit bug 16833"); | 1 description("setAttributeNS tests adapted from createAttributeNS which in turn w
ere adapted from createElementNS tests attached to webkit bug 16833"); |
| 2 | 2 |
| 3 // document.implementation.createDocument() should throw the same set of errors | |
| 4 // as document.createElementNS() | |
| 5 // http://www.w3.org/TR/DOM-Level-3-Core/core.html#Level-2-Core-DOM-createDocume
nt | |
| 6 // Thus we copied these test cases from: | |
| 7 // LayoutTests/fast/dom/Document/resources/createDocument-namespace-err.js | |
| 8 | |
| 9 function assert(c, m) | 3 function assert(c, m) |
| 10 { | 4 { |
| 11 if (!c) | 5 if (!c) |
| 12 testFailed(m); | 6 testFailed(m); |
| 13 else | 7 else |
| 14 testPassed(m); | 8 testPassed(m); |
| 15 } | 9 } |
| 16 | 10 |
| 17 function stringForExceptionCode(c) | 11 function stringForExceptionCode(c) |
| 18 { | 12 { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 "NCName (Gecko chooses to throw NAMESPACE_ERR here, but either is
valid " + | 75 "NCName (Gecko chooses to throw NAMESPACE_ERR here, but either is
valid " + |
| 82 "as this is both an invalid XML name and an invalid QName)" }, | 76 "as this is both an invalid XML name and an invalid QName)" }, |
| 83 { args: ["http://example.com/", "a:a\u0BC6"] }, | 77 { args: ["http://example.com/", "a:a\u0BC6"] }, |
| 84 { args: ["http://example.com/", "a\u0BC6:a"] }, | 78 { args: ["http://example.com/", "a\u0BC6:a"] }, |
| 85 { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml
prefix wrong" }, | 79 { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml
prefix wrong" }, |
| 86 { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xm
lns prefix wrong" }, | 80 { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xm
lns prefix wrong" }, |
| 87 { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "bind
ing namespace namespace to wrong prefix" }, | 81 { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "bind
ing namespace namespace to wrong prefix" }, |
| 88 { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] }, | 82 { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] }, |
| 89 { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] }, | 83 { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] }, |
| 90 { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] }, | 84 { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] }, |
| 85 { args: ["http://www.w3.org/2000/xmlns/", "xmlns"] }, // See http://www.w3.or
g/2000/xmlns/ |
| 86 { args: ["http://example.com/", "xmlns"], code: 14 }, // from the createAttri
buteNS section |
| 91 ]; | 87 ]; |
| 92 | 88 |
| 93 function sourceify(v) | 89 function sourceify(v) |
| 94 { | 90 { |
| 95 switch (typeof v) { | 91 switch (typeof v) { |
| 96 case "undefined": | 92 case "undefined": |
| 97 return v; | 93 return v; |
| 98 case "string": | 94 |
| 99 return '"' + v.replace('"', '\\"') + '"'; | 95 case "string": |
| 100 default: | 96 return '"' + v.replace('"', '\\"') + '"'; |
| 101 return String(v); | 97 |
| 98 default: |
| 99 return String(v); |
| 102 } | 100 } |
| 103 } | 101 } |
| 104 | 102 |
| 105 function sourceifyArgs(args) | 103 function runNSTests() |
| 106 { | 104 { |
| 107 var copy = new Array(args.length); | 105 var element = document.createElement("div"); |
| 108 for (var i = 0, sz = args.length; i < sz; i++) | 106 var setFunction = element.setAttributeNS; |
| 109 copy[i] = sourceify(args[i]); | 107 var setFunctionName = "element.setAttributeNS"; |
| 108 var value = "'value'"; |
| 110 | 109 |
| 111 return copy.join(", "); | 110 for (var i = 0, sz = allNSTests.length; i < sz; i++) { |
| 112 } | 111 var test = allNSTests[i]; |
| 113 | |
| 114 function runNSTests(tests, doc, createFunctionName) | |
| 115 { | |
| 116 for (var i = 0, sz = tests.length; i < sz; i++) { | |
| 117 var test = tests[i]; | |
| 118 | |
| 119 // Gecko throws "undefined" if createDocument isn't | |
| 120 // called with 3 arguments. Instead of modifying all | |
| 121 // of the values in the arrays above (which were taken from createElemen
tNS tests) | |
| 122 // we will instead just hack the args list here. | |
| 123 var argsWithExtraLastNull = test.args.slice(); // copy the args arary | |
| 124 argsWithExtraLastNull.push(null); | |
| 125 | 112 |
| 126 var code = -1; | 113 var code = -1; |
| 127 var argStr = sourceifyArgs(argsWithExtraLastNull); | 114 var argStr = sourceify(test.args[0]) + ", " + sourceify(test.args[1]) +
", " + value; |
| 128 var msg = createFunctionName + "(" + argStr + ")"; | 115 var msg = setFunctionName + "(" + argStr + ")"; |
| 129 if ("message" in test) | 116 if ("message" in test) |
| 130 msg += "; " + test.message; | 117 msg += "; " + test.message; |
| 131 try { | 118 try { |
| 132 doc[createFunctionName].apply(doc, argsWithExtraLastNull); | 119 setFunction.apply(element, test.args.concat([value])); |
| 133 assert(!("code" in test), msg); | 120 assert(!("code" in test), msg); |
| 134 } catch (e) { | 121 } catch (e) { |
| 135 assertEquals(e.code, test.code || "expected no exception", msg); | 122 assertEquals(e.code, test.code || "expected no exception", msg); |
| 136 } | 123 } |
| 137 } | 124 } |
| 138 } | 125 } |
| 139 | 126 |
| 140 shouldThrow("document.implementation.createDocument()", '"TypeError: Failed to e
xecute \'createDocument\' on \'DOMImplementation\': 2 arguments required, but on
ly 0 present."'); | 127 runNSTests(); |
| 141 shouldThrow("document.implementation.createDocument(\"http://www.example.com\")"
, '"TypeError: Failed to execute \'createDocument\' on \'DOMImplementation\': 2
arguments required, but only 1 present."'); | |
| 142 | |
| 143 runNSTests(allNSTests, document.implementation, "createDocument"); | |
| OLD | NEW |