text node should not be created, On setting document.title to the empty string.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Dec 2014 05:20:09 +0000 (05:20 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Dec 2014 05:20:09 +0000 (05:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139121

Patch by Shivakumar JM <shiva.jm@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.

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/Document/document-set-title-no-child-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Document/document-set-title-no-child.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLTitleElement.cpp

index 9d5ddd7..e9303fe 100644 (file)
@@ -1,3 +1,13 @@
+2014-12-16  Shivakumar JM  <shiva.jm@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  <dabates@apple.com>
 
         [iOS] Update expected results for LayoutTests/fast
diff --git a/LayoutTests/fast/dom/Document/document-set-title-no-child-expected.txt b/LayoutTests/fast/dom/Document/document-set-title-no-child-expected.txt
new file mode 100644 (file)
index 0000000..308870e
--- /dev/null
@@ -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
+
diff --git a/LayoutTests/fast/dom/Document/document-set-title-no-child.html b/LayoutTests/fast/dom/Document/document-set-title-no-child.html
new file mode 100644 (file)
index 0000000..e8d7964
--- /dev/null
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<script src="../../../resources/js-test.js"></script>
+<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>
index 83cdf82..53eae62 100644 (file)
@@ -1,3 +1,18 @@
+2014-12-16  Shivakumar JM  <shiva.jm@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.kim@samsung.com>
 
         Move WebCore/platform/graphics/surfaces to std::unique_ptr
index cfc6e12..c3a41d0 100644 (file)
@@ -93,23 +93,25 @@ StringWithDirection HTMLTitleElement::textWithDirection()
     return StringWithDirection(text(), direction);
 }
 
-void HTMLTitleElement::setText(const String &value)
+void HTMLTitleElement::setText(const Stringvalue)
 {
     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);
 }
 
 }