summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/dom/DOMImplementation
diff options
context:
space:
mode:
Diffstat (limited to 'LayoutTests/fast/dom/DOMImplementation')
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err-expected.txt51
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err.html13
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/createDocument-with-used-doctype-expected.txt1
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/createDocument-with-used-doctype.html32
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/createDocumentType-err-expected.txt31
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/createDocumentType-err.html13
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/createHTMLDocument-title-expected.txt5
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/createHTMLDocument-title.html9
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/detached-doctype-expected.txt5
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/detached-doctype.html29
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/resources/createDocument-with-used-doctype-frame.html17
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/script-tests/TEMPLATE.html13
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/script-tests/createDocument-namespace-err.js146
-rw-r--r--LayoutTests/fast/dom/DOMImplementation/script-tests/createDocumentType-err.js100
14 files changed, 465 insertions, 0 deletions
diff --git a/LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err-expected.txt b/LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err-expected.txt
new file mode 100644
index 0000000..09d4bdc
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err-expected.txt
@@ -0,0 +1,51 @@
+createDocument tests modeled after createElementNS tests from mozilla which were attached to webkit bug 16833
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.implementation.createDocument().toString() is "[object Document]"
+PASS document.implementation.createDocument("http://www.example.com").toString() is "[object Document]"
+PASS createDocument(, , null)
+PASS createDocument(null, , null)
+FAIL createDocument(, null, null)
+FAIL createDocument(null, null, null)
+FAIL createDocument(null, "", null)
+FAIL createDocument("", null, null)
+FAIL createDocument("", "", null)
+PASS createDocument(null, "<div>", null); threw INVALID_CHARACTER_ERR
+PASS createDocument(null, "0div", null); threw INVALID_CHARACTER_ERR
+PASS createDocument(null, "di v", null); threw INVALID_CHARACTER_ERR
+PASS createDocument(null, "di<v", null); threw INVALID_CHARACTER_ERR
+PASS createDocument(null, "-div", null); threw INVALID_CHARACTER_ERR
+PASS createDocument(null, ".div", null); threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", "<div>", null); threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", "0div", null); threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", "di<v", null); threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", "-div", null); threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", ".div", null); threw INVALID_CHARACTER_ERR
+PASS createDocument(null, ":div", null); threw NAMESPACE_ERR
+PASS createDocument(null, "div:", null); threw NAMESPACE_ERR
+PASS createDocument("http://example.com/", ":div", null); threw NAMESPACE_ERR
+PASS createDocument("http://example.com/", "div:", null); threw NAMESPACE_ERR
+PASS createDocument(null, "d:iv", null); threw NAMESPACE_ERR
+PASS createDocument(null, "a:b:c", null); valid XML name, invalid QName; threw NAMESPACE_ERR
+PASS createDocument("http://example.com/", "a:b:c", null); valid XML name, invalid QName; threw NAMESPACE_ERR
+PASS createDocument(null, "a::c", null); valid XML name, invalid QName; threw NAMESPACE_ERR
+PASS createDocument("http://example.com/", "a::c", null); valid XML name, invalid QName; threw NAMESPACE_ERR
+PASS createDocument("http://example.com/", "a:0", null); valid XML name, not a valid QName; threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", "0:a", null); 0 at start makes it not a valid XML name; threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", "a:_", null)
+FAIL createDocument("http://example.com/", "a:ெ", null); non-ASCII character after colon is CombiningChar, which is NCNameChar but not (Letter | "_") so invalid at start of NCName (but still a valid XML name, hence not INVALID_CHARACTER_ERR); expected NAMESPACE_ERR, threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", "ெ:a", null); non-ASCII character after colon is CombiningChar, which is NCNameChar but not (Letter | "_") so invalid at start of NCName (Gecko chooses to throw NAMESPACE_ERR here, but either is valid as this is both an invalid XML name and an invalid QName); threw INVALID_CHARACTER_ERR
+PASS createDocument("http://example.com/", "a:aெ", null)
+PASS createDocument("http://example.com/", "aெ:a", null)
+PASS createDocument("http://example.com/", "xml:test", null); binding xml prefix wrong; threw NAMESPACE_ERR
+PASS createDocument("http://example.com/", "xmlns:test", null); binding xmlns prefix wrong; threw NAMESPACE_ERR
+PASS createDocument("http://www.w3.org/2000/xmlns/", "x:test", null); binding namespace namespace to wrong prefix; threw NAMESPACE_ERR
+PASS createDocument("http://www.w3.org/2000/xmlns/", "xmlns:test", null)
+PASS createDocument("http://www.w3.org/XML/1998/namespace", "xml:test", null)
+PASS createDocument("http://www.w3.org/XML/1998/namespace", "x:test", null)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err.html b/LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err.html
new file mode 100644
index 0000000..33954ad
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/createDocument-namespace-err.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css">
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/createDocument-namespace-err.js"></script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/DOMImplementation/createDocument-with-used-doctype-expected.txt b/LayoutTests/fast/dom/DOMImplementation/createDocument-with-used-doctype-expected.txt
new file mode 100644
index 0000000..7ef22e9
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/createDocument-with-used-doctype-expected.txt
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/DOMImplementation/createDocument-with-used-doctype.html b/LayoutTests/fast/dom/DOMImplementation/createDocument-with-used-doctype.html
new file mode 100644
index 0000000..ae4a7ae
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/createDocument-with-used-doctype.html
@@ -0,0 +1,32 @@
+<body>
+<iframe src="resources/createDocument-with-used-doctype-frame.html" onload="test()"></iframe>
+<script>
+if (window.layoutTestController) {
+ layoutTestController.dumpAsText();
+ layoutTestController.waitUntilDone();
+}
+
+function gc()
+{
+ if (window.GCController)
+ return GCController.collect();
+
+ for (var i = 0; i < 10000; i++)
+ var s = new String("");
+}
+
+// Reload multiple times, to make crashing more likely.
+var iterationsLeft = 50;
+function test()
+{
+ if (--iterationsLeft) {
+ frames[0].history.go(0);
+ } else {
+ gc();
+ document.body.textContent = frames[0].document.body.textContent;
+ if (window.layoutTestController)
+ layoutTestController.notifyDone();
+ }
+}
+</script>
+</body>
diff --git a/LayoutTests/fast/dom/DOMImplementation/createDocumentType-err-expected.txt b/LayoutTests/fast/dom/DOMImplementation/createDocumentType-err-expected.txt
new file mode 100644
index 0000000..a398870
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/createDocumentType-err-expected.txt
@@ -0,0 +1,31 @@
+createDocument tests modeled after mozilla's testing
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.implementation.createDocumentType('foo').toString() is "[object DocumentType]"
+PASS document.implementation.createDocumentType('foo', null).toString() is "[object DocumentType]"
+PASS createDocumentType(, ); threw INVALID_CHARACTER_ERR
+PASS createDocumentType(null, ); threw INVALID_CHARACTER_ERR
+PASS createDocumentType(, null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType(, , null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType(null, null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType(null, null, null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType(null, ""); threw INVALID_CHARACTER_ERR
+PASS createDocumentType("", null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType("", ""); threw INVALID_CHARACTER_ERR
+PASS createDocumentType("a:", null, null); threw NAMESPACE_ERR
+PASS createDocumentType(":foo", null, null); threw NAMESPACE_ERR
+PASS createDocumentType(":", null, null); threw NAMESPACE_ERR
+PASS createDocumentType("foo", null, null)
+PASS createDocumentType("foo:bar", null, null)
+PASS createDocumentType("foo::bar", null, null); threw NAMESPACE_ERR
+PASS createDocumentType(" :bar", null, null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType("foo: ", null, null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType("foo :bar", null, null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType("foo: bar", null, null); threw INVALID_CHARACTER_ERR
+PASS createDocumentType("a:b:c", null, null); valid XML name, invalid QName; threw NAMESPACE_ERR
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/DOMImplementation/createDocumentType-err.html b/LayoutTests/fast/dom/DOMImplementation/createDocumentType-err.html
new file mode 100644
index 0000000..516e991
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/createDocumentType-err.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css">
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/createDocumentType-err.js"></script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/DOMImplementation/createHTMLDocument-title-expected.txt b/LayoutTests/fast/dom/DOMImplementation/createHTMLDocument-title-expected.txt
new file mode 100644
index 0000000..712f2f1
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/createHTMLDocument-title-expected.txt
@@ -0,0 +1,5 @@
+Test for a bug 30982: createHTMLDocument doesn't escape ampersand and less-than in title.
+
+Should say PASS:
+
+PASS
diff --git a/LayoutTests/fast/dom/DOMImplementation/createHTMLDocument-title.html b/LayoutTests/fast/dom/DOMImplementation/createHTMLDocument-title.html
new file mode 100644
index 0000000..5e4a153
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/createHTMLDocument-title.html
@@ -0,0 +1,9 @@
+<p>Test for a <href="https://bugs.webkit.org/show_bug.cgi?id=30982">bug 30982</a>: createHTMLDocument doesn't escape ampersand and less-than in title.</p>
+<p>Should say PASS:</p>
+<script>
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+var result = document.implementation.createHTMLDocument('foo</title>').title;
+document.write((result == 'foo</title>') ? "PASS" : ("FAIL. Title is:<xmp>" + result + "</xmp>"));
+</script>
diff --git a/LayoutTests/fast/dom/DOMImplementation/detached-doctype-expected.txt b/LayoutTests/fast/dom/DOMImplementation/detached-doctype-expected.txt
new file mode 100644
index 0000000..38b8bbc
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/detached-doctype-expected.txt
@@ -0,0 +1,5 @@
+Test for bug 26402: Crashes when using a detached DocumentType node.
+
+PASS if no crash.
+
+DONE
diff --git a/LayoutTests/fast/dom/DOMImplementation/detached-doctype.html b/LayoutTests/fast/dom/DOMImplementation/detached-doctype.html
new file mode 100644
index 0000000..a508f82
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/detached-doctype.html
@@ -0,0 +1,29 @@
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=26402">bug 26402<a/>: Crashes when using a detached DocumentType node.</p>
+<p>PASS if no crash.</p>
+<SCRIPT>
+function gc()
+{
+ if (window.GCController)
+ return GCController.collect();
+
+ for (var i = 0; i < 10000; i++)
+ var s = new String("");
+}
+
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+var o = document.implementation.createDocumentType('x', null, null);
+var doc = document.implementation.createDocument("doc", null, 0);
+for (i in o) {
+ try { o[i]; } catch (e) {}
+ try { o[i](); } catch (e) {}
+}
+o.addEventListener("click", function() {}, true);
+o.removeEventListener("click", function() {}, true);
+o.childNodes;
+o.childNodes.item(0);
+o.firstChild;
+gc();
+document.write("DONE");
+</SCRIPT>
diff --git a/LayoutTests/fast/dom/DOMImplementation/resources/createDocument-with-used-doctype-frame.html b/LayoutTests/fast/dom/DOMImplementation/resources/createDocument-with-used-doctype-frame.html
new file mode 100644
index 0000000..e0e7e67
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/resources/createDocument-with-used-doctype-frame.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<title>document.implementation.createDocument with current document's DOCTYPE</title>
+<body>
+FAIL (Script did not run);
+<script>
+document.body.textContent = "FAIL";
+try {
+ document.implementation.createDocument(null, null, document.doctype);
+ document.body.textContent = "FAIL (no exception)";
+}
+catch(e) {
+ if (e.code === DOMException.WRONG_DOCUMENT_ERR || e.code === DOMException.NOT_SUPPORTED_ERR)
+ document.body.textContent = "PASS";
+ else
+ document.body.textContent = "FAIL (wrong exception: " + e.code + ")";
+}
+</script>
diff --git a/LayoutTests/fast/dom/DOMImplementation/script-tests/TEMPLATE.html b/LayoutTests/fast/dom/DOMImplementation/script-tests/TEMPLATE.html
new file mode 100644
index 0000000..1951c43
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/script-tests/TEMPLATE.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css">
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="YOUR_JS_FILE_HERE"></script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/DOMImplementation/script-tests/createDocument-namespace-err.js b/LayoutTests/fast/dom/DOMImplementation/script-tests/createDocument-namespace-err.js
new file mode 100644
index 0000000..6683f8b
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/script-tests/createDocument-namespace-err.js
@@ -0,0 +1,146 @@
+description("createDocument tests modeled after createElementNS tests from mozilla which were attached to webkit bug 16833");
+
+// document.implementation.createDocument() should throw the same set of errors
+// as document.createElementNS()
+// http://www.w3.org/TR/DOM-Level-3-Core/core.html#Level-2-Core-DOM-createDocument
+// Thus we copied these test cases from:
+// LayoutTests/fast/dom/Document/resources/createDocument-namespace-err.js
+
+function assert(c, m)
+{
+ if (!c)
+ testFailed(m);
+ else
+ testPassed(m);
+}
+
+function stringForExceptionCode(c)
+{
+ var exceptionName;
+ switch(c) {
+ case DOMException.INVALID_CHARACTER_ERR:
+ exceptionName = "INVALID_CHARACTER_ERR";
+ break;
+ case DOMException.NAMESPACE_ERR:
+ exceptionName = "NAMESPACE_ERR";
+ }
+ if (exceptionName)
+ return exceptionName; // + "(" + c + ")";
+ return c;
+}
+
+function assertEquals(actual, expect, m)
+{
+ if (actual !== expect) {
+ m += "; expected " + stringForExceptionCode(expect) + ", threw " + stringForExceptionCode(actual);
+ testFailed(m);
+ } else {
+ m += "; threw " + stringForExceptionCode(actual);;
+ testPassed(m);
+ }
+}
+
+var allNSTests = [
+ { args: [undefined, undefined] },
+ { args: [null, undefined] },
+ { args: [undefined, null], code: 5 },
+ { args: [null, null], code: 5 },
+ { args: [null, ""], code: 5 },
+ { args: ["", null], code: 5 },
+ { args: ["", ""], code: 5 },
+ { args: [null, "<div>"], code: 5 },
+ { args: [null, "0div"], code: 5 },
+ { args: [null, "di v"], code: 5 },
+ { args: [null, "di<v"], code: 5 },
+ { args: [null, "-div"], code: 5 },
+ { args: [null, ".div"], code: 5 },
+ { args: ["http://example.com/", "<div>"], code: 5 },
+ { args: ["http://example.com/", "0div"], code: 5 },
+ { args: ["http://example.com/", "di<v"], code: 5 },
+ { args: ["http://example.com/", "-div"], code: 5 },
+ { args: ["http://example.com/", ".div"], code: 5 },
+ { args: [null, ":div"], code: 14 },
+ { args: [null, "div:"], code: 14 },
+ { args: ["http://example.com/", ":div"], code: 14 },
+ { args: ["http://example.com/", "div:"], code: 14 },
+ { args: [null, "d:iv"], code: 14 },
+ { args: [null, "a:b:c"], code: 14, message: "valid XML name, invalid QName" },
+ { args: ["http://example.com/", "a:b:c"], code: 14, message: "valid XML name, invalid QName" },
+ { args: [null, "a::c"], code: 14, message: "valid XML name, invalid QName" },
+ { args: ["http://example.com/", "a::c"], code: 14, message: "valid XML name, invalid QName" },
+ { args: ["http://example.com/", "a:0"], code: 5, message: "valid XML name, not a valid QName" },
+ { args: ["http://example.com/", "0:a"], code: 5, message: "0 at start makes it not a valid XML name" },
+ { args: ["http://example.com/", "a:_"] },
+ { args: ["http://example.com/", "a:\u0BC6"], code: 14,
+ message: "non-ASCII character after colon is CombiningChar, which is " +
+ "NCNameChar but not (Letter | \"_\") so invalid at start of " +
+ "NCName (but still a valid XML name, hence not INVALID_CHARACTER_ERR)" },
+ { args: ["http://example.com/", "\u0BC6:a"], code: 5,
+ message: "non-ASCII character after colon is CombiningChar, which is " +
+ "NCNameChar but not (Letter | \"_\") so invalid at start of " +
+ "NCName (Gecko chooses to throw NAMESPACE_ERR here, but either is valid " +
+ "as this is both an invalid XML name and an invalid QName)" },
+ { args: ["http://example.com/", "a:a\u0BC6"] },
+ { args: ["http://example.com/", "a\u0BC6:a"] },
+ { args: ["http://example.com/", "xml:test"], code: 14, message: "binding xml prefix wrong" },
+ { args: ["http://example.com/", "xmlns:test"], code: 14, message: "binding xmlns prefix wrong" },
+ { args: ["http://www.w3.org/2000/xmlns/", "x:test"], code: 14, message: "binding namespace namespace to wrong prefix" },
+ { args: ["http://www.w3.org/2000/xmlns/", "xmlns:test"] },
+ { args: ["http://www.w3.org/XML/1998/namespace", "xml:test"] },
+ { args: ["http://www.w3.org/XML/1998/namespace", "x:test"] },
+];
+
+function sourceify(v)
+{
+ switch (typeof v) {
+ case "undefined":
+ return v;
+ case "string":
+ return '"' + v.replace('"', '\\"') + '"';
+ default:
+ return String(v);
+ }
+}
+
+function sourceifyArgs(args)
+{
+ var copy = new Array(args.length);
+ for (var i = 0, sz = args.length; i < sz; i++)
+ copy[i] = sourceify(args[i]);
+
+ return copy.join(", ");
+}
+
+function runNSTests(tests, doc, createFunctionName)
+{
+ for (var i = 0, sz = tests.length; i < sz; i++) {
+ var test = tests[i];
+
+ // Gecko throws "undefined" if createDocument isn't
+ // called with 3 arguments. Instead of modifying all
+ // of the values in the arrays above (which were taken from createElementNS tests)
+ // we will instead just hack the args list here.
+ var argsWithExtraLastNull = test.args.slice(); // copy the args arary
+ argsWithExtraLastNull.push(null);
+
+ var code = -1;
+ var argStr = sourceifyArgs(argsWithExtraLastNull);
+ var msg = createFunctionName + "(" + argStr + ")";
+ if ("message" in test)
+ msg += "; " + test.message;
+ try {
+ doc[createFunctionName].apply(doc, argsWithExtraLastNull);
+ assert(!("code" in test), msg);
+ } catch (e) {
+ assertEquals(e.code, test.code || "expected no exception", msg);
+ }
+ }
+}
+
+// Moz throws a "Not enough arguments" exception in these, we don't:
+shouldBeEqualToString("document.implementation.createDocument().toString()", "[object Document]");
+shouldBeEqualToString("document.implementation.createDocument(\"http://www.example.com\").toString()", "[object Document]");
+
+runNSTests(allNSTests, document.implementation, "createDocument");
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/dom/DOMImplementation/script-tests/createDocumentType-err.js b/LayoutTests/fast/dom/DOMImplementation/script-tests/createDocumentType-err.js
new file mode 100644
index 0000000..9ef7e7c
--- /dev/null
+++ b/LayoutTests/fast/dom/DOMImplementation/script-tests/createDocumentType-err.js
@@ -0,0 +1,100 @@
+description("createDocument tests modeled after mozilla's testing");
+
+function stringForExceptionCode(c)
+{
+ var exceptionName;
+ switch(c) {
+ case DOMException.INVALID_CHARACTER_ERR:
+ exceptionName = "INVALID_CHARACTER_ERR";
+ break;
+ case DOMException.NAMESPACE_ERR:
+ exceptionName = "NAMESPACE_ERR";
+ }
+ if (exceptionName)
+ return exceptionName; // + "(" + c + ")";
+ return c;
+}
+
+function assertEquals(actual, expect, m)
+{
+ if (actual !== expect) {
+ m += "; expected " + stringForExceptionCode(expect) + ", threw " + stringForExceptionCode(actual);
+ testFailed(m);
+ } else {
+ m += "; threw " + stringForExceptionCode(actual);;
+ testPassed(m);
+ }
+}
+
+var allTests = [
+ { args: [undefined, undefined], code: 5 },
+ { args: [null, undefined], code: 5 },
+ { args: [undefined, null], code: 5 },
+ { args: [undefined, undefined, null], code: 5 },
+ { args: [null, null], code: 5 },
+ { args: [null, null, null], code: 5 },
+ { args: [null, ""], code: 5 },
+ { args: ["", null], code: 5 },
+ { args: ["", ""], code: 5 },
+ { args: ["a:", null, null], code: 14 },
+ { args: [":foo", null, null], code: 14 },
+ { args: [":", null, null], code: 14 },
+ { args: ["foo", null, null] },
+ { args: ["foo:bar", null, null] },
+ { args: ["foo::bar", null, null], code: 14 },
+ { args: ["\t:bar", null, null], code: 5 },
+ { args: ["foo:\t", null, null], code: 5 },
+ { args: ["foo :bar", null, null], code: 5 },
+ { args: ["foo: bar", null, null], code: 5 },
+ { args: ["a:b:c", null, null], code: 14, message: "valid XML name, invalid QName" },
+];
+
+function sourceify(v)
+{
+ switch (typeof v) {
+ case "undefined":
+ return v;
+ case "string":
+ return '"' + v.replace('"', '\\"') + '"';
+ default:
+ return String(v);
+ }
+}
+
+function sourceifyArgs(args)
+{
+ var copy = new Array(args.length);
+ for (var i = 0, sz = args.length; i < sz; i++)
+ copy[i] = sourceify(args[i]);
+
+ return copy.join(", ");
+}
+
+function runTests(tests, createFunctionName)
+{
+ for (var i = 0, sz = tests.length; i < sz; i++) {
+ var test = tests[i];
+
+ var code = -1;
+ var argStr = sourceifyArgs(test.args);
+ var msg = createFunctionName + "(" + argStr + ")";
+ if ("message" in test)
+ msg += "; " + test.message;
+ try {
+ document.implementation[createFunctionName].apply(document.implementation, test.args);
+ if ('code' in test)
+ testFailed(msg + " expected exception: " + test.code);
+ else
+ testPassed(msg);
+ } catch (e) {
+ assertEquals(e.code, test.code || "expected no exception", msg);
+ }
+ }
+}
+
+// Moz throws a "Not enough arguments" exception in these, we don't:
+shouldBeEqualToString("document.implementation.createDocumentType('foo').toString()", "[object DocumentType]");
+shouldBeEqualToString("document.implementation.createDocumentType('foo', null).toString()", "[object DocumentType]");
+runTests(allTests, "createDocumentType");
+
+var successfullyParsed = true;