Title: [138130] trunk
Revision
138130
Author
ta...@google.com
Date
2012-12-19 00:54:10 -0800 (Wed, 19 Dec 2012)

Log Message

[Shadow] TITLE elements in Shadow DOM should not affect document.title attribute
https://bugs.webkit.org/show_bug.cgi?id=85864

Reviewed by Ryosuke Niwa.

Source/WebCore:

Modified HTMLTitleElement to check whether a title element is in a
shadow tree or not when it is inserted or removed. Now if a title
element has been just removed from or inserted into a shadow tree,
document.title is not updated independent of inDocument().  If the
title element is not in a shadow tree and in document,
document.title is updated.

Test: fast/dom/shadow/title-element-in-shadow.html

* html/HTMLTitleElement.cpp:
(WebCore::HTMLTitleElement::insertedInto):
Added a condition: isInShadowTree() to the code which checks
inDocument or not.
(WebCore::HTMLTitleElement::removedFrom):
Added a condition: insertionPoint.isInShadowTree() to the code which
checks an insertion point is in a document or not.
(WebCore::HTMLTitleElement::childrenChanged):
Added a condition: isInShadowTree() before setTitle.
If not isInShadowTree, modified to removeTitle from document.

LayoutTests:

* fast/dom/shadow/title-element-in-shadow-expected.txt: Added.
* fast/dom/shadow/title-element-in-shadow.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (138129 => 138130)


--- trunk/LayoutTests/ChangeLog	2012-12-19 08:46:12 UTC (rev 138129)
+++ trunk/LayoutTests/ChangeLog	2012-12-19 08:54:10 UTC (rev 138130)
@@ -1,3 +1,13 @@
+2012-12-19  Takashi Sakamoto  <ta...@google.com>
+
+        [Shadow] TITLE elements in Shadow DOM should not affect document.title attribute
+        https://bugs.webkit.org/show_bug.cgi?id=85864
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/dom/shadow/title-element-in-shadow-expected.txt: Added.
+        * fast/dom/shadow/title-element-in-shadow.html: Added.
+
 2012-12-19  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r138123.

Added: trunk/LayoutTests/fast/dom/shadow/title-element-in-shadow-expected.txt (0 => 138130)


--- trunk/LayoutTests/fast/dom/shadow/title-element-in-shadow-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/title-element-in-shadow-expected.txt	2012-12-19 08:54:10 UTC (rev 138130)
@@ -0,0 +1,21 @@
+This test ensures that title elements in a shadow subtree do not affect document.title attribute.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+create a title element and insert it to document.
+PASS document.title is "document title"
+remove title element from document.
+PASS document.title is ""
+create a shadow root whose host is already in document, create a subtree which contains a title element, and add the subtree to the shadow root.
+PASS document.title is ""
+remove the subtree from document.
+PASS document.title is ""
+create a subtree, add a shadow root which contains a title element to the subtree, and insert the subtree to document.
+PASS document.title is ""
+remove the subtree from document
+PASS document.title is ""
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/shadow/title-element-in-shadow.html (0 => 138130)


--- trunk/LayoutTests/fast/dom/shadow/title-element-in-shadow.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/title-element-in-shadow.html	2012-12-19 08:54:10 UTC (rev 138130)
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+description("This test ensures that title elements in a shadow subtree do not affect document.title attribute.")
+
+debug('create a title element and insert it to document.');
+var title = document.createElement('title');
+title.appendChild(document.createTextNode('document title'));
+document.head.appendChild(title);
+shouldBe('document.title', '"document title"');
+document.head.removeChild(title);
+debug('remove title element from document.');
+shouldBe('document.title', '""');
+
+debug('create a shadow root whose host is already in document, create a subtree which contains a title element, and add the subtree to the shadow root.');
+var subtree1 = document.createElement('div');
+var shadow1 = subtree1.webkitCreateShadowRoot();
+document.head.appendChild(subtree1);
+var shadowTitle = document.createElement('title');
+shadowTitle.appendChild(document.createTextNode('shadow title1'));
+shadow1.appendChild(shadowTitle);
+shouldBe('document.title', '""');
+
+debug('remove the subtree from document.');
+document.head.removeChild(subtree1);
+shouldBe('document.title', '""');
+
+debug('create a subtree, add a shadow root which contains a title element to the subtree, and insert the subtree to document.')
+var subtree2 = document.createElement('div');
+var shadow2 = subtree2.webkitCreateShadowRoot();
+shadow2.innerHTML = '<title>shadow title2</title>';
+document.head.appendChild(subtree2);
+shouldBe('document.title', '""');
+debug('remove the subtree from document');
+document.head.removeChild(subtree2);
+shouldBe('document.title', '""');
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (138129 => 138130)


--- trunk/Source/WebCore/ChangeLog	2012-12-19 08:46:12 UTC (rev 138129)
+++ trunk/Source/WebCore/ChangeLog	2012-12-19 08:54:10 UTC (rev 138130)
@@ -1,3 +1,30 @@
+2012-12-19  Takashi Sakamoto  <ta...@google.com>
+
+        [Shadow] TITLE elements in Shadow DOM should not affect document.title attribute
+        https://bugs.webkit.org/show_bug.cgi?id=85864
+
+        Reviewed by Ryosuke Niwa.
+
+        Modified HTMLTitleElement to check whether a title element is in a
+        shadow tree or not when it is inserted or removed. Now if a title
+        element has been just removed from or inserted into a shadow tree,
+        document.title is not updated independent of inDocument().  If the
+        title element is not in a shadow tree and in document,
+        document.title is updated.
+
+        Test: fast/dom/shadow/title-element-in-shadow.html
+
+        * html/HTMLTitleElement.cpp:
+        (WebCore::HTMLTitleElement::insertedInto):
+        Added a condition: isInShadowTree() to the code which checks
+        inDocument or not.
+        (WebCore::HTMLTitleElement::removedFrom):
+        Added a condition: insertionPoint.isInShadowTree() to the code which
+        checks an insertion point is in a document or not.
+        (WebCore::HTMLTitleElement::childrenChanged):
+        Added a condition: isInShadowTree() before setTitle.
+        If not isInShadowTree, modified to removeTitle from document.
+
 2012-12-19  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r138123.

Modified: trunk/Source/WebCore/html/HTMLTitleElement.cpp (138129 => 138130)


--- trunk/Source/WebCore/html/HTMLTitleElement.cpp	2012-12-19 08:46:12 UTC (rev 138129)
+++ trunk/Source/WebCore/html/HTMLTitleElement.cpp	2012-12-19 08:54:10 UTC (rev 138130)
@@ -49,7 +49,7 @@
 Node::InsertionNotificationRequest HTMLTitleElement::insertedInto(ContainerNode* insertionPoint)
 {
     HTMLElement::insertedInto(insertionPoint);
-    if (insertionPoint->inDocument())
+    if (inDocument() && !isInShadowTree())
         document()->setTitleElement(m_title, this);
     return InsertionDone;
 }
@@ -57,7 +57,7 @@
 void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint)
 {
     HTMLElement::removedFrom(insertionPoint);
-    if (insertionPoint->inDocument())
+    if (insertionPoint->inDocument() && !insertionPoint->isInShadowTree())
         document()->removeTitle(this);
 }
 
@@ -65,8 +65,12 @@
 {
     HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
     m_title = textWithDirection();
-    if (inDocument())
-        document()->setTitleElement(m_title, this);
+    if (inDocument()) {
+        if (!isInShadowTree())
+            document()->setTitleElement(m_title, this);
+        else
+            document()->removeTitle(this);
+    }
 }
 
 String HTMLTitleElement::text() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to