REGRESSION(r189555): ImageDocument title no longer includes the size of the image
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jan 2017 05:04:36 +0000 (05:04 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jan 2017 05:04:36 +0000 (05:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166876
<rdar://problem/29939970>

Reviewed by Tim Horton.

Source/WebCore:

ImageDocument title no longer included the size of the image after r189555.
This is because Document::setTitle() is a no-op if the document does not
have a <head> element. To address the issue, we now include a <head>
element in ImageDocuments so that their title element properly gets added
to it.

Test: fast/images/imageDocument-title.html

* html/ImageDocument.cpp:
(WebCore::ImageDocument::createDocumentStructure):

LayoutTests:

Add layout test coverage.

* fast/images/imageDocument-title-expected.txt: Added.
* fast/images/imageDocument-title.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/images/imageDocument-title-expected.txt [new file with mode: 0644]
LayoutTests/fast/images/imageDocument-title.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/ImageDocument.cpp

index 7c48725..b2729d4 100644 (file)
@@ -1,3 +1,16 @@
+2017-01-09  Chris Dumez  <cdumez@apple.com>
+
+        REGRESSION(r189555): ImageDocument title no longer includes the size of the image
+        https://bugs.webkit.org/show_bug.cgi?id=166876
+        <rdar://problem/29939970>
+
+        Reviewed by Tim Horton.
+
+        Add layout test coverage.
+
+        * fast/images/imageDocument-title-expected.txt: Added.
+        * fast/images/imageDocument-title.html: Added.
+
 2017-01-09  Zalan Bujtas  <zalan@apple.com>
 
         ASSERTION FAILED: newLogicalTop >= logicalTop in WebCore::RenderBlockFlow::getClearDelta
diff --git a/LayoutTests/fast/images/imageDocument-title-expected.txt b/LayoutTests/fast/images/imageDocument-title-expected.txt
new file mode 100644 (file)
index 0000000..90b12cb
--- /dev/null
@@ -0,0 +1,11 @@
+Tests that the title of an ImageDocument is properly set.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS f.contentDocument.title is "green-24x24.jpg 24×24 pixels"
+PASS f.contentDocument.head.getElementsByTagName('title')[0].textContent is "green-24x24.jpg 24×24 pixels"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/images/imageDocument-title.html b/LayoutTests/fast/images/imageDocument-title.html
new file mode 100644 (file)
index 0000000..3a288e9
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+</head>
+<body>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+description("Tests that the title of an ImageDocument is properly set.");
+jsTestIsAsync = true;
+
+var f = document.createElement("iframe");
+f.onload = function() {
+    shouldBeEqualToString("f.contentDocument.title", "green-24x24.jpg 24×24 pixels");
+    shouldBeEqualToString("f.contentDocument.head.getElementsByTagName('title')[0].textContent", "green-24x24.jpg 24×24 pixels");
+    finishJSTest();
+}
+
+f.src = "resources/green-24x24.jpg";
+document.body.appendChild(f);
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index a05a642..e29724a 100644 (file)
@@ -1,3 +1,22 @@
+2017-01-09  Chris Dumez  <cdumez@apple.com>
+
+        REGRESSION(r189555): ImageDocument title no longer includes the size of the image
+        https://bugs.webkit.org/show_bug.cgi?id=166876
+        <rdar://problem/29939970>
+
+        Reviewed by Tim Horton.
+
+        ImageDocument title no longer included the size of the image after r189555.
+        This is because Document::setTitle() is a no-op if the document does not
+        have a <head> element. To address the issue, we now include a <head>
+        element in ImageDocuments so that their title element properly gets added
+        to it.
+
+        Test: fast/images/imageDocument-title.html
+
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocument::createDocumentStructure):
+
 2017-01-09  Zalan Bujtas  <zalan@apple.com>
 
         ASSERTION FAILED: newLogicalTop >= logicalTop in WebCore::RenderBlockFlow::getClearDelta
index ddc8402..c471332 100644 (file)
@@ -35,6 +35,7 @@
 #include "FrameLoaderClient.h"
 #include "FrameView.h"
 #include "HTMLBodyElement.h"
+#include "HTMLHeadElement.h"
 #include "HTMLHtmlElement.h"
 #include "HTMLImageElement.h"
 #include "HTMLNames.h"
@@ -215,6 +216,9 @@ void ImageDocument::createDocumentStructure()
 
     frame()->injectUserScripts(InjectAtDocumentStart);
 
+    auto head = HTMLHeadElement::create(*this);
+    rootElement->appendChild(head);
+
     auto body = HTMLBodyElement::create(*this);
     body->setAttribute(styleAttr, "margin: 0px");
     if (MIMETypeRegistry::isPDFMIMEType(document().loader()->responseMIMEType()))