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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err.html

Issue 2667393002: Stop using script-tests in fast/dom/. (Closed)
Patch Set: . Created 3 years, 10 months 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
OLDNEW
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/createDocument-namespace-err.js"></script> 7 <script>
8 description("createDocument tests modelled after createElementNS tests from mozi lla which were attached to webkit bug 16833");
9
10 // document.implementation.createDocument() should throw the same set of errors
11 // as document.createElementNS()
12 // http://www.w3.org/TR/DOM-Level-3-Core/core.html#Level-2-Core-DOM-createDocume nt
13 // Thus we copied these test cases from:
14 // LayoutTests/fast/dom/Document/resources/createDocument-namespace-err.js
15
16 function assert(c, m)
17 {
18 if (!c)
19 testFailed(m);
20 else
21 testPassed(m);
22 }
23
24 function stringForExceptionCode(c)
25 {
26 var exceptionName;
27 switch(c) {
28 case DOMException.INVALID_CHARACTER_ERR:
29 exceptionName = "INVALID_CHARACTER_ERR";
30 break;
31 case DOMException.NAMESPACE_ERR:
32 exceptionName = "NAMESPACE_ERR";
33 }
34 if (exceptionName)
35 return exceptionName; // + "(" + c + ")";
36 return c;
37 }
38
39 function assertEquals(actual, expect, m)
40 {
41 if (actual !== expect) {
42 m += "; expected " + stringForExceptionCode(expect) + ", threw " + strin gForExceptionCode(actual);
43 testFailed(m);
44 } else {
45 m += "; threw " + stringForExceptionCode(actual);;
46 testPassed(m);
47 }
48 }
49
50 var allNSTests = [
51 { args: [undefined, undefined] },
52 { args: [null, undefined] },
53 { args: [undefined, null], code: 5 },
54 { args: [null, null], code: 5 },
55 { args: [null, ""], code: 5 },
56 { args: ["", null], code: 5 },
57 { args: ["", ""], code: 5 },
58 { args: [null, "<div>"], code: 5 },
59 { args: [null, "0div"], code: 5 },
60 { args: [null, "di v"], code: 5 },
61 { args: [null, "di<v"], code: 5 },
62 { args: [null, "-div"], code: 5 },
63 { args: [null, ".div"], code: 5 },
64 { args: ["http://example.com/", "<div>"], code: 5 },
65 { args: ["http://example.com/", "0div"], code: 5 },
66 { args: ["http://example.com/", "di<v"], code: 5 },
67 { args: ["http://example.com/", "-div"], code: 5 },
68 { args: ["http://example.com/", ".div"], code: 5 },
69 { args: [null, ":div"], code: 14 },
70 { args: [null, "div:"], code: 14 },
71 { args: ["http://example.com/", ":div"], code: 14 },
72 { args: ["http://example.com/", "div:"], code: 14 },
73 { args: [null, "d:iv"], code: 14 },
74 { args: [null, "a:b:c"], code: 14, message: "valid XML name, invalid QName" } ,
75 { args: ["http://example.com/", "a:b:c"], code: 14, message: "valid XML name, invalid QName" },
76 { args: [null, "a::c"], code: 14, message: "valid XML name, invalid QName" },
77 { args: ["http://example.com/", "a::c"], code: 14, message: "valid XML name, invalid QName" },
78 { args: ["http://example.com/", "a:0"], code: 5, message: "valid XML name, no t a valid QName" },
79 { args: ["http://example.com/", "0:a"], code: 5, message: "0 at start makes i t not a valid XML name" },
80 { args: ["http://example.com/", "a:_"] },
81 { args: ["http://example.com/", "a:\u0BC6"], code: 14,
82 message: "non-ASCII character after colon is CombiningChar, which is " +
83 "NCNameChar but not (Letter | \"_\") so invalid at start of " +
84 "NCName (but still a valid XML name, hence not INVALID_CHARACTER_E RR)" },
85 { args: ["http://example.com/", "\u0BC6:a"], code: 5,
86 message: "non-ASCII character after colon is CombiningChar, which is " +
87 "NCNameChar but not (Letter | \"_\") so invalid at start of " +
88 "NCName (Gecko chooses to throw NAMESPACE_ERR here, but either is valid " +
89 "as this is both an invalid XML name and an invalid QName)" },
90 { args: ["http://example.com/", "a:a\u0BC6"] },
91 { args: ["http://example.com/", "a\u0BC6:a"] },
92 { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml prefix wrong" },
93 { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xm lns prefix wrong" },
94 { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "bind ing namespace namespace to wrong prefix" },
95 { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] },
96 { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] },
97 { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] },
98 ];
99
100 function sourceify(v)
101 {
102 switch (typeof v) {
103 case "undefined":
104 return v;
105 case "string":
106 return '"' + v.replace('"', '\\"') + '"';
107 default:
108 return String(v);
109 }
110 }
111
112 function sourceifyArgs(args)
113 {
114 var copy = new Array(args.length);
115 for (var i = 0, sz = args.length; i < sz; i++)
116 copy[i] = sourceify(args[i]);
117
118 return copy.join(", ");
119 }
120
121 function runNSTests(tests, doc, createFunctionName)
122 {
123 for (var i = 0, sz = tests.length; i < sz; i++) {
124 var test = tests[i];
125
126 // Gecko throws "undefined" if createDocument isn't
127 // called with 3 arguments. Instead of modifying all
128 // of the values in the arrays above (which were taken from createElemen tNS tests)
129 // we will instead just hack the args list here.
130 var argsWithExtraLastNull = test.args.slice(); // copy the args arary
131 argsWithExtraLastNull.push(null);
132
133 var code = -1;
134 var argStr = sourceifyArgs(argsWithExtraLastNull);
135 var msg = createFunctionName + "(" + argStr + ")";
136 if ("message" in test)
137 msg += "; " + test.message;
138 try {
139 doc[createFunctionName].apply(doc, argsWithExtraLastNull);
140 assert(!("code" in test), msg);
141 } catch (e) {
142 assertEquals(e.code, test.code || "expected no exception", msg);
143 }
144 }
145 }
146
147 shouldThrow("document.implementation.createDocument()", '"TypeError: Failed to e xecute \'createDocument\' on \'DOMImplementation\': 2 arguments required, but on ly 0 present."');
148 shouldThrow("document.implementation.createDocument(\"http://www.example.com\")" , '"TypeError: Failed to execute \'createDocument\' on \'DOMImplementation\': 2 arguments required, but only 1 present."');
149
150 runNSTests(allNSTests, document.implementation, "createDocument");
151 </script>
8 </body> 152 </body>
9 </html> 153 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698