| OLD | NEW |
| (Empty) |
| 1 description("createElementNS tests from mozilla, attached to webkit bug 16833"); | |
| 2 | |
| 3 function assert(c, m) | |
| 4 { | |
| 5 if (!c) | |
| 6 testFailed(m); | |
| 7 else | |
| 8 testPassed(m); | |
| 9 } | |
| 10 | |
| 11 function stringForExceptionCode(c) | |
| 12 { | |
| 13 var exceptionName; | |
| 14 switch(c) { | |
| 15 case DOMException.INVALID_CHARACTER_ERR: | |
| 16 exceptionName = "INVALID_CHARACTER_ERR"; | |
| 17 break; | |
| 18 case DOMException.NAMESPACE_ERR: | |
| 19 exceptionName = "NAMESPACE_ERR"; | |
| 20 } | |
| 21 if (exceptionName) | |
| 22 return exceptionName; // + "(" + c + ")"; | |
| 23 return c; | |
| 24 } | |
| 25 | |
| 26 function assertExceptionCode(exception, expect, m) | |
| 27 { | |
| 28 var actual = exception.code; | |
| 29 if (actual !== expect) { | |
| 30 m += "; expected " + stringForExceptionCode(expect) + ", threw " + strin
gForExceptionCode(actual); | |
| 31 testFailed(m); | |
| 32 } else { | |
| 33 m += "; threw " + exception.toString(); | |
| 34 testPassed(m); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 var allNSTests = [ | |
| 39 { args: [undefined, undefined] }, | |
| 40 { args: [null, undefined] }, | |
| 41 { args: [undefined, null] }, | |
| 42 { args: [null, null] }, | |
| 43 { args: [null, ""], code: 5 }, | |
| 44 { args: ["", null] }, | |
| 45 { args: ["", ""], code: 5 }, | |
| 46 { args: [null, "<div>"], code: 5 }, | |
| 47 { args: [null, "0div"], code: 5 }, | |
| 48 { args: [null, "di v"], code: 5 }, | |
| 49 { args: [null, "di<v"], code: 5 }, | |
| 50 { args: [null, "-div"], code: 5 }, | |
| 51 { args: [null, ".div"], code: 5 }, | |
| 52 { args: ["http://example.com/", "<div>"], code: 5 }, | |
| 53 { args: ["http://example.com/", "0div"], code: 5 }, | |
| 54 { args: ["http://example.com/", "di<v"], code: 5 }, | |
| 55 { args: ["http://example.com/", "-div"], code: 5 }, | |
| 56 { args: ["http://example.com/", ".div"], code: 5 }, | |
| 57 { args: [null, ":div"], code: 14 }, | |
| 58 { args: [null, "div:"], code: 14 }, | |
| 59 { args: ["http://example.com/", ":div"], code: 14 }, | |
| 60 { args: ["http://example.com/", "div:"], code: 14 }, | |
| 61 { args: [null, "d:iv"], code: 14 }, | |
| 62 { args: [null, "a:b:c"], code: 14, message: "valid XML name, invalid QName" }
, | |
| 63 { args: ["http://example.com/", "a:b:c"], code: 14, message: "valid XML name,
invalid QName" }, | |
| 64 { args: [null, "a::c"], code: 14, message: "valid XML name, invalid QName" }, | |
| 65 { args: ["http://example.com/", "a::c"], code: 14, message: "valid XML name,
invalid QName" }, | |
| 66 { args: ["http://example.com/", "a:0"], code: 5, message: "valid XML name, no
t a valid QName" }, | |
| 67 { args: ["http://example.com/", "0:a"], code: 5, message: "0 at start makes i
t not a valid XML name" }, | |
| 68 { args: ["http://example.com/", "a:_"] }, | |
| 69 { args: ["http://example.com/", "a:\u0BC6"], code: 14, | |
| 70 message: "non-ASCII character after colon is CombiningChar, which is " + | |
| 71 "NCNameChar but not (Letter | \"_\") so invalid at start of " + | |
| 72 "NCName (but still a valid XML name, hence not INVALID_CHARACTER_E
RR)" }, | |
| 73 { args: ["http://example.com/", "\u0BC6:a"], code: 5, | |
| 74 message: "non-ASCII character after colon is CombiningChar, which is " + | |
| 75 "NCNameChar but not (Letter | \"_\") so invalid at start of " + | |
| 76 "NCName (Gecko chooses to throw NAMESPACE_ERR here, but either is
valid " + | |
| 77 "as this is both an invalid XML name and an invalid QName)" }, | |
| 78 { args: ["http://example.com/", "a:a\u0BC6"] }, | |
| 79 { args: ["http://example.com/", "a\u0BC6:a"] }, | |
| 80 { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml
prefix wrong" }, | |
| 81 { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xm
lns prefix wrong" }, | |
| 82 { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "bind
ing namespace namespace to wrong prefix" }, | |
| 83 { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] }, | |
| 84 { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] }, | |
| 85 { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] }, | |
| 86 ]; | |
| 87 | |
| 88 var allNoNSTests = [ | |
| 89 { args: [undefined] }, | |
| 90 { args: [null] }, | |
| 91 { args: [""], code: 5 }, | |
| 92 { args: ["<div>"], code: 5 }, | |
| 93 { args: ["0div"], code: 5 }, | |
| 94 { args: ["di v"], code: 5 }, | |
| 95 { args: ["di<v"], code: 5 }, | |
| 96 { args: ["-div"], code: 5 }, | |
| 97 { args: [".div"], code: 5 }, | |
| 98 { args: [":"], message: "valid XML name, invalid QName" }, | |
| 99 { args: [":div"], message: "valid XML name, invalid QName" }, | |
| 100 { args: ["div:"], message: "valid XML name, invalid QName" }, | |
| 101 { args: ["d:iv"] }, | |
| 102 { args: ["a:b:c"], message: "valid XML name, invalid QName" }, | |
| 103 { args: ["a::c"], message: "valid XML name, invalid QName" }, | |
| 104 { args: ["a::c:"], message: "valid XML name, invalid QName" }, | |
| 105 { args: ["a:0"], message: "valid XML name, not a valid QName" }, | |
| 106 { args: ["0:a"], code: 5, message: "0 at start makes it not a valid XML name"
}, | |
| 107 { args: ["a:_"] }, | |
| 108 { args: ["a:\u0BC6"], | |
| 109 message: "non-ASCII character after colon is CombiningChar, which is " + | |
| 110 "valid in pre-namespace XML" }, | |
| 111 { args: ["\u0BC6:a"], code: 5, message: "not a valid start character" }, | |
| 112 { args: ["a:a\u0BC6"] }, | |
| 113 { args: ["a\u0BC6:a"] }, | |
| 114 { args: ["xml:test"] }, | |
| 115 { args: ["xmlns:test"] }, | |
| 116 { args: ["x:test"] }, | |
| 117 { args: ["xmlns:test"] }, | |
| 118 { args: ["SOAP-ENV:Body"] }, // From Yahoo Mail Beta | |
| 119 ]; | |
| 120 | |
| 121 function sourceify(v) | |
| 122 { | |
| 123 switch (typeof v) { | |
| 124 case "undefined": | |
| 125 return v; | |
| 126 case "string": | |
| 127 return '"' + v.replace('"', '\\"') + '"'; | |
| 128 default: | |
| 129 return String(v); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 function sourceifyArgs(args) | |
| 134 { | |
| 135 var copy = new Array(args.length); | |
| 136 for (var i = 0, sz = args.length; i < sz; i++) | |
| 137 copy[i] = sourceify(args[i]); | |
| 138 | |
| 139 return copy.join(", "); | |
| 140 } | |
| 141 | |
| 142 function runNSTests(tests, doc, createFunctionName) | |
| 143 { | |
| 144 for (var i = 0, sz = tests.length; i < sz; i++) { | |
| 145 var test = tests[i]; | |
| 146 | |
| 147 var code = -1; | |
| 148 var argStr = sourceifyArgs(test.args); | |
| 149 var msg = createFunctionName + "(" + argStr + ")"; | |
| 150 if ("message" in test) | |
| 151 msg += "; " + test.message; | |
| 152 try { | |
| 153 doc[createFunctionName].apply(doc, test.args); | |
| 154 assert(!("code" in test), msg); | |
| 155 } catch (e) { | |
| 156 assertExceptionCode(e, test.code || "expected no exception", msg); | |
| 157 } | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 debug("HTML tests:") | |
| 162 runNSTests(allNSTests, document, "createElementNS"); | |
| 163 runNSTests(allNoNSTests, document, "createElement"); | |
| 164 | |
| 165 debug("XHTML createElement tests:") | |
| 166 var xhtmlDoc = document.implementation.createDocument("http://www.w3.org/1999/xh
tml", "html", null); | |
| 167 runNSTests(allNoNSTests, xhtmlDoc, "createElement"); | |
| 168 | |
| 169 debug("XML createElement tests:") | |
| 170 var xmlDoc = document.implementation.createDocument("http://www.example.com/foo"
, "example", null); | |
| 171 runNSTests(allNoNSTests, xmlDoc, "createElement"); | |
| OLD | NEW |