Commit 3248501c authored by Rob Buis's avatar Rob Buis Committed by Commit Bot

Setting document.title should have no effect for non SVG/HTML documents

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.

Bug: 906038

Change-Id: I724abf9ecd711536d71ad95ab45c72230c2e87b6
Reviewed-on: https://chromium-review.googlesource.com/c/1339959
Commit-Queue: Rob Buis <rbuis@igalia.com>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609407}
parent c6360e0b
<!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, "foo", 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>
...@@ -1681,31 +1681,25 @@ void Document::DispatchDidReceiveTitle() { ...@@ -1681,31 +1681,25 @@ void Document::DispatchDidReceiveTitle() {
void Document::setTitle(const String& title) { void Document::setTitle(const String& title) {
// Title set by JavaScript -- overrides any title elements. // Title set by JavaScript -- overrides any title elements.
Element* element = documentElement();
if (IsSVGSVGElement(element)) {
if (!title_element_) {
title_element_ = SVGTitleElement::Create(*this);
element->InsertBefore(title_element_.Get(), element->firstChild());
}
if (auto* svg_title = ToSVGTitleElementOrNull(title_element_))
svg_title->SetText(title);
} else if (element && element->IsHTMLElement()) {
if (!title_element_) { if (!title_element_) {
if (IsHTMLDocument() || IsXHTMLDocument()) {
HTMLElement* head_element = head(); HTMLElement* head_element = head();
if (!head_element) if (!head_element)
return; return;
title_element_ = HTMLTitleElement::Create(*this); title_element_ = HTMLTitleElement::Create(*this);
head_element->AppendChild(title_element_.Get()); head_element->AppendChild(title_element_.Get());
} else if (IsSVGDocument()) {
Element* element = documentElement();
if (!IsSVGSVGElement(element))
return;
title_element_ = SVGTitleElement::Create(*this);
element->InsertBefore(title_element_.Get(), element->firstChild());
}
} else {
if (!IsHTMLDocument() && !IsXHTMLDocument() && !IsSVGDocument())
title_element_ = nullptr;
} }
if (auto* html_title = ToHTMLTitleElementOrNull(title_element_)) if (auto* html_title = ToHTMLTitleElementOrNull(title_element_))
html_title->setText(title); html_title->setText(title);
else if (auto* svg_title = ToSVGTitleElementOrNull(title_element_)) }
svg_title->SetText(title);
else
UpdateTitle(title);
} }
void Document::SetTitleElement(Element* title_element) { void Document::SetTitleElement(Element* title_element) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment