Title: [177435] trunk
Revision
177435
Author
commit-qu...@webkit.org
Date
2014-12-16 21:20:09 -0800 (Tue, 16 Dec 2014)

Log Message

text node should not be created, On setting document.title to the empty string.
https://bugs.webkit.org/show_bug.cgi?id=139121

Patch by Shivakumar JM <shiva...@samsung.com> on 2014-12-16
Reviewed by Darin Adler.

Source/WebCore:

Do not create text node, On setting document.title to the empty string as in spec.
I have confirmed this matches the behavior of Firefox and Chrome.

Test: fast/dom/Document/document-set-title-no-child.html

* html/HTMLTitleElement.cpp:
(WebCore::HTMLTitleElement::setText):

LayoutTests:

* fast/dom/Document/document-set-title-no-child-expected.txt: Added.
* fast/dom/Document/document-set-title-no-child.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (177434 => 177435)


--- trunk/LayoutTests/ChangeLog	2014-12-17 04:02:33 UTC (rev 177434)
+++ trunk/LayoutTests/ChangeLog	2014-12-17 05:20:09 UTC (rev 177435)
@@ -1,3 +1,13 @@
+2014-12-16  Shivakumar JM  <shiva...@samsung.com>
+
+        text node should not be created, On setting document.title to the empty string.
+        https://bugs.webkit.org/show_bug.cgi?id=139121
+
+        Reviewed by Darin Adler.
+
+        * fast/dom/Document/document-set-title-no-child-expected.txt: Added.
+        * fast/dom/Document/document-set-title-no-child.html: Added.
+
 2014-12-16  Daniel Bates  <daba...@apple.com>
 
         [iOS] Update expected results for LayoutTests/fast

Added: trunk/LayoutTests/fast/dom/Document/document-set-title-no-child-expected.txt (0 => 177435)


--- trunk/LayoutTests/fast/dom/Document/document-set-title-no-child-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/document-set-title-no-child-expected.txt	2014-12-17 05:20:09 UTC (rev 177435)
@@ -0,0 +1,22 @@
+On setting document.title to the empty string, no text node should be created
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.title is ""
+document.title = ''
+PASS document.title is ""
+PASS document.getElementsByTagName('title')[0].firstChild is null
+PASS document.title is "titletext"
+PASS document.getElementsByTagName('title')[0].firstChild is non-null.
+document.title = ''
+PASS document.title is ""
+PASS document.getElementsByTagName('title')[0].firstChild is null
+PASS document.title is "titletextnew"
+PASS document.getElementsByTagName('title')[0].firstChild is non-null.
+PASS document.title is "updatetitletextnew"
+PASS document.getElementsByTagName('title')[0].firstChild is non-null.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Document/document-set-title-no-child.html (0 => 177435)


--- trunk/LayoutTests/fast/dom/Document/document-set-title-no-child.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/document-set-title-no-child.html	2014-12-17 05:20:09 UTC (rev 177435)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<script src=""
+<body>
+<script>
+    description("On setting document.title to the empty string, no text node should be created");
+    shouldBeEmptyString("document.title");
+    evalAndLog("document.title = ''");
+    shouldBeEmptyString("document.title");
+    shouldBeNull("document.getElementsByTagName('title')[0].firstChild");
+
+    document.title = "titletext";
+    shouldBeEqualToString("document.title", "titletext");
+    shouldBeNonNull("document.getElementsByTagName('title')[0].firstChild");
+
+    evalAndLog("document.title = ''");
+    shouldBeEmptyString("document.title");
+    shouldBeNull("document.getElementsByTagName('title')[0].firstChild");
+
+    document.title = "titletextnew";
+    shouldBeEqualToString("document.title", "titletextnew");
+    shouldBeNonNull("document.getElementsByTagName('title')[0].firstChild");
+
+    document.title = "updatetitletextnew";
+    shouldBeEqualToString("document.title", "updatetitletextnew");
+    shouldBeNonNull("document.getElementsByTagName('title')[0].firstChild");
+
+</script>
+</body>

Modified: trunk/Source/WebCore/ChangeLog (177434 => 177435)


--- trunk/Source/WebCore/ChangeLog	2014-12-17 04:02:33 UTC (rev 177434)
+++ trunk/Source/WebCore/ChangeLog	2014-12-17 05:20:09 UTC (rev 177435)
@@ -1,3 +1,18 @@
+2014-12-16  Shivakumar JM  <shiva...@samsung.com>
+
+        text node should not be created, On setting document.title to the empty string.
+        https://bugs.webkit.org/show_bug.cgi?id=139121
+
+        Reviewed by Darin Adler.
+
+        Do not create text node, On setting document.title to the empty string as in spec.
+        I have confirmed this matches the behavior of Firefox and Chrome.
+
+        Test: fast/dom/Document/document-set-title-no-child.html
+
+        * html/HTMLTitleElement.cpp:
+        (WebCore::HTMLTitleElement::setText):
+
 2014-12-16  Gyuyoung Kim  <gyuyoung....@samsung.com>
 
         Move WebCore/platform/graphics/surfaces to std::unique_ptr

Modified: trunk/Source/WebCore/html/HTMLTitleElement.cpp (177434 => 177435)


--- trunk/Source/WebCore/html/HTMLTitleElement.cpp	2014-12-17 04:02:33 UTC (rev 177434)
+++ trunk/Source/WebCore/html/HTMLTitleElement.cpp	2014-12-17 05:20:09 UTC (rev 177435)
@@ -93,23 +93,25 @@
     return StringWithDirection(text(), direction);
 }
 
-void HTMLTitleElement::setText(const String &value)
+void HTMLTitleElement::setText(const String& value)
 {
     Ref<HTMLTitleElement> protectFromMutationEvents(*this);
     
-    if (hasOneChild() && is<Text>(*firstChild()))
+    if (!value.isEmpty() && hasOneChild() && is<Text>(*firstChild())) {
         downcast<Text>(*firstChild()).setData(value, IGNORE_EXCEPTION);
-    else {
-        // We make a copy here because entity of "value" argument can be Document::m_title,
-        // which goes empty during removeChildren() invocation below,
-        // which causes HTMLTitleElement::childrenChanged(), which ends up Document::setTitle().
-        String valueCopy(value);
+        return;
+    }
 
-        if (hasChildNodes())
-            removeChildren();
+    // We make a copy here because entity of "value" argument can be Document::m_title,
+    // which goes empty during removeChildren() invocation below,
+    // which causes HTMLTitleElement::childrenChanged(), which ends up Document::setTitle().
+    String valueCopy(value);
 
-        appendChild(document().createTextNode(valueCopy.impl()), IGNORE_EXCEPTION);
-    }
+    if (hasChildNodes())
+        removeChildren();
+
+    if (!valueCopy.isEmpty())
+        appendChild(document().createTextNode(valueCopy), IGNORE_EXCEPTION);
 }
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to