Title: [140631] trunk
Revision
140631
Author
[email protected]
Date
2013-01-23 18:31:35 -0800 (Wed, 23 Jan 2013)

Log Message

Template element should parse in XHTML just as it does in HTML
https://bugs.webkit.org/show_bug.cgi?id=106491

Reviewed by Ryosuke Niwa.

Source/WebCore:

https://dvcs.w3.org/hg/webcomponents/raw-file/f33622c39c5e/spec/templates/index.html#parsing-xhtml-documents.
https://dvcs.w3.org/hg/webcomponents/raw-file/f33622c39c5e/spec/templates/index.html#serializing-xhtml-documents.

This patch modifies the XML parser in two ways: (1) when nodes are created, their owner document is
the owner document of the current node, rather than the containing document, and (2) when an HTMLTemplateElement
is encountered, its content document fragment is pushed onto the stack, rather than the element itself, so that children
are appended to the template content. Also, because XSLT operates on the serialized input document, transforms consider
template contents to be descendants.

Tests: fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml
       fast/xpath/xpath-template-element.html
       fast/xsl/xslt-processor-template.html
       fast/xsl/xslt-xhtml-template.xml

* xml/parser/XMLDocumentParser.cpp:
(WebCore::XMLDocumentParser::enterText):
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::startElementNs):
(WebCore::XMLDocumentParser::processingInstruction):
(WebCore::XMLDocumentParser::cdataBlock):
(WebCore::XMLDocumentParser::comment):

LayoutTests:

* fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization-expected.txt: Added.
* fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml: Added.
* fast/xpath/xpath-template-element-expected.txt: Added.
* fast/xpath/xpath-template-element.html: Added.
* fast/xsl/resources/xhtml-template.xsl: Added.
* fast/xsl/xslt-processor-template-expected.txt: Added.
* fast/xsl/xslt-processor-template.html: Added.
* fast/xsl/xslt-xhtml-template-expected.txt: Added.
* fast/xsl/xslt-xhtml-template.xml: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (140630 => 140631)


--- trunk/LayoutTests/ChangeLog	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/LayoutTests/ChangeLog	2013-01-24 02:31:35 UTC (rev 140631)
@@ -1,3 +1,20 @@
+2013-01-23  Rafael Weinstein  <[email protected]>
+
+        Template element should parse in XHTML just as it does in HTML
+        https://bugs.webkit.org/show_bug.cgi?id=106491
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization-expected.txt: Added.
+        * fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml: Added.
+        * fast/xpath/xpath-template-element-expected.txt: Added.
+        * fast/xpath/xpath-template-element.html: Added.
+        * fast/xsl/resources/xhtml-template.xsl: Added.
+        * fast/xsl/xslt-processor-template-expected.txt: Added.
+        * fast/xsl/xslt-processor-template.html: Added.
+        * fast/xsl/xslt-xhtml-template-expected.txt: Added.
+        * fast/xsl/xslt-xhtml-template.xml: Added.
+
 2013-01-23  Yoshifumi Inoue  <[email protected]>
 
         Unreviewew. Rebaseline for Chromium: fast/ruby/select-ruby.html

Added: trunk/LayoutTests/fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization-expected.txt (0 => 140631)


--- trunk/LayoutTests/fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization-expected.txt	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,3 @@
+This tests that content within template is lifted to the template contents when parsed as xhtml.
+The template content made it through the wormhole
+<template xmlns="http://www.w3.org/1999/xhtml"><div>Template content</div></template>

Added: trunk/LayoutTests/fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml (0 => 140631)


--- trunk/LayoutTests/fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,25 @@
+<!DOCTYPE html 
+     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xml:lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
+    <body>
+        <template><div>Template content</div></template>
+        <span>This tests that content within template is lifted to the template contents when parsed as xhtml.</span>
+        <div id="output">
+        </div>
+        <div id="serialization">
+        </div>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var output = document.getElementById("output");
+var template = document.querySelector("template");
+if (template.content.childNodes.length > template.childNodes.length)
+  output.textContent = "The template content made it through the wormhole\n";
+
+var serialization = document.getElementById("serialization");
+serialization.textContent = new XMLSerializer().serializeToString(template);
+</script>
+    </body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/xpath/xpath-template-element-expected.txt (0 => 140631)


--- trunk/LayoutTests/fast/xpath/xpath-template-element-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/xpath/xpath-template-element-expected.txt	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,8 @@
+This tests that XPath expressions do not consider (traverse into) template content
+
+A B
+PASS document.evaluate('count(//span)', test, null, XPathResult.NUMBER_TYPE, null).numberValue is 2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/xpath/xpath-template-element.html (0 => 140631)


--- trunk/LayoutTests/fast/xpath/xpath-template-element.html	                        (rev 0)
+++ trunk/LayoutTests/fast/xpath/xpath-template-element.html	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p>This tests that XPath expressions do not consider (traverse into) template content</p>
+
+<div id=test>
+    <span>A</span>
+    <span>B</span>
+    <template>
+        <span>C</span>
+        <span>D</span>
+    </template>
+</div>
+
+<div id="console"></div>
+<script>
+var test = document.getElementById('test');
+var result = document.evaluate('count(//span)', test, null, XPathResult.NUMBER_TYPE, null);
+shouldBe("document.evaluate('count(//span)', test, null, XPathResult.NUMBER_TYPE, null).numberValue", "2");
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/xsl/resources/xhtml-template.xsl (0 => 140631)


--- trunk/LayoutTests/fast/xsl/resources/xhtml-template.xsl	                        (rev 0)
+++ trunk/LayoutTests/fast/xsl/resources/xhtml-template.xsl	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,46 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xhtml="http://www.w3.org/1999/xhtml"
+    xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xhtml xsl xs">
+    <xsl:output method="xml" omit-xml-declaration="yes"/>
+    <xsl:template match="xhtml:html">
+        <html>
+            <body>
+                <template>
+                    <xsl:apply-templates select="//xhtml:body/xhtml:span" />
+                </template>
+                <xsl:apply-templates select="//xhtml:template//xhtml:span" />
+                <p>This tests that XSLT transforms can traverse into XHTML template element content when applying XSL template.
+                   If the test succeeds, the transform will have swapped the position of the body spans (A and B) with the template content spans (C and D)
+                   and replaced the spans with divs.</p>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+function divChildTextNodes(parent) {
+    var output = '';
+
+    for (var child = parent.firstChild; child; child = child.nextSibling) {
+        if (child.tagName == 'div') {
+            output += child.textContent;
+        }
+    }
+
+    return output;
+}
+
+var span = document.body.appendChild(document.createElement('span'));
+span.textContent = 'Body divs: ' + divChildTextNodes(document.body);
+
+span = document.body.appendChild(document.createElement('span'));
+var template = document.querySelector('template');
+span.textContent = ', Template content divs: ' + divChildTextNodes(template.content);
+</script>
+            </body>
+        </html>
+    </xsl:template>
+    <xsl:template match="xhtml:span">
+        <div><xsl:value-of select="text()" /></div>
+    </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file

Added: trunk/LayoutTests/fast/xsl/xslt-processor-template-expected.txt (0 => 140631)


--- trunk/LayoutTests/fast/xsl/xslt-processor-template-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/xsl/xslt-processor-template-expected.txt	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,3 @@
+This tests that XSLT transforms can traverse into XHTML template element content when applying XSL template. If the test succeeds, the transform will have swapped the position of the body spans (A and B) with the template content spans (C and D) and replaced the spans with divs.
+
+Body divs: CD, Template content divs: AB

Added: trunk/LayoutTests/fast/xsl/xslt-processor-template.html (0 => 140631)


--- trunk/LayoutTests/fast/xsl/xslt-processor-template.html	                        (rev 0)
+++ trunk/LayoutTests/fast/xsl/xslt-processor-template.html	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,53 @@
+<html>
+<head>
+</head>
+<body id="body">
+<p>This tests that XSLT transforms can traverse into XHTML template element content when applying XSL template.
+If the test succeeds, the transform will have swapped the position of the body spans (A and B) with the template content spans (C and D)
+and replaced the spans with divs.</p>
+<script>
+if (window.testRunner)
+	testRunner.dumpAsText();
+
+var requester = new XMLHttpRequest();
+var processor = new XSLTProcessor();
+var serializer = new XMLSerializer();
+
+function getXMLDocument(name)
+{
+	requester.open("GET", name, false);
+	requester.send(null);
+	return requester.responseXML;
+}
+
+function addStringResult(text)
+{
+	document.writeln("<span>" + text + "</span>");
+}
+
+function divChildTextNodes(parent) {
+    var output = '';
+
+    for (var child = parent.firstChild; child; child = child.nextSibling) {
+        if (child.tagName == 'div') {
+            output += child.textContent;
+        }
+    }
+
+    return output;
+}
+
+var xml = getXMLDocument("xslt-xhtml-template.xml");
+var xsl = getXMLDocument("resources/xhtml-template.xsl");
+
+processor.importStylesheet(xsl);
+
+var ownerDocument = document.implementation.createDocument("", "test", null);
+var frag = processor.transformToFragment(xml, ownerDocument);
+
+addStringResult('Body divs: ' + divChildTextNodes(frag.querySelector('body')) + 
+                ', Template content divs: ' + divChildTextNodes(frag.querySelector('template').content));
+
+</script>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/xsl/xslt-xhtml-template-expected.txt (0 => 140631)


--- trunk/LayoutTests/fast/xsl/xslt-xhtml-template-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/xsl/xslt-xhtml-template-expected.txt	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,5 @@
+C
+D
+This tests that XSLT transforms can traverse into XHTML template element content when applying XSL template. If the test succeeds, the transform will have swapped the position of the body spans (A and B) with the template content spans (C and D) and replaced the spans with divs.
+
+Body divs: CD, Template content divs: AB

Added: trunk/LayoutTests/fast/xsl/xslt-xhtml-template.xml (0 => 140631)


--- trunk/LayoutTests/fast/xsl/xslt-xhtml-template.xml	                        (rev 0)
+++ trunk/LayoutTests/fast/xsl/xslt-xhtml-template.xml	2013-01-24 02:31:35 UTC (rev 140631)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<?xml-stylesheet href="" type="text/xsl"?>
+
+<!DOCTYPE html 
+     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xml:lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
+    <body>
+        <span>A</span>
+        <span>B</span>
+        <template>
+            <span>C</span>
+            <span>D</span>
+        </template>
+    </body>
+</html>
\ No newline at end of file

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (140630 => 140631)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2013-01-24 02:31:35 UTC (rev 140631)
@@ -91,6 +91,13 @@
 # ENABLE(DRAGGABLE_REGION) is disabled
 fast/css/draggable-region-parser.html [ WontFix ]
 
+# ENABLE(TEMPLATE_ELEMENT) is disabled.
+webkit.org/b/103547 fast/dom/HTMLTemplateElement [ Skip ]
+webkit.org/b/103547 html5lib/run-template.html [ Skip ]
+webkit.org/b/103547 fast/xsl/xslt-xhtml-template.xml [ Skip ]
+webkit.org/b/103547 fast/xpath/xpath-template-element.html [ Skip ]
+webkit.org/b/103547 fast/xsl/xslt-processor-template.html [ Skip ]
+
 # These test -apple- and -khtml- prefixed CSS properties, which we don't support.
 inspector/styles/vendor-prefixes.html [ WontFix ]
 fast/css/apple-prefix.html [ WontFix ]

Modified: trunk/LayoutTests/platform/mac/TestExpectations (140630 => 140631)


--- trunk/LayoutTests/platform/mac/TestExpectations	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2013-01-24 02:31:35 UTC (rev 140631)
@@ -432,6 +432,9 @@
 # ENABLE(TEMPLATE_ELEMENT) is disabled.
 fast/dom/HTMLTemplateElement
 html5lib/run-template.html
+fast/xsl/xslt-xhtml-template.xml
+fast/xpath/xpath-template-element.html
+fast/xsl/xslt-processor-template.html
 
 # JSC does not support setIsolatedWorldSecurityOrigin (http://webkit.org/b/61540)
 http/tests/security/isolatedWorld/cross-origin-xhr.html

Modified: trunk/LayoutTests/platform/qt/TestExpectations (140630 => 140631)


--- trunk/LayoutTests/platform/qt/TestExpectations	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/LayoutTests/platform/qt/TestExpectations	2013-01-24 02:31:35 UTC (rev 140631)
@@ -195,6 +195,9 @@
 # ENABLE(TEMPLATE_ELEMENT) is disabled.
 fast/dom/HTMLTemplateElement
 html5lib/run-template.html
+fast/xsl/xslt-xhtml-template.xml
+fast/xpath/xpath-template-element.html
+fast/xsl/xslt-processor-template.html
 
 # Fail until SUBPIXEL_LAYOUT is enabled
 # https://bugs.webkit.org/show_bug.cgi?id=85532

Modified: trunk/LayoutTests/platform/win/TestExpectations (140630 => 140631)


--- trunk/LayoutTests/platform/win/TestExpectations	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/LayoutTests/platform/win/TestExpectations	2013-01-24 02:31:35 UTC (rev 140631)
@@ -1537,6 +1537,9 @@
 # ENABLE(TEMPLATE_ELEMENT) is disabled.
 fast/dom/HTMLTemplateElement
 html5lib/run-template.html
+fast/xsl/xslt-xhtml-template.xml
+fast/xpath/xpath-template-element.html
+fast/xsl/xslt-processor-template.html
 
 # CSS Regions support not yet enabled. http://webkit.org/b/57312
 fast/regions

Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (140630 => 140631)


--- trunk/LayoutTests/platform/wincairo/TestExpectations	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations	2013-01-24 02:31:35 UTC (rev 140631)
@@ -2066,6 +2066,9 @@
 # ENABLE(TEMPLATE_ELEMENT) is disabled.
 fast/dom/HTMLTemplateElement
 html5lib/run-template.html
+fast/xsl/xslt-xhtml-template.xml
+fast/xpath/xpath-template-element.html
+fast/xsl/xslt-processor-template.html
 
 # CSS Regions support not yet enabled. http://webkit.org/b/57312
 fast/regions

Modified: trunk/Source/WebCore/ChangeLog (140630 => 140631)


--- trunk/Source/WebCore/ChangeLog	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/Source/WebCore/ChangeLog	2013-01-24 02:31:35 UTC (rev 140631)
@@ -1,3 +1,32 @@
+2013-01-23  Rafael Weinstein  <[email protected]>
+
+        Template element should parse in XHTML just as it does in HTML
+        https://bugs.webkit.org/show_bug.cgi?id=106491
+
+        Reviewed by Ryosuke Niwa.
+
+        https://dvcs.w3.org/hg/webcomponents/raw-file/f33622c39c5e/spec/templates/index.html#parsing-xhtml-documents.
+        https://dvcs.w3.org/hg/webcomponents/raw-file/f33622c39c5e/spec/templates/index.html#serializing-xhtml-documents.
+
+        This patch modifies the XML parser in two ways: (1) when nodes are created, their owner document is
+        the owner document of the current node, rather than the containing document, and (2) when an HTMLTemplateElement
+        is encountered, its content document fragment is pushed onto the stack, rather than the element itself, so that children
+        are appended to the template content. Also, because XSLT operates on the serialized input document, transforms consider
+        template contents to be descendants.
+
+        Tests: fast/dom/HTMLTemplateElement/xhtml-parsing-and-serialization.xml
+               fast/xpath/xpath-template-element.html
+               fast/xsl/xslt-processor-template.html
+               fast/xsl/xslt-xhtml-template.xml
+
+        * xml/parser/XMLDocumentParser.cpp:
+        (WebCore::XMLDocumentParser::enterText):
+        * xml/parser/XMLDocumentParserLibxml2.cpp:
+        (WebCore::XMLDocumentParser::startElementNs):
+        (WebCore::XMLDocumentParser::processingInstruction):
+        (WebCore::XMLDocumentParser::cdataBlock):
+        (WebCore::XMLDocumentParser::comment):
+
 2013-01-23  Tony Gentilcore  <[email protected]>
 
         Teach threaded HTML parser to update InspectorInstrumentation when writing HTML

Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp (140630 => 140631)


--- trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp	2013-01-24 02:31:35 UTC (rev 140631)
@@ -146,7 +146,7 @@
     ASSERT(m_bufferedText.size() == 0);
 #endif
     ASSERT(!m_leafTextNode);
-    m_leafTextNode = Text::create(document(), "");
+    m_leafTextNode = Text::create(m_currentNode->document(), "");
     m_currentNode->parserAppendChild(m_leafTextNode.get());
 }
 

Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp (140630 => 140631)


--- trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp	2013-01-24 02:27:58 UTC (rev 140630)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp	2013-01-24 02:31:35 UTC (rev 140631)
@@ -42,6 +42,7 @@
 #include "HTMLLinkElement.h"
 #include "HTMLNames.h"
 #include "HTMLStyleElement.h"
+#include "HTMLTemplateElement.h"
 #include "ProcessingInstruction.h"
 #include "ResourceError.h"
 #include "ResourceHandle.h"
@@ -789,7 +790,7 @@
     m_sawFirstElement = true;
 
     QualifiedName qName(prefix, localName, uri);
-    RefPtr<Element> newElement = document()->createElement(qName, true);
+    RefPtr<Element> newElement = m_currentNode->document()->createElement(qName, true);
     if (!newElement) {
         stopParsing();
         return;
@@ -819,7 +820,15 @@
 
     m_currentNode->parserAppendChild(newElement.get());
 
+#if ENABLE(TEMPLATE_ELEMENT)
+    if (newElement->hasTagName(HTMLNames::templateTag))
+        pushCurrentNode(toHTMLTemplateElement(newElement.get())->content());
+    else
+        pushCurrentNode(newElement.get());
+#else
     pushCurrentNode(newElement.get());
+#endif
+
     if (m_view && !newElement->attached())
         newElement->attach();
 
@@ -962,7 +971,7 @@
 
     // ### handle exceptions
     ExceptionCode ec = 0;
-    RefPtr<ProcessingInstruction> pi = document()->createProcessingInstruction(
+    RefPtr<ProcessingInstruction> pi = m_currentNode->document()->createProcessingInstruction(
         toString(target), toString(data), ec);
     if (ec)
         return;
@@ -996,7 +1005,7 @@
 
     exitText();
 
-    RefPtr<CDATASection> newNode = CDATASection::create(document(), toString(s, len));
+    RefPtr<CDATASection> newNode = CDATASection::create(m_currentNode->document(), toString(s, len));
     m_currentNode->parserAppendChild(newNode.get());
     if (m_view && !newNode->attached())
         newNode->attach();
@@ -1014,7 +1023,7 @@
 
     exitText();
 
-    RefPtr<Comment> newNode = Comment::create(document(), toString(s));
+    RefPtr<Comment> newNode = Comment::create(m_currentNode->document(), toString(s));
     m_currentNode->parserAppendChild(newNode.get());
     if (m_view && !newNode->attached())
         newNode->attach();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to