Setting document.title should have no effect for non SVG/HTML documents
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Nov 2018 20:42:53 +0000 (20:42 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Nov 2018 20:42:53 +0000 (20:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191643

Patch by Rob Buis <rbuis@igalia.com> on 2018-11-19
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg-expected.txt: Added.
* web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg.html: Added.

Source/WebCore:

Setting document.title should have no effect for non SVG/HTML documents,
see https://html.spec.whatwg.org/multipage/dom.html#document.title.

Behavior matches Firefox and Chrome.

Test: imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg.html

* dom/Document.cpp:
(WebCore::Document::setTitle):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238377 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp

index 4661c54..41c4614 100644 (file)
@@ -1,3 +1,13 @@
+2018-11-19  Rob Buis  <rbuis@igalia.com>
+
+        Setting document.title should have no effect for non SVG/HTML documents
+        https://bugs.webkit.org/show_bug.cgi?id=191643
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg-expected.txt: Added.
+        * web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg.html: Added.
+
 2018-11-18  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
 
         Unreviewed, rolling in the rest of r237254
diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg-expected.txt
new file mode 100644 (file)
index 0000000..689f10f
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS Should not be able to set document title in XML document 
+PASS Should not be able to set document title in XML document with html:title element 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg.html b/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg.html
new file mode 100644 (file)
index 0000000..49a6226
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<link rel="author" title="Rob Buis" href="mailto:rbuis@igalia.com">
+<link rel="help" href="https://html.spec.whatwg.org/multipage/#document.title">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+
+function newXMLDocument() {
+  return document.implementation.createDocument(null, "xml", null);
+}
+
+test(function() {
+  var doc = newXMLDocument();
+  assert_equals(doc.title, "");
+  doc.title = "fail";
+  assert_equals(doc.title, "");
+}, "Should not be able to set document title in XML document");
+
+test(function() {
+  var doc = newXMLDocument();
+  doc.documentElement.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "html:title"));
+  assert_equals(doc.title, "");
+  doc.title = "fail";
+  assert_equals(doc.title, "");
+}, "Should not be able to set document title in XML document with html:title element");
+</script>
index 553f22f..91dcd7d 100644 (file)
@@ -1,3 +1,20 @@
+2018-11-19  Rob Buis  <rbuis@igalia.com>
+
+        Setting document.title should have no effect for non SVG/HTML documents
+        https://bugs.webkit.org/show_bug.cgi?id=191643
+
+        Reviewed by Chris Dumez.
+
+        Setting document.title should have no effect for non SVG/HTML documents,
+        see https://html.spec.whatwg.org/multipage/dom.html#document.title.
+
+        Behavior matches Firefox and Chrome.
+
+        Test: imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-not-in-html-svg.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::setTitle):
+
 2018-11-19  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Dragging image with a border-image larger than the image element crashes
index 4ed10f0..fe01e94 100644 (file)
@@ -1580,33 +1580,23 @@ void Document::updateTitleFromTitleElement()
 
 void Document::setTitle(const String& title)
 {
-    if (!m_titleElement) {
-        if (isHTMLDocument() || isXHTMLDocument()) {
+    auto* element = documentElement();
+    if (is<SVGSVGElement>(element)) {
+        if (!m_titleElement) {
+            m_titleElement = SVGTitleElement::create(SVGNames::titleTag, *this);
+            element->insertBefore(*m_titleElement, element->firstChild());
+        }
+        m_titleElement->setTextContent(title);
+    } else if (is<HTMLElement>(element)) {
+        if (!m_titleElement) {
             auto* headElement = head();
             if (!headElement)
                 return;
             m_titleElement = HTMLTitleElement::create(HTMLNames::titleTag, *this);
             headElement->appendChild(*m_titleElement);
-        } else if (isSVGDocument()) {
-            auto* element = documentElement();
-            if (!is<SVGSVGElement>(element))
-                return;
-            m_titleElement = SVGTitleElement::create(SVGNames::titleTag, *this);
-            element->insertBefore(*m_titleElement, element->firstChild());
         }
-    } else if (!isHTMLDocument() && !isXHTMLDocument() && !isSVGDocument()) {
-        // FIXME: What exactly is the point of this? This seems like a strange moment
-        // in time to demote something from being m_titleElement, when setting the
-        // value of the title attribute. Do we have test coverage for this?
-        m_titleElement = nullptr;
+        m_titleElement->setTextContent(title);
     }
-
-    if (is<HTMLTitleElement>(m_titleElement.get()))
-        downcast<HTMLTitleElement>(*m_titleElement).setTextContent(title);
-    else if (is<SVGTitleElement>(m_titleElement.get()))
-        downcast<SVGTitleElement>(*m_titleElement).setTextContent(title);
-    else
-        updateTitle({ title, TextDirection::LTR });
 }
 
 template<typename> struct TitleTraits;