XMLSerializer should reset default namespace when necessary
https://bugs.webkit.org/show_bug.cgi?id=16739
XMLSerializer's handling of namespaces seems to be pretty broken
https://bugs.webkit.org/show_bug.cgi?id=106531

Reviewed by Ryosuke Niwa.

Source/WebCore:

Write out empty default namespace declaration if the element is not in any namespace, as
described in http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syntax.html#xml-fragment-serialization-algorithm.

Tests: fast/dom/XMLSerializer-element-empty-namespace.html
       fast/dom/XMLSerializer-element-empty-namespace2.html

* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::appendNamespace):
(WebCore::MarkupAccumulator::appendOpenTag):
* editing/MarkupAccumulator.h:

LayoutTests:

Add tests based on the testcases of both bugs.

* fast/dom/XMLSerializer-element-empty-namespace-expected.txt: Added.
* fast/dom/XMLSerializer-element-empty-namespace.html: Added.
* fast/dom/XMLSerializer-element-empty-namespace2-expected.txt: Added.
* fast/dom/XMLSerializer-element-empty-namespace2.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153508 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace.html b/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace.html
new file mode 100644
index 0000000..d694ebd
--- /dev/null
+++ b/LayoutTests/fast/dom/XMLSerializer-element-empty-namespace.html
@@ -0,0 +1,29 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <script type="text/javascript">
+    function runTest()
+    {
+        if (window.testRunner)
+            testRunner.dumpAsText();
+
+        var target = document.getElementById("target");
+
+        var a = document.createElementNS("", "a");
+        a.setAttribute('href', '#');
+
+        target.appendChild(a);
+
+        var serializer = new XMLSerializer();
+        var xmlString = serializer.serializeToString(target);
+
+        var outputText = document.getElementById("output");
+        outputText.textContent = xmlString;
+    }
+    </script>
+</head>
+    <body onload="runTest()">
+This tests that XMLSerializer.serializeToString() correctly writes out an empty default namespace declaration if the element is not in any namespace.
+        <div id="target"/>
+        <div id="output"/>
+    </body>
+</html>