diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/test/test_bug352728.xhtml | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/test_bug352728.xhtml')
-rw-r--r-- | dom/base/test/test_bug352728.xhtml | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/dom/base/test/test_bug352728.xhtml b/dom/base/test/test_bug352728.xhtml new file mode 100644 index 0000000000..b868deb463 --- /dev/null +++ b/dom/base/test/test_bug352728.xhtml @@ -0,0 +1,188 @@ +<html xmlns="http://www.w3.org/1999/xhtml"> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=352728 +--> +<head> + <title>Test for Bug 352728</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<!-- First make sure that a script consisting of multiple CDATA sections is + even supported --> +<script class="testbody" type="text/javascript"> + var cdataTest1 = false; + var cdataTest2 = false; + var cdataTest3 = false; +</script> + +<script class="testbody" type="text/javascript"> +<![CDATA[ + cdataTest1 = true; +]]> + cdataTest2 = true; +<![CDATA[ + cdataTest3 = true; +]]> +</script> + +<script class="testbody" type="text/javascript"> + is(cdataTest1, true, "Check first CDATA section"); + is(cdataTest2, true, "Check in between CDATA sections"); + is(cdataTest3, true, "Check second CDATA section"); +</script> + +<script class="testbody" type="text/javascript"> +<![CDATA[ + +/** Test for Bug 352728 **/ +function checkTypes(aNode, aNodeType, aTypeArray) +{ + for (var i = 0; i < aTypeArray.length; ++i) { + ok( + aNode instanceof aTypeArray[i], + aNodeType + " type test " + i + " - " + + aNodeType + " should be a " + aTypeArray[i] + ); + } +} + +function checkInterfaces(aNode, aNodeType, aInterfaceArray) +{ + for (var i = 0; i < aInterfaceArray.length; ++i) { + ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]], + aNodeType + " interface test " + i + " - " + + aNodeType + " should be a " + aInterfaceArray[i]); + } +} + +function testCharacterData(aNode, aText) +{ + is(aNode.length, aText.length, "Text length should match"); + is(aNode.data, aText, "Text content should match"); + is(aNode.nodeValue, aText, "Check nodeValue"); + is(aNode.localName, undefined, "Check localName") + is(aNode.namespaceURI, undefined, "Check namespaceURI"); +} + +function testComment(aText) +{ + try { + var comment = document.createComment(aText); + var types = [ Comment, CharacterData, Node ]; + checkTypes(comment, "comment", types); + + var interfaces = []; + checkInterfaces(comment, "comment", interfaces); + + testCharacterData(comment, aText); + is(comment.nodeName, "#comment", "Check nodeName"); + is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType"); + } catch (e) { + ok(false, "Correct functioning of comment stuff - something broke: " + e); + } +} + +function testCDATASection(aText, aShouldSucceed) +{ + try { + var cdataSection = document.createCDATASection(aText); + var types = [ CDATASection, CharacterData, Node ]; + checkTypes(cdataSection, "CDATA section", types); + + var interfaces = []; + checkInterfaces(cdataSection, "CDATA section", interfaces); + + testCharacterData(cdataSection, aText); + is(cdataSection.nodeName, "#cdata-section", "Check nodeName"); + is(cdataSection.nodeType, Node.CDATA_SECTION_NODE, "Check nodeType"); + + if (!aShouldSucceed) { + ok(0, "Invalid CDATA section creation - " + +]]> + "Shouldn't create CDATA section with embedded \"]]>\""); +<![CDATA[ + } + } catch (e) { + if (aShouldSucceed) { + ok(false, + "Correct functioning of CDATA section stuff - something broke: " + e); + } else { + is(e.name, "InvalidCharacterError", "Check exception"); + is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code"); + } + } +} + +function testPI(aTarget, aData, aShouldSucceed, aReason) +{ + try { + var pi = document.createProcessingInstruction(aTarget, aData); + var types = [ ProcessingInstruction, Node ]; + checkTypes(pi, "processing instruction", types); + + var interfaces = []; + checkInterfaces(pi, "processing instruction", interfaces); + + is(pi.target, aTarget, "Check target"); + is(pi.data, aData, "Check data"); + is(pi.nodeName, aTarget, "Check nodeName"); + is(pi.nodeValue, aData, "Check nodeValue"); + is(pi.localName, undefined, "Check localName") + is(pi.namespaceURI, undefined, "Check namespaceURI"); + + is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType"); + + if (!aShouldSucceed) { + ok(false, "Invalid processing instruction creation - " + aReason); + } + } catch (e) { + if (aShouldSucceed) { + ok(false, + "Correct functioning of processing instruction stuff - " + + "something broke: " + e); + } else { + is(e.name, "InvalidCharacterError", "Check exception"); + is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code"); + } + } +} + +testComment("Some text"); +testComment("Some text with a '-' in it"); +testComment("Some text with a '-' and a '-' and another '-'"); +testComment("Some text -- this should create a node!"); +testComment("<!-- This is an HTML comment -->"); + +testCDATASection("Some text", true); +testCDATASection("Some text with a '?' in it", true); +testCDATASection("Some text with a '>' in it", true); +testCDATASection("Some text with a '?' and a '>' in it", true); +testCDATASection("Some text with a '? >' in it", true); +testCDATASection("Some text -- ?> this should be ok", true); +]]> +testCDATASection("Some text ]]> this should not create a node!", false); + +<![CDATA[ + +testPI("foo", "bar", true); +testPI("foo:bar", "baz", true); +testPI("foo", "bar?", true); +testPI("foo", "bar>", true); +testPI("foo", "bar? >", true); +testPI("<aaa", "bar", false, "Target should not contain '<'"); +testPI("aaa>", "bar", false, "Target should not contain '>'"); +testPI("aa?", "bar", false, "Target should not contain '?'"); +testPI("foo", "bar?>", false, "Data should not contain '?>'"); +]]> +</script> +</pre> +</body> +</html> + |