From 807b3275a431a28738b66aaafd3d1c906d5e3556 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Thu, 7 Dec 2023 17:44:43 +0100 Subject: [PATCH] dom: add more WPT tests for document --- tests/wpt/dom/nodes/Document-adoptNode.html | 50 ++++++++++++++ .../dom/nodes/Document-createAttribute.html | 55 +++++++++++++++ .../Document-createCDATASection-xhtml.xhtml | 22 ++++++ .../nodes/Document-createCDATASection.html | 16 +++++ .../Document-createComment-createTextNode.js | 22 ++++++ .../wpt/dom/nodes/Document-createComment.html | 21 ++++++ ...nt-createProcessingInstruction-xhtml.xhtml | 15 +++++ .../Document-createProcessingInstruction.html | 11 +++ .../Document-createProcessingInstruction.js | 39 +++++++++++ .../dom/nodes/Document-createTextNode.html | 21 ++++++ tests/wpt/dom/nodes/Document-importNode.html | 67 +++++++++++++++++++ 11 files changed, 339 insertions(+) create mode 100644 tests/wpt/dom/nodes/Document-adoptNode.html create mode 100644 tests/wpt/dom/nodes/Document-createAttribute.html create mode 100644 tests/wpt/dom/nodes/Document-createCDATASection-xhtml.xhtml create mode 100644 tests/wpt/dom/nodes/Document-createCDATASection.html create mode 100644 tests/wpt/dom/nodes/Document-createComment-createTextNode.js create mode 100644 tests/wpt/dom/nodes/Document-createComment.html create mode 100644 tests/wpt/dom/nodes/Document-createProcessingInstruction-xhtml.xhtml create mode 100644 tests/wpt/dom/nodes/Document-createProcessingInstruction.html create mode 100644 tests/wpt/dom/nodes/Document-createProcessingInstruction.js create mode 100644 tests/wpt/dom/nodes/Document-createTextNode.html create mode 100644 tests/wpt/dom/nodes/Document-importNode.html diff --git a/tests/wpt/dom/nodes/Document-adoptNode.html b/tests/wpt/dom/nodes/Document-adoptNode.html new file mode 100644 index 00000000..60a4e677 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-adoptNode.html @@ -0,0 +1,50 @@ + + +Document.adoptNode + + + +
+x + diff --git a/tests/wpt/dom/nodes/Document-createAttribute.html b/tests/wpt/dom/nodes/Document-createAttribute.html new file mode 100644 index 00000000..b3dc8b60 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createAttribute.html @@ -0,0 +1,55 @@ + + +Document.createAttribute + + + + +
+ diff --git a/tests/wpt/dom/nodes/Document-createCDATASection-xhtml.xhtml b/tests/wpt/dom/nodes/Document-createCDATASection-xhtml.xhtml new file mode 100644 index 00000000..b0a5a7f2 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createCDATASection-xhtml.xhtml @@ -0,0 +1,22 @@ + + + + + document.createCDATASection + + + + + + + + + + diff --git a/tests/wpt/dom/nodes/Document-createCDATASection.html b/tests/wpt/dom/nodes/Document-createCDATASection.html new file mode 100644 index 00000000..72b3684c --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createCDATASection.html @@ -0,0 +1,16 @@ + + +document.createCDATASection must throw in HTML documents + + + + + diff --git a/tests/wpt/dom/nodes/Document-createComment-createTextNode.js b/tests/wpt/dom/nodes/Document-createComment-createTextNode.js new file mode 100644 index 00000000..62a38d38 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createComment-createTextNode.js @@ -0,0 +1,22 @@ +function test_create(method, iface, nodeType, nodeName) { + ["\u000b", "a -- b", "a-", "-b", null, undefined].forEach(function(value) { + test(function() { + var c = document[method](value); + var expected = String(value); + assert_true(c instanceof iface); + assert_true(c instanceof CharacterData); + assert_true(c instanceof Node); + assert_equals(c.ownerDocument, document); + assert_equals(c.data, expected, "data"); + assert_equals(c.nodeValue, expected, "nodeValue"); + assert_equals(c.textContent, expected, "textContent"); + assert_equals(c.length, expected.length); + assert_equals(c.nodeType, nodeType); + assert_equals(c.nodeName, nodeName); + assert_equals(c.hasChildNodes(), false); + assert_equals(c.childNodes.length, 0); + assert_equals(c.firstChild, null); + assert_equals(c.lastChild, null); + }, method + "(" + format_value(value) + ")"); + }); +} diff --git a/tests/wpt/dom/nodes/Document-createComment.html b/tests/wpt/dom/nodes/Document-createComment.html new file mode 100644 index 00000000..a175c3a2 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createComment.html @@ -0,0 +1,21 @@ + + +Document.createComment + + + + + + + + + + + + + + +
+ diff --git a/tests/wpt/dom/nodes/Document-createProcessingInstruction-xhtml.xhtml b/tests/wpt/dom/nodes/Document-createProcessingInstruction-xhtml.xhtml new file mode 100644 index 00000000..d06f70fd --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createProcessingInstruction-xhtml.xhtml @@ -0,0 +1,15 @@ + + +Document.createProcessingInstruction in XML documents + + + + + + + + +
+ + +
+ diff --git a/tests/wpt/dom/nodes/Document-createProcessingInstruction.js b/tests/wpt/dom/nodes/Document-createProcessingInstruction.js new file mode 100644 index 00000000..d6cc3725 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createProcessingInstruction.js @@ -0,0 +1,39 @@ +test(function() { + var invalid = [ + ["A", "?>"], + ["\u00B7A", "x"], + ["\u00D7A", "x"], + ["A\u00D7", "x"], + ["\\A", "x"], + ["\f", "x"], + [0, "x"], + ["0", "x"] + ], + valid = [ + ["xml:fail", "x"], + ["A\u00B7A", "x"], + ["a0", "x"] + ] + + for (var i = 0, il = invalid.length; i < il; i++) { + test(function() { + assert_throws_dom("INVALID_CHARACTER_ERR", function() { + document.createProcessingInstruction(invalid[i][0], invalid[i][1]) + }) + }, "Should throw an INVALID_CHARACTER_ERR for target " + + format_value(invalid[i][0]) + " and data " + + format_value(invalid[i][1]) + ".") + } + for (var i = 0, il = valid.length; i < il; ++i) { + test(function() { + var pi = document.createProcessingInstruction(valid[i][0], valid[i][1]); + assert_equals(pi.target, valid[i][0]); + assert_equals(pi.data, valid[i][1]); + assert_equals(pi.ownerDocument, document); + assert_true(pi instanceof ProcessingInstruction); + assert_true(pi instanceof Node); + }, "Should get a ProcessingInstruction for target " + + format_value(valid[i][0]) + " and data " + + format_value(valid[i][1]) + ".") + } +}) diff --git a/tests/wpt/dom/nodes/Document-createTextNode.html b/tests/wpt/dom/nodes/Document-createTextNode.html new file mode 100644 index 00000000..ccc1b1b7 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createTextNode.html @@ -0,0 +1,21 @@ + + +Document.createTextNode + + + + + + + + + + + + + + +
+ diff --git a/tests/wpt/dom/nodes/Document-importNode.html b/tests/wpt/dom/nodes/Document-importNode.html new file mode 100644 index 00000000..d27cce6c --- /dev/null +++ b/tests/wpt/dom/nodes/Document-importNode.html @@ -0,0 +1,67 @@ + + +Document.importNode + + + +
+