Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: LayoutTests/fast/dom/Document/script-tests/createAttributeNS-namespace-err.js

Issue 740223003: Revive tests for Document.createAttributeNS() and Element.setAttributeNodeNS() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: deprecation messages Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 description("createDocument tests modeled after createElementNS tests from mozil la which were attached to webkit bug 16833"); 1 description("createAttirbuteNS tests 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 {
19 var exceptionName; 13 var exceptionName;
20 switch(c) { 14 switch(c) {
21 case DOMException.INVALID_CHARACTER_ERR: 15 case DOMException.INVALID_CHARACTER_ERR:
22 exceptionName = "INVALID_CHARACTER_ERR"; 16 exceptionName = "INVALID_CHARACTER_ERR";
23 break; 17 break;
24 case DOMException.NAMESPACE_ERR: 18 case DOMException.NAMESPACE_ERR:
25 exceptionName = "NAMESPACE_ERR"; 19 exceptionName = "NAMESPACE_ERR";
26 } 20 }
27 if (exceptionName) 21 if (exceptionName)
28 return exceptionName; // + "(" + c + ")"; 22 return exceptionName; // + "(" + c + ")";
29 return c; 23 return c;
30 } 24 }
31 25
32 function assertEquals(actual, expect, m) 26 function assertExceptionCode(exception, expect, m)
33 { 27 {
28 var actual = exception.code;
34 if (actual !== expect) { 29 if (actual !== expect) {
35 m += "; expected " + stringForExceptionCode(expect) + ", threw " + strin gForExceptionCode(actual); 30 m += "; expected " + stringForExceptionCode(expect) + ", threw " + strin gForExceptionCode(actual);
36 testFailed(m); 31 testFailed(m);
37 } else { 32 } else {
38 m += "; threw " + stringForExceptionCode(actual);; 33 m += "; threw " + exception.toString();
39 testPassed(m); 34 testPassed(m);
40 } 35 }
41 } 36 }
42 37
43 var allNSTests = [ 38 var allNSTests = [
44 { args: [undefined, undefined] }, 39 { args: [undefined, undefined] },
45 { args: [null, undefined] }, 40 { args: [null, undefined] },
46 { args: [undefined, null], code: 5 }, 41 { args: [undefined, null], code: 5 },
47 { args: [null, null], code: 5 }, 42 { args: [null, null], code: 5 },
48 { args: [null, ""], code: 5 }, 43 { args: [null, ""], code: 5 },
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 "NCName (Gecko chooses to throw NAMESPACE_ERR here, but either is valid " + 76 "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)" }, 77 "as this is both an invalid XML name and an invalid QName)" },
83 { args: ["http://example.com/", "a:a\u0BC6"] }, 78 { args: ["http://example.com/", "a:a\u0BC6"] },
84 { args: ["http://example.com/", "a\u0BC6:a"] }, 79 { args: ["http://example.com/", "a\u0BC6:a"] },
85 { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml prefix wrong" }, 80 { 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" }, 81 { 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" }, 82 { 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"] }, 83 { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] },
89 { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] }, 84 { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] },
90 { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] }, 85 { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] },
86 { args: ["http://www.w3.org/2000/xmlns/", "xmlns"] }, // See http://www.w3.or g/2000/xmlns/
87 { args: ["http://example.com/", "xmlns"], code: 14 }, // from the createAttri buteNS section
91 ]; 88 ];
92 89
93 function sourceify(v) 90 function sourceify(v)
94 { 91 {
95 switch (typeof v) { 92 switch (typeof v) {
96 case "undefined": 93 case "undefined":
97 return v; 94 return v;
98 case "string": 95
99 return '"' + v.replace('"', '\\"') + '"'; 96 case "string":
100 default: 97 return '"' + v.replace('"', '\\"') + '"';
101 return String(v); 98
99 default:
100 return String(v);
102 } 101 }
103 } 102 }
104 103
105 function sourceifyArgs(args) 104 function runNSTests()
106 { 105 {
107 var copy = new Array(args.length); 106 var createFunction = document.createAttributeNS;
108 for (var i = 0, sz = args.length; i < sz; i++) 107 var createFunctionName = "createAttributeNS";
109 copy[i] = sourceify(args[i]); 108 var doc = document;
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]);
128 var msg = createFunctionName + "(" + argStr + ")"; 115 var msg = createFunctionName + "(" + 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 createFunction.apply(doc, test.args);
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 assertExceptionCode(e, 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 // Moz throws a "Not enough arguments" exception in these, we don't:
141 shouldThrow("document.implementation.createDocument(\"http://www.example.com\")" , '"TypeError: Failed to execute \'createDocument\' on \'DOMImplementation\': 2 arguments required, but only 1 present."'); 128 shouldBeEqualToString("document.createAttributeNS().toString()", "[object Attr]" );
129 shouldBeEqualToString("document.createAttributeNS(\"http://www.example.com\").to String()", "[object Attr]");
142 130
143 runNSTests(allNSTests, document.implementation, "createDocument"); 131 runNSTests();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698