diff options
Diffstat (limited to 'LayoutTests/fast/dom/Node')
21 files changed, 986 insertions, 0 deletions
diff --git a/LayoutTests/fast/dom/Node/DOMNodeRemovedEvent-expected.txt b/LayoutTests/fast/dom/Node/DOMNodeRemovedEvent-expected.txt new file mode 100644 index 0000000..1ccc099 --- /dev/null +++ b/LayoutTests/fast/dom/Node/DOMNodeRemovedEvent-expected.txt @@ -0,0 +1,10 @@ +This test checks that DOMNodeRemovedEvent is emitted once (and only once). + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS count is 1 +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/dom/Node/DOMNodeRemovedEvent.html b/LayoutTests/fast/dom/Node/DOMNodeRemovedEvent.html new file mode 100644 index 0000000..4b1cd04 --- /dev/null +++ b/LayoutTests/fast/dom/Node/DOMNodeRemovedEvent.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/DOMNodeRemovedEvent.js"></script> +<script src="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/LayoutTests/fast/dom/Node/default-namespace-empty-argument-expected.txt b/LayoutTests/fast/dom/Node/default-namespace-empty-argument-expected.txt new file mode 100644 index 0000000..ef7b411 --- /dev/null +++ b/LayoutTests/fast/dom/Node/default-namespace-empty-argument-expected.txt @@ -0,0 +1,5 @@ +Test for a bug 30992: Node.isDefaultNamespace doesn't convert empty strings to null. + +Should say PASS: + +PASS diff --git a/LayoutTests/fast/dom/Node/default-namespace-empty-argument.html b/LayoutTests/fast/dom/Node/default-namespace-empty-argument.html new file mode 100644 index 0000000..da915c1 --- /dev/null +++ b/LayoutTests/fast/dom/Node/default-namespace-empty-argument.html @@ -0,0 +1,8 @@ +<p>Test for a <href="https://bugs.webkit.org/show_bug.cgi?id=30992">bug 30992</a>: Node.isDefaultNamespace doesn't convert empty strings to null.</p> +<p>Should say PASS:</p> +<script> +if (window.layoutTestController) + layoutTestController.dumpAsText(); + +document.write((document.implementation.createDocument(null, 'root', null).isDefaultNamespace('')) ? "PASS" : "FAIL"); +</script> diff --git a/LayoutTests/fast/dom/Node/fragment-mutation-expected.txt b/LayoutTests/fast/dom/Node/fragment-mutation-expected.txt new file mode 100644 index 0000000..41e8fa4 --- /dev/null +++ b/LayoutTests/fast/dom/Node/fragment-mutation-expected.txt @@ -0,0 +1,17 @@ +This test creates a fragment containing three elements: "B", "U", and "P", attempts to appendChild this fragment and studies effects of mutation events on the fragment. + +Inserting an element in front of the next item in fragment should not affect the result: PASS +Removing next item should not abort iteration: PASS +Appending an element at the end of the fragment should not affect the result: PASS +Continually re-appending removed element to the fragment should eventually throw NOT_FOUND_ERR: PASS +Moving next item to become previous sibling of the re-parentee should not result in stack exhaustion: PASS + +This test creates a fragment containing three elements: "B", "U", and "P", attempts to insertBefore this fragment and studies effects of mutation events on the fragment. + +Inserting an element in front of the next item in fragment should not affect the result: PASS +Removing next item should not abort iteration: PASS +Appending an element at the end of the fragment should not affect the result: PASS +Continually re-appending removed element to the fragment should eventually throw NOT_FOUND_ERR: PASS +Moving next item to become previous sibling of the re-parentee should not result in stack exhaustion: PASS + + diff --git a/LayoutTests/fast/dom/Node/fragment-mutation.html b/LayoutTests/fast/dom/Node/fragment-mutation.html new file mode 100644 index 0000000..037e17b --- /dev/null +++ b/LayoutTests/fast/dom/Node/fragment-mutation.html @@ -0,0 +1,148 @@ +<html> +<head> +<title>Fragment Mutation Tests</title> +<script> + +if (window.layoutTestController) + layoutTestController.dumpAsText(); + +var log = []; + +function logResult(description, outcome) +{ + log.push({ description: description, outcome: outcome}); +} + +function printLog(methodName) +{ + var entries = log.map(function(entry) { + return "<li>" + entry.description + ": " + entry.outcome; + }); + document.body.appendChild(document.createElement("p")).innerHTML = "This test creates a fragment containing three elements: \"B\", \"U\", and \"P\", " + + " attempts to " + methodName + " this fragment and studies effects of mutation events on the fragment."; + document.body.appendChild(document.createElement("ul")).innerHTML = entries.join("\n"); + document.body.appendChild(document.createElement("br")); + log = []; +} + +function produceNodeNameString(nodes) +{ + var node = nodes.firstChild; + var result = ""; + while(node) { + result += node.nodeName; + node = node.nextSibling; + } + return result; +} + +function expectException(code) +{ + return function(stash, exception) { + if (!exception) + return "FAIL, expected exception with code " + code + ". The resulting fragment was: \"" + produceNodeNameString(stash) + "\"."; + + if (code == exception.code) + return "PASS"; + return "FAIL, expected exception code: " + code + ", was: " + exception + "."; + } +} + +function expectNodes(nodes) +{ + return function(stash, exception) { + if (exception) + return "FAIL, unexpected exception thrown: " + exception; + var result = produceNodeNameString(stash); + if (nodes == result) + return "PASS"; + return "FAIL, expected \"" + nodes + "\", was \"" + result + "\"."; + }; +} + +function testFragment(method, description, mutationHandler, expectation, nonStop) +{ + var once = 0; + var logged = 0; + var frag = document.createDocumentFragment(); + var stash = document.body.appendChild(document.createElement("div")); + frag.appendChild(document.createElement("b")); + frag.appendChild(document.createElement("u")); + frag.appendChild(document.createElement("p")); + frag.addEventListener("DOMSubtreeModified", function(evt) + { + if (!nonStop && once++) + return; + + try { + mutationHandler(evt, frag, stash); + } + catch(e) { + logResult(description, expectation(stash, e)); + logged++; + } + }, false); + + try { + method(stash, frag); + } + catch(e) { + logResult(description, expectation(stash, e)); + logged++; + } + if (!logged) + logResult(description, expectation(stash)); + document.body.removeChild(stash); +} + +function appendChildMethod(object, subject) +{ + object.appendChild(subject); +} + +function insertBeforeMethod(object, subject) +{ + object.insertBefore(subject, object.firstChild); +} + +function runTest(methodName, method) +{ + var missing = document.body.appendChild(document.createElement("em")); + testFragment(method, "Inserting an element in front of the next item in fragment should not affect the result", function(evt, frag) + { + frag.insertBefore(missing, frag.firstChild); + }, expectNodes("BUP")); + + testFragment(method, "Removing next item should not abort iteration", function(evt, frag) + { + frag.removeChild(frag.firstChild); + }, expectNodes("BUP")); + + var extra = document.body.appendChild(document.createElement("em")); + testFragment(method, "Appending an element at the end of the fragment should not affect the result", function(evt, frag) + { + frag.appendChild(extra); + }, expectNodes("BUP")); + + testFragment(method, "Continually re-appending removed element to the fragment should eventually throw NOT_FOUND_ERR", function(evt, frag, stash) + { + stash.insertBefore(frag.lastChild, stash.firstChild); + }, expectException(8), true); + + testFragment(method, "Moving next item to become previous sibling of the re-parentee should not result in stack exhaustion", function(evt, frag, stash) + { + document.body.insertBefore(frag.firstChild, stash); + }, expectNodes("BUP")); + printLog(methodName); +} +function runTests() +{ + runTest("appendChild", appendChildMethod); + runTest("insertBefore", insertBeforeMethod); +} + +</script> +</head> +<body onload="runTests()"> +</body> +</html>
\ No newline at end of file diff --git a/LayoutTests/fast/dom/Node/initial-values-expected.txt b/LayoutTests/fast/dom/Node/initial-values-expected.txt new file mode 100644 index 0000000..48d2895 --- /dev/null +++ b/LayoutTests/fast/dom/Node/initial-values-expected.txt @@ -0,0 +1,151 @@ +Test creation of each type of Node and check intial values + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +Attribute creation using createElement on an HTML doc: +PASS attr.nodeName is 'foo' +PASS attr.name is 'foo' +FAIL attr.localName should be null (of type object). Was foo (of type string). +PASS attr.namespaceURI is null +PASS attr.prefix is null +PASS attr.nodeValue is '' +PASS attr.value is '' +PASS attr.attributes is null +Attribute creation using createElementNS on an HTML doc: +PASS attr.nodeName is 'example:foo' +PASS attr.name is 'example:foo' +PASS attr.localName is 'foo' +PASS attr.namespaceURI is 'http://www.example.com' +PASS attr.prefix is 'example' +PASS attr.nodeValue is '' +PASS attr.value is '' +PASS attr.attributes is null +Attribute creation using createElement on an XHTML doc: +PASS attr.nodeName is 'foo' +PASS attr.name is 'foo' +FAIL attr.localName should be null (of type object). Was foo (of type string). +PASS attr.namespaceURI is null +PASS attr.prefix is null +PASS attr.nodeValue is '' +PASS attr.value is '' +PASS attr.attributes is null +Attribute creation using createElementNS on an XHTML doc: +PASS attr.nodeName is 'example:foo' +PASS attr.name is 'example:foo' +PASS attr.localName is 'foo' +PASS attr.namespaceURI is 'http://www.example.com' +PASS attr.prefix is 'example' +PASS attr.nodeValue is '' +PASS attr.value is '' +PASS attr.attributes is null +PASS comment.nodeName is '#comment' +PASS comment.localName is null +PASS comment.namespaceURI is null +PASS comment.prefix is null +PASS comment.nodeValue is 'foo' +PASS comment.data is 'foo' +PASS comment.attributes is null +PASS document.createCDATASection('foo') threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9. +PASS cdata.nodeName is '#cdata-section' +PASS cdata.localName is null +PASS cdata.namespaceURI is null +PASS cdata.prefix is null +PASS cdata.nodeValue is 'foo' +PASS cdata.data is 'foo' +PASS cdata.attributes is null +PASS fragment.nodeName is '#document-fragment' +PASS fragment.localName is null +PASS fragment.namespaceURI is null +PASS fragment.prefix is null +PASS fragment.nodeValue is null +PASS fragment.attributes is null +PASS doc.nodeName is '#document' +PASS doc.localName is null +FAIL doc.namespaceURI should be http://www.w3.org/1999/xhtml (of type string). Was null (of type object). +PASS doc.prefix is null +PASS doc.nodeValue is null +PASS doc.attributes is null +PASS doctype.nodeName is 'svg' +PASS doctype.name is 'svg' +PASS doctype.localName is null +PASS doctype.namespaceURI is null +PASS doctype.prefix is null +PASS doctype.nodeValue is null +PASS doctype.attributes is null +Element creation using createElement on an HTML doc: +PASS element.nodeName is 'PRE' +FAIL element.localName should be null (of type object). Was pre (of type string). +FAIL element.namespaceURI should be null (of type object). Was http://www.w3.org/1999/xhtml (of type string). +PASS element.prefix is null +PASS element.nodeValue is null +PASS element.attributes.toString() is '[object NamedNodeMap]' +Prefixed element creation using createElementNS on an HTML doc: +PASS element.nodeName is 'html:pre' +PASS element.localName is 'pre' +PASS element.namespaceURI is 'http://www.w3.org/1999/xhtml' +PASS element.prefix is 'html' +PASS element.nodeValue is null +PASS element.attributes.toString() is '[object NamedNodeMap]' +SVG Element creation using createElementNS on an HTML doc: +PASS element.nodeName is 'svg' +PASS element.localName is 'svg' +PASS element.namespaceURI is 'http://www.w3.org/2000/svg' +PASS element.prefix is null +PASS element.nodeValue is null +PASS element.attributes.toString() is '[object NamedNodeMap]' +Unknown Element creation using createElementNS on an HTML doc: +PASS element.nodeName is 'foo:svg' +PASS element.localName is 'svg' +PASS element.namespaceURI is 'http://www.webkit.org' +PASS element.prefix is 'foo' +PASS element.nodeValue is null +PASS element.attributes.toString() is '[object NamedNodeMap]' +Element creation using createElementNS on an HTML doc: +FAIL element.nodeName should be pre. Was PRE. +PASS element.localName is 'pre' +PASS element.namespaceURI is 'http://www.w3.org/1999/xhtml' +PASS element.prefix is null +PASS element.nodeValue is null +PASS element.attributes.toString() is '[object NamedNodeMap]' +Element creation using createElement on an XHTML doc: +PASS element.nodeName is 'pre' +FAIL element.localName should be null (of type object). Was pre (of type string). +FAIL element.namespaceURI should be null (of type object). Was http://www.w3.org/1999/xhtml (of type string). +PASS element.prefix is null +PASS element.nodeValue is null +PASS element.attributes.toString() is '[object NamedNodeMap]' +Element creation using createElementNS on an XHTML doc: +PASS element.nodeName is 'html:pre' +PASS element.localName is 'pre' +PASS element.namespaceURI is 'http://www.w3.org/1999/xhtml' +PASS element.prefix is 'html' +PASS element.nodeValue is null +PASS element.attributes.toString() is '[object NamedNodeMap]' +PASS document.createEntityReference('gt') threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9. +PASS entityReference.nodeName is 'gt' +PASS entityReference.localName is null +PASS entityReference.namespaceURI is null +PASS entityReference.prefix is null +PASS entityReference.nodeValue is null +PASS entityReference.attributes is null +PASS document.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"') threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9. +PASS processingInstruction.nodeName is 'xml-stylesheet' +PASS processingInstruction.localName is null +PASS processingInstruction.namespaceURI is null +PASS processingInstruction.prefix is null +PASS processingInstruction.nodeValue is 'type="text/xsl" href="missing.xsl"' +PASS processingInstruction.attributes is null +PASS processingInstruction.target is 'xml-stylesheet' +PASS processingInstruction.data is 'type="text/xsl" href="missing.xsl"' +PASS text.nodeName is '#text' +PASS text.localName is null +PASS text.namespaceURI is null +PASS text.prefix is null +PASS text.nodeValue is 'foo' +PASS text.data is 'foo' +PASS text.attributes is null +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/dom/Node/initial-values.html b/LayoutTests/fast/dom/Node/initial-values.html new file mode 100644 index 0000000..19b634b --- /dev/null +++ b/LayoutTests/fast/dom/Node/initial-values.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/initial-values.js"></script> +<script src="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/LayoutTests/fast/dom/Node/isEqualNode-expected.txt b/LayoutTests/fast/dom/Node/isEqualNode-expected.txt new file mode 100644 index 0000000..1877d20 --- /dev/null +++ b/LayoutTests/fast/dom/Node/isEqualNode-expected.txt @@ -0,0 +1,13 @@ +Test the isEqualNode API. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +Test isEqualNode for DocumentType nodes. +PASS docTypeAllSet.isEqualNode(docTypeAllSet2) is true +PASS docTypeAllSet.isEqualNode(docTypeDifferentPublicID) is false +PASS docTypeAllSet.isEqualNode(docTypeDifferentSystemID) is false +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/dom/Node/isEqualNode.html b/LayoutTests/fast/dom/Node/isEqualNode.html new file mode 100644 index 0000000..0222e70 --- /dev/null +++ b/LayoutTests/fast/dom/Node/isEqualNode.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/isEqualNode.js"></script> +<script src="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/LayoutTests/fast/dom/Node/mutation-blur-expected.txt b/LayoutTests/fast/dom/Node/mutation-blur-expected.txt new file mode 100644 index 0000000..d33e8bf --- /dev/null +++ b/LayoutTests/fast/dom/Node/mutation-blur-expected.txt @@ -0,0 +1,4 @@ +Tests for proper handling of DOM changes during a blur event. If the test doesn't crash, it passed. + + + diff --git a/LayoutTests/fast/dom/Node/mutation-blur.html b/LayoutTests/fast/dom/Node/mutation-blur.html new file mode 100644 index 0000000..173409e --- /dev/null +++ b/LayoutTests/fast/dom/Node/mutation-blur.html @@ -0,0 +1,73 @@ +<html> +<head> +<script> + if (window.layoutTestController) { + layoutTestController.dumpAsText(); + layoutTestController.waitUntilDone(); + } + + var container1; + var container2; + var elem; + + function handler2() + { + container2.appendChild(elem); + } + + function onload() + { + container1 = document.getElementById("newcontainer1"); + container2 = document.getElementById("newcontainer2"); + + if (!window.eventSender) + return; + + var rect = document.getElementById("trigger").getBoundingClientRect(); + eventSender.mouseMoveTo(rect.left + rect.width / 2, rect.top + rect.height / 2); + eventSender.mouseDown(); + eventSender.mouseUp(); + } + + function onpress() + { + elem = document.getElementById("subcontainer1"); + document.getElementById("sub1").focus(); + + try { + container1.appendChild(elem); + container1.removeChild(elem); + elem = null; + } + catch (e) { } + + // Force GC. + if (this.GCController) + GCController.collect(); + else { + for (var i = 0; i < 10000; ++i) { + ({ }); + } + } + + document.body.removeChild(container2); + + if (window.layoutTestController) + layoutTestController.notifyDone(); + + } + +</script> +</head> +<body onload="onload()"> +<p>Tests for proper handling of DOM changes during a blur event. If the test doesn't crash, it passed. +<div id="subcontainer1"> + <textarea id="sub1" onblur="handler2()"></textarea> +</div> + +<input id="trigger" type="button" name="Press" value="press" onclick="onpress()"> +<div id="newcontainer1"></div> +<div id="newcontainer2"></div> + +</body> +</html> diff --git a/LayoutTests/fast/dom/Node/normalize-expected.txt b/LayoutTests/fast/dom/Node/normalize-expected.txt new file mode 100644 index 0000000..31f1ff9 --- /dev/null +++ b/LayoutTests/fast/dom/Node/normalize-expected.txt @@ -0,0 +1,12 @@ +Several tests of the DOM normalize() function. +test1 (two non-empty text nodes): PASSED +test2 (three non-empty text nodes): PASSED +test3 (non-empty text nodes mixed with elements): PASSED +test4 (single empty text node): PASSED +test5 (empty text node between elements): PASSED +test6 (empty text nodes before non-empty node): PASSED +test7 (empty text nodes after non-empty node): PASSED +test8 (empty text nodes between non-empty nodes): PASSED +test9 (empty and non-empty text nodes mixed with elements): PASSED +test10 (mixed cases including deeper nested text nodes): PASSED + diff --git a/LayoutTests/fast/dom/Node/normalize-with-cdata-expected.txt b/LayoutTests/fast/dom/Node/normalize-with-cdata-expected.txt new file mode 100644 index 0000000..f8291ef --- /dev/null +++ b/LayoutTests/fast/dom/Node/normalize-with-cdata-expected.txt @@ -0,0 +1,15 @@ +Test of normalize on an XML document with CDATA. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +Before normalize +PASS serializer.serializeToString(xmlChunk) is "<foo>This is some text before the CDATA<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>This is some text after the CDATA</foo>" +PASS xmlChunk.documentElement.childNodes.length is 3 +After normalize +PASS serializer.serializeToString(xmlChunk) is "<foo>This is some text before the CDATA<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>This is some text after the CDATA</foo>" +PASS xmlChunk.documentElement.childNodes.length is 3 +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/dom/Node/normalize-with-cdata.html b/LayoutTests/fast/dom/Node/normalize-with-cdata.html new file mode 100644 index 0000000..a74ec70 --- /dev/null +++ b/LayoutTests/fast/dom/Node/normalize-with-cdata.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/normalize-with-cdata.js"></script> +<script src="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/LayoutTests/fast/dom/Node/normalize.html b/LayoutTests/fast/dom/Node/normalize.html new file mode 100644 index 0000000..a8b61cb --- /dev/null +++ b/LayoutTests/fast/dom/Node/normalize.html @@ -0,0 +1,213 @@ +<html> + +<head> + +<title>Test of DOM Node.normalize()</title> + +<script> + +function logLine(message) +{ + var console = document.getElementById("console"); + console.appendChild(document.createTextNode(message)); + console.appendChild(document.createElement('br')); +} + +function log(message) +{ + var console = document.getElementById("console"); + console.appendChild(document.createTextNode(message)); +} + + +function prepare_test1(testDiv) +{ + testDiv.firstChild.splitText(4); + return testDiv.childNodes.length == 2; +} +function check_test1(testDiv) +{ + return testDiv.childNodes.length == 1; +} + +function prepare_test2(testDiv) +{ + testDiv.firstChild.splitText(9); + testDiv.firstChild.splitText(4); + return testDiv.childNodes.length == 3; +} +function check_test2(testDiv) +{ + return testDiv.childNodes.length == 1; +} + +function prepare_test3(testDiv) +{ + testDiv.childNodes[1].splitText(4); + testDiv.childNodes[4].splitText(3); + return testDiv.childNodes.length == 6; +} +function check_test3(testDiv) +{ + return testDiv.childNodes.length == 4; +} + +function prepare_test4(testDiv) +{ + testDiv.childNodes[0].data = ""; + return testDiv.childNodes.length == 1; +} +function check_test4(testDiv) +{ + return testDiv.childNodes.length == 0; +} + +function prepare_test5(testDiv) +{ + testDiv.childNodes[1].data = ""; + return testDiv.childNodes.length == 3; +} +function check_test5(testDiv) +{ + return testDiv.childNodes.length == 2; +} + +function prepare_test6(testDiv) +{ + testDiv.childNodes[0].splitText(0); + testDiv.childNodes[0].splitText(0); + return testDiv.childNodes.length == 3; +} +function check_test6(testDiv) +{ + return testDiv.childNodes.length == 1; +} + +function prepare_test7(testDiv) +{ + testDiv.childNodes[0].splitText(4); + testDiv.childNodes[0].splitText(4); + testDiv.childNodes[0].splitText(4); + return testDiv.childNodes.length == 4; +} +function check_test7(testDiv) +{ + return testDiv.childNodes.length == 1; +} + +function prepare_test8(testDiv) +{ + testDiv.childNodes[0].splitText(4); + testDiv.childNodes[0].splitText(4); + return testDiv.childNodes.length == 3; +} +function check_test8(testDiv) +{ + return testDiv.childNodes.length == 1; +} + +function prepare_test9(testDiv) +{ + testDiv.childNodes[1].splitText(4); + testDiv.childNodes[1].splitText(0); // empty text node before other text nodes + testDiv.childNodes[5].splitText(3); + testDiv.childNodes[5].splitText(3); // empty text node between other text nodes + testDiv.childNodes[7].splitText(2); // empty text node after other text nodes + return testDiv.childNodes.length == 9; +} +function check_test9(testDiv) +{ + return testDiv.childNodes.length == 4; +} + +function prepare_test10(testDiv) +{ + testDiv.childNodes[0].childNodes[0].splitText(2); + testDiv.childNodes[1].splitText(4); + testDiv.childNodes[3].childNodes[0].data = ""; // empty first text node of the second bold node + testDiv.childNodes[3].childNodes[1].childNodes[0].data = ""; // empty text node of the italic node + testDiv.childNodes[4].splitText(1); + return testDiv.childNodes.length == 6; +} +function check_test10(testDiv) +{ + return testDiv.childNodes.length == 4 + && testDiv.childNodes[0].childNodes.length == 1 // first bold node must have single text node child + && testDiv.childNodes[2].childNodes.length == 1 // first bold node must have single italic node child + && testDiv.childNodes[2].childNodes[0].childNodes.length == 0; // italic node must be empty +} + +function runTest(testDiv, testName) +{ + if (self["prepare_"+testName](testDiv)) { + var oldHTML = testDiv.innerHTML; + testDiv.normalize(); + if (testDiv.innerHTML != oldHTML) { + log("FAILED: innerHTML changed from \"" + oldHTML + "\" to \"" + testDiv.innerHTML + "\""); + } else { + if (self["check_"+testName](testDiv)) + log("PASSED"); + else + log("FAILED"); + } + } else { + log("FAILED in test preparation"); + } +} + +function runTests() +{ + if (window.layoutTestController) + layoutTestController.dumpAsText(); + + try { + var tests = document.getElementById("tests").childNodes; + for (i = 0; i < tests.length; i++) { + var testDiv = tests[i]; + // Skip formatting text nodes + if (testDiv.nodeType == Node.ELEMENT_NODE) { + var testName = testDiv.getAttribute("name"); + + log(testName + " (" + testDiv.getAttribute("description") + "): "); + + try { + runTest(testDiv, testName); + } catch(e) { + log("FAILED with exception: " + e); + } + + logLine("") + } + } + + } catch(e) { + logLine("FAILED, exception thrown during tests: " + e); + } +} + +</script> + +</head> + +<body onload="runTests()"> + +<div id="description">Several tests of the DOM normalize() function.</div> + +<div id="tests" style="display:none"> + <div name="test1" description="two non-empty text nodes">some text</div> + <div name="test2" description="three non-empty text nodes">some more text</div> + <div name="test3" description="non-empty text nodes mixed with elements"><b></b>some more<b></b> text</div> + <div name="test4" description="single empty text node">text</div> + <div name="test5" description="empty text node between elements"><b></b>text<i></i></div> + <div name="test6" description="empty text nodes before non-empty node">text</div> + <div name="test7" description="empty text nodes after non-empty node">text</div> + <div name="test8" description="empty text nodes between non-empty nodes">some text</div> + <div name="test9" description="empty and non-empty text nodes mixed with elements"><b></b>some more<b></b> text</div> + <div name="test10" description="mixed cases including deeper nested text nodes"><b>text</b>text <b>text<i>text</i></b> text</div> +</div> + +<div id="console"></div> + +</body> + +</html> diff --git a/LayoutTests/fast/dom/Node/script-tests/DOMNodeRemovedEvent.js b/LayoutTests/fast/dom/Node/script-tests/DOMNodeRemovedEvent.js new file mode 100644 index 0000000..a149c1d --- /dev/null +++ b/LayoutTests/fast/dom/Node/script-tests/DOMNodeRemovedEvent.js @@ -0,0 +1,12 @@ +description("This test checks that DOMNodeRemovedEvent is emitted once (and only once)."); + +var div = document.createElement("div"); +document.body.appendChild(div); + +var count = 0; +document.body.addEventListener("DOMNodeRemoved", function () { count++; }, false); +document.body.removeChild(div); + +shouldBe("count", "1"); + +var successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Node/script-tests/TEMPLATE.html b/LayoutTests/fast/dom/Node/script-tests/TEMPLATE.html new file mode 100644 index 0000000..1951c43 --- /dev/null +++ b/LayoutTests/fast/dom/Node/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/Node/script-tests/initial-values.js b/LayoutTests/fast/dom/Node/script-tests/initial-values.js new file mode 100644 index 0000000..4dfc376 --- /dev/null +++ b/LayoutTests/fast/dom/Node/script-tests/initial-values.js @@ -0,0 +1,205 @@ +description("Test creation of each type of Node and check intial values") + +var xmlDoc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null); + +debug("Attribute creation using createElement on an HTML doc:") +var attr = document.createAttribute("foo"); +shouldBe("attr.nodeName", "'foo'"); +shouldBe("attr.name", "'foo'"); +// Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createAttribute +// Both FF and WebKit return "foo" for Attribute.localName, even though the spec says null +shouldBe("attr.localName", "null"); +shouldBe("attr.namespaceURI", "null"); +shouldBe("attr.prefix", "null"); +shouldBe("attr.nodeValue", "''"); +shouldBe("attr.value", "''"); +shouldBe("attr.attributes", "null"); + +debug("Attribute creation using createElementNS on an HTML doc:") +attr = document.createAttributeNS("http://www.example.com", "example:foo"); +shouldBe("attr.nodeName", "'example:foo'"); +shouldBe("attr.name", "'example:foo'"); +shouldBe("attr.localName", "'foo'"); +shouldBe("attr.namespaceURI", "'http://www.example.com'"); +shouldBe("attr.prefix", "'example'"); +shouldBe("attr.nodeValue", "''"); +shouldBe("attr.value", "''"); +shouldBe("attr.attributes", "null"); + +debug("Attribute creation using createElement on an XHTML doc:") +attr = xmlDoc.createAttribute("foo"); +shouldBe("attr.nodeName", "'foo'"); +shouldBe("attr.name", "'foo'"); +// Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createAttribute +// Both FF and WebKit return "foo" for Attribute.localName, even though the spec says null +shouldBe("attr.localName", "null"); +shouldBe("attr.namespaceURI", "null"); +shouldBe("attr.prefix", "null"); +shouldBe("attr.nodeValue", "''"); +shouldBe("attr.value", "''"); +shouldBe("attr.attributes", "null"); + +debug("Attribute creation using createElementNS on an XHTML doc:") +attr = xmlDoc.createAttributeNS("http://www.example.com", "example:foo"); +shouldBe("attr.nodeName", "'example:foo'"); +shouldBe("attr.name", "'example:foo'"); +shouldBe("attr.localName", "'foo'"); +shouldBe("attr.namespaceURI", "'http://www.example.com'"); +shouldBe("attr.prefix", "'example'"); +shouldBe("attr.nodeValue", "''"); +shouldBe("attr.value", "''"); +shouldBe("attr.attributes", "null"); + +var comment = document.createComment("foo"); +shouldBe("comment.nodeName", "'#comment'"); +shouldBe("comment.localName", "null"); +shouldBe("comment.namespaceURI", "null"); +shouldBe("comment.prefix", "null"); +shouldBe("comment.nodeValue", "'foo'"); +shouldBe("comment.data", "'foo'"); +shouldBe("comment.attributes", "null"); + +shouldThrow("document.createCDATASection('foo')"); +var cdata = xmlDoc.createCDATASection("foo"); +shouldBe("cdata.nodeName", "'#cdata-section'"); +shouldBe("cdata.localName", "null"); +shouldBe("cdata.namespaceURI", "null"); +shouldBe("cdata.prefix", "null"); +shouldBe("cdata.nodeValue", "'foo'"); +shouldBe("cdata.data", "'foo'"); +shouldBe("cdata.attributes", "null"); + +var fragment = document.createDocumentFragment(); +shouldBe("fragment.nodeName", "'#document-fragment'"); +shouldBe("fragment.localName", "null"); +shouldBe("fragment.namespaceURI", "null"); +shouldBe("fragment.prefix", "null"); +shouldBe("fragment.nodeValue", "null"); +shouldBe("fragment.attributes", "null"); + +var doc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null); +shouldBe("doc.nodeName", "'#document'"); +shouldBe("doc.localName", "null"); +// Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocument +// Currently both FF and WebKit return null here, disagreeing with the spec +shouldBe("doc.namespaceURI", "'http://www.w3.org/1999/xhtml'"); +shouldBe("doc.prefix", "null"); +shouldBe("doc.nodeValue", "null"); +shouldBe("doc.attributes", "null"); + +var doctype = document.implementation.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"); +shouldBe("doctype.nodeName", "'svg'"); +shouldBe("doctype.name", "'svg'"); +shouldBe("doctype.localName", "null"); +shouldBe("doctype.namespaceURI", "null"); +shouldBe("doctype.prefix", "null"); +shouldBe("doctype.nodeValue", "null"); +shouldBe("doctype.attributes", "null"); + +debug("Element creation using createElement on an HTML doc:") +var element = document.createElement("pre"); +shouldBe("element.nodeName", "'PRE'"); +// Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createElement +// FF returns "PRE" for localName, WebKit returns "pre", the spec says we should return null +shouldBe("element.localName", "null"); +// FF returns null for namespaceURI, WebKit returns http://www.w3.org/1999/xhtml, the spec says we should return null +shouldBe("element.namespaceURI", "null"); +shouldBe("element.prefix", "null"); +shouldBe("element.nodeValue", "null"); +shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); + +debug("Prefixed element creation using createElementNS on an HTML doc:") +element = document.createElementNS("http://www.w3.org/1999/xhtml", "html:pre"); +shouldBe("element.nodeName", "'html:pre'"); +shouldBe("element.localName", "'pre'"); +shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'"); +shouldBe("element.prefix", "'html'"); +shouldBe("element.nodeValue", "null"); +shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); + +debug("SVG Element creation using createElementNS on an HTML doc:") +element = document.createElementNS("http://www.w3.org/2000/svg", "svg"); +shouldBe("element.nodeName", "'svg'"); +shouldBe("element.localName", "'svg'"); +shouldBe("element.namespaceURI", "'http://www.w3.org/2000/svg'"); +shouldBe("element.prefix", "null"); +shouldBe("element.nodeValue", "null"); +shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); + +debug("Unknown Element creation using createElementNS on an HTML doc:") +element = document.createElementNS("http://www.webkit.org", "foo:svg"); +shouldBe("element.nodeName", "'foo:svg'"); +shouldBe("element.localName", "'svg'"); +shouldBe("element.namespaceURI", "'http://www.webkit.org'"); +shouldBe("element.prefix", "'foo'"); +shouldBe("element.nodeValue", "null"); +shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); + +debug("Element creation using createElementNS on an HTML doc:") +element = document.createElementNS("http://www.w3.org/1999/xhtml", "pre"); +// Spec: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-104682815 (element.tagName) +// FF and Opera returns "pre" for nodeName as it is an XHTML element, WebKit returns "PRE". +shouldBe("element.nodeName", "'pre'"); +shouldBe("element.localName", "'pre'"); +shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'"); +shouldBe("element.prefix", "null"); +shouldBe("element.nodeValue", "null"); +shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); + +debug("Element creation using createElement on an XHTML doc:") +element = xmlDoc.createElement("pre"); +shouldBe("element.nodeName", "'pre'"); +shouldBe("element.localName", "null"); +// FF returns null for namespaceURI, WebKit returns http://www.w3.org/1999/xhtml, the spec says we should return null +shouldBe("element.namespaceURI", "null"); +shouldBe("element.prefix", "null"); +shouldBe("element.nodeValue", "null"); +shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); + +debug("Element creation using createElementNS on an XHTML doc:") +element = xmlDoc.createElementNS("http://www.w3.org/1999/xhtml", "html:pre"); +shouldBe("element.nodeName", "'html:pre'"); +shouldBe("element.localName", "'pre'"); +shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'"); +shouldBe("element.prefix", "'html'"); +shouldBe("element.nodeValue", "null"); +shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); + +// Not possible to create Entity nodes via the DOM, WebKit doesn't create them from parsing + +shouldThrow("document.createEntityReference('gt')"); +var entityReference = xmlDoc.createEntityReference("gt"); +shouldBe("entityReference.nodeName", "'gt'"); +shouldBe("entityReference.localName", "null"); +shouldBe("entityReference.namespaceURI", "null"); +shouldBe("entityReference.prefix", "null"); +shouldBe("entityReference.nodeValue", "null"); +shouldBe("entityReference.attributes", "null"); + +// Not possible to create Notation nodes via the DOM, WebKit doesn't create them from parsing + +shouldThrow("document.createProcessingInstruction('xml-stylesheet', 'type=\"text/xsl\" href=\"missing.xsl\"')"); +var processingInstruction = xmlDoc.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"'); +shouldBe("processingInstruction.nodeName", "'xml-stylesheet'"); +shouldBe("processingInstruction.localName", "null"); +shouldBe("processingInstruction.namespaceURI", "null"); +shouldBe("processingInstruction.prefix", "null"); +// DOM Core Level 2 and DOM Core Level 3 disagree on ProcessingInstruction.nodeValue +// L2: entire content excluding the target +// L3: same as ProcessingInstruction.data +// We're following Level 3 +shouldBe("processingInstruction.nodeValue", "'type=\"text/xsl\" href=\"missing.xsl\"'"); +shouldBe("processingInstruction.attributes", "null"); +shouldBe("processingInstruction.target", "'xml-stylesheet'"); +shouldBe("processingInstruction.data", "'type=\"text/xsl\" href=\"missing.xsl\"'"); + +var text = document.createTextNode("foo"); +shouldBe("text.nodeName", "'#text'"); +shouldBe("text.localName", "null"); +shouldBe("text.namespaceURI", "null"); +shouldBe("text.prefix", "null"); +shouldBe("text.nodeValue", "'foo'"); +shouldBe("text.data", "'foo'"); +shouldBe("text.attributes", "null"); + +var successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Node/script-tests/isEqualNode.js b/LayoutTests/fast/dom/Node/script-tests/isEqualNode.js new file mode 100644 index 0000000..c56199b --- /dev/null +++ b/LayoutTests/fast/dom/Node/script-tests/isEqualNode.js @@ -0,0 +1,13 @@ +description("Test the isEqualNode API."); + +debug("Test isEqualNode for DocumentType nodes."); +var docTypeAllSet = document.implementation.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); +var docTypeAllSet2 = document.implementation.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); +var docTypeDifferentPublicID = document.implementation.createDocumentType('html', 'foo', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); +var docTypeDifferentSystemID = document.implementation.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'bar'); + +shouldBeTrue("docTypeAllSet.isEqualNode(docTypeAllSet2)"); +shouldBeFalse("docTypeAllSet.isEqualNode(docTypeDifferentPublicID)"); +shouldBeFalse("docTypeAllSet.isEqualNode(docTypeDifferentSystemID)"); + +var successfullyParsed = true; diff --git a/LayoutTests/fast/dom/Node/script-tests/normalize-with-cdata.js b/LayoutTests/fast/dom/Node/script-tests/normalize-with-cdata.js new file mode 100644 index 0000000..d1e3efe --- /dev/null +++ b/LayoutTests/fast/dom/Node/script-tests/normalize-with-cdata.js @@ -0,0 +1,22 @@ +description('Test of normalize on an XML document with CDATA.'); + +var parser = new DOMParser(); +var serializer = new XMLSerializer(); + +var xmlChunk = parser.parseFromString( + '<foo>' + + 'This is some text before the CDATA' + + '<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>' + + 'This is some text after the CDATA' + + '</foo>', + 'application/xml'); + +debug('Before normalize'); +shouldBe('serializer.serializeToString(xmlChunk)', '"<foo>This is some text before the CDATA<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>This is some text after the CDATA</foo>"'); +shouldBe('xmlChunk.documentElement.childNodes.length', '3'); +xmlChunk.documentElement.normalize(); +debug('After normalize'); +shouldBe('serializer.serializeToString(xmlChunk)', '"<foo>This is some text before the CDATA<![CDATA[This is some <bold>markup</bold> inside of a CDATA]]>This is some text after the CDATA</foo>"'); +shouldBe('xmlChunk.documentElement.childNodes.length', '3'); + +var successfullyParsed = true; |