Safari 4.0 treats CDATA and Text nodes seperately, but it still merges them when Node#normalize() is called, breaking XMLTest. This method fixes the test and adds a comment to Node#normalize() explaining this behavior.
Patch by: jlabanca
Review by: jgw (desk)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6057 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/xml/client/Node.java b/user/src/com/google/gwt/xml/client/Node.java
index 8f4491c..9ab2cde 100644
--- a/user/src/com/google/gwt/xml/client/Node.java
+++ b/user/src/com/google/gwt/xml/client/Node.java
@@ -215,7 +215,8 @@
/**
* This method may collapse adjacent text nodes into one text node, depending
- * on the implementation.
+ * on the implementation. Safari 4.0 and Chrome will also merge CDATA nodes
+ * into text nodes, even though they support CDATA nodes as distinct nodes.
*/
void normalize();
diff --git a/user/test/com/google/gwt/xml/client/XMLTest.java b/user/test/com/google/gwt/xml/client/XMLTest.java
index d0d865e..3730173 100644
--- a/user/test/com/google/gwt/xml/client/XMLTest.java
+++ b/user/test/com/google/gwt/xml/client/XMLTest.java
@@ -124,13 +124,16 @@
top.getFirstChild().getFirstChild().appendChild(deep2);
top.appendChild(d.createTextNode("0123456789"));
- top.appendChild(d.createCDATASection("abcdefghij"));
+ top.appendChild(d.createTextNode("abcdefghij"));
+ top.appendChild(d.createElement("e4"));
+ top.appendChild(d.createCDATASection("klmnopqrst"));
return d;
}
/**
* Returns the module name for GWT unit test running.
*/
+ @Override
public String getModuleName() {
return "com.google.gwt.xml.XML";
}
@@ -169,18 +172,18 @@
createProcessingInstruction, createTextNode});
for (int i = 0; i < canHaveChildren.size(); i++) {
- Node parent = (Node) canHaveChildren.get(i);
+ Node parent = canHaveChildren.get(i);
Node cloneParent = parent.cloneNode(false);
if (canBeChildren.contains(parent)) {
d.appendChild(cloneParent);
}
for (int j = 0; j < canBeChildren.size(); j++) {
- Node child = (Node) canBeChildren.get(j);
+ Node child = canBeChildren.get(j);
cloneParent.appendChild(child.cloneNode(false));
}
for (int j = 0; j < canBeChildren.size(); j++) {
Node clonedChild = cloneParent.getChildNodes().item(j);
- Node hopefullySameChild = (Node) canBeChildren.get(j);
+ Node hopefullySameChild = canBeChildren.get(j);
assertEquals(hopefullySameChild.cloneNode(false).toString(),
clonedChild.toString());
}
@@ -441,22 +444,17 @@
assertEquals("t data", t.getData(), "01234");
assertEquals("LeftT data", rightT.getData(), "56789");
CDATASection cd = (CDATASection) d.getDocumentElement().getChildNodes().item(
- 5);
+ 7);
Text rightCD = cd.splitText(5);
assertEquals("cd and leftCd parent equality", cd.getParentNode(),
rightCD.getParentNode());
assertEquals("leftCD.getPreviousSibling", rightCD.getPreviousSibling(), cd);
assertEquals("cd length", cd.getData().length(), 5);
assertEquals("leftCD.length", rightCD.getData().length(), 5);
- assertEquals("cd data", cd.getData(), "abcde");
- assertEquals("leftCD data", rightCD.getData(), "fghij");
+ assertEquals("cd data", cd.getData(), "klmno");
+ assertEquals("leftCD data", rightCD.getData(), "pqrst");
d.getDocumentElement().normalize();
- if (XMLParser.supportsCDATASection()) {
- assertEquals("normalized t", d.getDocumentElement().getChildNodes().item(
- 3).toString(), "0123456789");
- } else {
- assertEquals("normalized t", d.getDocumentElement().getChildNodes().item(
- 3).toString(), "0123456789abcdefghij");
- }
+ assertEquals("normalized t", d.getDocumentElement().getChildNodes().item(
+ 3).toString(), "0123456789abcdefghij");
}
}