| OLD | NEW |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <script src="script-tests/setAttributeNS-namespace-err.js"></script> | 7 <script> |
| 8 description("setAttributeNS tests adapted from createAttributeNS which in turn w
ere adapted from createElementNS tests attached to webkit bug 16833"); |
| 9 |
| 10 function assert(c, m) |
| 11 { |
| 12 if (!c) |
| 13 testFailed(m); |
| 14 else |
| 15 testPassed(m); |
| 16 } |
| 17 |
| 18 function stringForExceptionCode(c) |
| 19 { |
| 20 var exceptionName; |
| 21 switch(c) { |
| 22 case DOMException.INVALID_CHARACTER_ERR: |
| 23 exceptionName = "INVALID_CHARACTER_ERR"; |
| 24 break; |
| 25 case DOMException.NAMESPACE_ERR: |
| 26 exceptionName = "NAMESPACE_ERR"; |
| 27 } |
| 28 if (exceptionName) |
| 29 return exceptionName; // + "(" + c + ")"; |
| 30 return c; |
| 31 } |
| 32 |
| 33 function assertEquals(actual, expect, m) |
| 34 { |
| 35 if (actual !== expect) { |
| 36 m += "; expected " + stringForExceptionCode(expect) + ", threw " + strin
gForExceptionCode(actual); |
| 37 testFailed(m); |
| 38 } else { |
| 39 m += "; threw " + stringForExceptionCode(actual);; |
| 40 testPassed(m); |
| 41 } |
| 42 } |
| 43 |
| 44 var allNSTests = [ |
| 45 { args: [undefined, undefined] }, |
| 46 { args: [null, undefined] }, |
| 47 { args: [undefined, null], code: 5 }, |
| 48 { args: [null, null], code: 5 }, |
| 49 { args: [null, ""], code: 5 }, |
| 50 { args: ["", null], code: 5 }, |
| 51 { args: ["", ""], code: 5 }, |
| 52 { args: [null, "<div>"], code: 5 }, |
| 53 { args: [null, "0div"], code: 5 }, |
| 54 { args: [null, "di v"], code: 5 }, |
| 55 { args: [null, "di<v"], code: 5 }, |
| 56 { args: [null, "-div"], code: 5 }, |
| 57 { args: [null, ".div"], code: 5 }, |
| 58 { args: ["http://example.com/", "<div>"], code: 5 }, |
| 59 { args: ["http://example.com/", "0div"], code: 5 }, |
| 60 { args: ["http://example.com/", "di<v"], code: 5 }, |
| 61 { args: ["http://example.com/", "-div"], code: 5 }, |
| 62 { args: ["http://example.com/", ".div"], code: 5 }, |
| 63 { args: [null, ":div"], code: 14 }, |
| 64 { args: [null, "div:"], code: 14 }, |
| 65 { args: ["http://example.com/", ":div"], code: 14 }, |
| 66 { args: ["http://example.com/", "div:"], code: 14 }, |
| 67 { args: [null, "d:iv"], code: 14 }, |
| 68 { args: [null, "a:b:c"], code: 14, message: "valid XML name, invalid QName" }
, |
| 69 { args: ["http://example.com/", "a:b:c"], code: 14, message: "valid XML name,
invalid QName" }, |
| 70 { args: [null, "a::c"], code: 14, message: "valid XML name, invalid QName" }, |
| 71 { args: ["http://example.com/", "a::c"], code: 14, message: "valid XML name,
invalid QName" }, |
| 72 { args: ["http://example.com/", "a:0"], code: 5, message: "valid XML name, no
t a valid QName" }, |
| 73 { args: ["http://example.com/", "0:a"], code: 5, message: "0 at start makes i
t not a valid XML name" }, |
| 74 { args: ["http://example.com/", "a:_"] }, |
| 75 { args: ["http://example.com/", "a:\u0BC6"], code: 14, |
| 76 message: "non-ASCII character after colon is CombiningChar, which is " + |
| 77 "NCNameChar but not (Letter | \"_\") so invalid at start of " + |
| 78 "NCName (but still a valid XML name, hence not INVALID_CHARACTER_E
RR)" }, |
| 79 { args: ["http://example.com/", "\u0BC6:a"], code: 5, |
| 80 message: "non-ASCII character after colon is CombiningChar, which is " + |
| 81 "NCNameChar but not (Letter | \"_\") so invalid at start of " + |
| 82 "NCName (Gecko chooses to throw NAMESPACE_ERR here, but either is
valid " + |
| 83 "as this is both an invalid XML name and an invalid QName)" }, |
| 84 { args: ["http://example.com/", "a:a\u0BC6"] }, |
| 85 { args: ["http://example.com/", "a\u0BC6:a"] }, |
| 86 { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml
prefix wrong" }, |
| 87 { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xm
lns prefix wrong" }, |
| 88 { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "bind
ing namespace namespace to wrong prefix" }, |
| 89 { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] }, |
| 90 { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] }, |
| 91 { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] }, |
| 92 { args: ["http://www.w3.org/2000/xmlns/", "xmlns"] }, // See http://www.w3.or
g/2000/xmlns/ |
| 93 { args: ["http://example.com/", "xmlns"], code: 14 }, // from the createAttri
buteNS section |
| 94 ]; |
| 95 |
| 96 function sourceify(v) |
| 97 { |
| 98 switch (typeof v) { |
| 99 case "undefined": |
| 100 return v; |
| 101 |
| 102 case "string": |
| 103 return '"' + v.replace('"', '\\"') + '"'; |
| 104 |
| 105 default: |
| 106 return String(v); |
| 107 } |
| 108 } |
| 109 |
| 110 function runNSTests() |
| 111 { |
| 112 var element = document.createElement("div"); |
| 113 var setFunction = element.setAttributeNS; |
| 114 var setFunctionName = "element.setAttributeNS"; |
| 115 var value = "'value'"; |
| 116 |
| 117 for (var i = 0, sz = allNSTests.length; i < sz; i++) { |
| 118 var test = allNSTests[i]; |
| 119 |
| 120 var code = -1; |
| 121 var argStr = sourceify(test.args[0]) + ", " + sourceify(test.args[1]) +
", " + value; |
| 122 var msg = setFunctionName + "(" + argStr + ")"; |
| 123 if ("message" in test) |
| 124 msg += "; " + test.message; |
| 125 try { |
| 126 setFunction.apply(element, test.args.concat([value])); |
| 127 assert(!("code" in test), msg); |
| 128 } catch (e) { |
| 129 assertEquals(e.code, test.code || "expected no exception", msg); |
| 130 } |
| 131 } |
| 132 } |
| 133 |
| 134 runNSTests(); |
| 135 </script> |
| 8 </body> | 136 </body> |
| 9 </html> | 137 </html> |
| OLD | NEW |