Title: [202881] trunk
Revision
202881
Author
[email protected]
Date
2016-07-06 15:13:18 -0700 (Wed, 06 Jul 2016)

Log Message

Document.body should return the first child of the html element that is either a body / frameset element
https://bugs.webkit.org/show_bug.cgi?id=159488

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Import corresponding W3C test.

* web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt: Added.
* web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body.html: Added.

Source/WebCore:

Document.body should return the first child of the html element that is
either a body / frameset element:
- https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
- https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2

We used the first child of the *document* element that is either a
body / frameset element, even if the document element is not an html
element.

Firefox and Chrome match the specification.

Test: imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body.html

* dom/Document.cpp:
(WebCore::Document::bodyOrFrameset):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (202880 => 202881)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-07-06 21:54:45 UTC (rev 202880)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-07-06 22:13:18 UTC (rev 202881)
@@ -1,5 +1,17 @@
 2016-07-06  Chris Dumez  <[email protected]>
 
+        Document.body should return the first child of the html element that is either a body / frameset element
+        https://bugs.webkit.org/show_bug.cgi?id=159488
+
+        Reviewed by Ryosuke Niwa.
+
+        Import corresponding W3C test.
+
+        * web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt: Added.
+        * web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body.html: Added.
+
+2016-07-06  Chris Dumez  <[email protected]>
+
         [ShadowDOM] assignedSlot property should be on Text, not CharacterData
         https://bugs.webkit.org/show_bug.cgi?id=159482
         <rdar://problem/27201687>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt (0 => 202881)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt	2016-07-06 22:13:18 UTC (rev 202881)
@@ -0,0 +1,24 @@
+
+PASS Childless document 
+PASS Childless html element 
+PASS Body followed by frameset inside the html element 
+PASS Frameset followed by body inside the html element 
+PASS Body followed by frameset inside a non-HTML html element 
+PASS Frameset followed by body inside a non-HTML html element 
+PASS Non-HTML body followed by body inside the html element 
+PASS Non-HTML frameset followed by body inside the html element 
+PASS Body inside an x element followed by a body 
+PASS Frameset inside an x element followed by a frameset 
+PASS Body as the root node 
+PASS Frameset as the root node 
+PASS Body as the root node with a frameset child 
+PASS Frameset as the root node with a body child 
+PASS Non-HTML body as the root node 
+PASS Non-HTML frameset as the root node 
+PASS existing document's body 
+PASS Setting document.body to a string. 
+PASS Setting document.body to a div element. 
+PASS Setting document.body when there's no root element. 
+PASS Setting document.body to a new body element. 
+FAIL Setting document.body to a new frameset element. HierarchyRequestError: DOM Exception 3
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body.html (0 => 202881)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body.html	2016-07-06 22:13:18 UTC (rev 202881)
@@ -0,0 +1,169 @@
+<!DOCTYPE html>
+<title>Document.body</title>
+<link rel="author" title="Ms2ger" href=""
+<link rel="help" href=""
+<script src=""
+<script src=""
+<div id="log"></div>
+<script>
+function createDocument() {
+  var doc = document.implementation.createHTMLDocument("");
+  doc.removeChild(doc.documentElement);
+  return doc;
+}
+test(function() {
+  var doc = createDocument();
+  assert_equals(doc.body, null);
+}, "Childless document");
+test(function() {
+  var doc = createDocument();
+  doc.appendChild(doc.createElement("html"));
+  assert_equals(doc.body, null);
+}, "Childless html element");
+test(function() {
+  var doc = createDocument();
+  var html = doc.appendChild(doc.createElement("html"));
+  var b =
+    html.appendChild(doc.createElement("body"));
+  html.appendChild(doc.createElement("frameset"));
+  assert_equals(doc.body, b);
+}, "Body followed by frameset inside the html element");
+test(function() {
+  var doc = createDocument();
+  var html = doc.appendChild(doc.createElement("html"));
+  var f =
+    html.appendChild(doc.createElement("frameset"));
+  html.appendChild(doc.createElement("body"));
+  assert_equals(doc.body, f);
+}, "Frameset followed by body inside the html element");
+test(function() {
+  var doc = createDocument();
+  var html =
+    doc.appendChild(doc.createElementNS("http://example.org/test", "html"));
+  html.appendChild(doc.createElement("body"));
+  html.appendChild(doc.createElement("frameset"));
+  assert_equals(doc.body, null);
+}, "Body followed by frameset inside a non-HTML html element");
+test(function() {
+  var doc = createDocument();
+  var html =
+    doc.appendChild(doc.createElementNS("http://example.org/test", "html"));
+  html.appendChild(doc.createElement("frameset"));
+  html.appendChild(doc.createElement("body"));
+  assert_equals(doc.body, null);
+}, "Frameset followed by body inside a non-HTML html element");
+test(function() {
+  var doc = createDocument();
+  var html = doc.appendChild(doc.createElement("html"));
+  html.appendChild(
+    doc.createElementNS("http://example.org/test", "body"));
+  var b = html.appendChild(doc.createElement("body"));
+  assert_equals(doc.body, b);
+}, "Non-HTML body followed by body inside the html element");
+test(function() {
+  var doc = createDocument();
+  var html = doc.appendChild(doc.createElement("html"));
+  html.appendChild(
+    doc.createElementNS("http://example.org/test", "frameset"));
+  var b = html.appendChild(doc.createElement("body"));
+  assert_equals(doc.body, b);
+}, "Non-HTML frameset followed by body inside the html element");
+test(function() {
+  var doc = createDocument();
+  var html = doc.appendChild(doc.createElement("html"));
+  var x = html.appendChild(doc.createElement("x"));
+  x.appendChild(doc.createElement("body"));
+  var body = html.appendChild(doc.createElement("body"));
+  assert_equals(doc.body, body);
+}, "Body inside an x element followed by a body");
+test(function() {
+  var doc = createDocument();
+  var html = doc.appendChild(doc.createElement("html"));
+  var x = html.appendChild(doc.createElement("x"));
+  x.appendChild(doc.createElement("frameset"));
+  var frameset = html.appendChild(doc.createElement("frameset"));
+  assert_equals(doc.body, frameset);
+}, "Frameset inside an x element followed by a frameset");
+
+// Root node is not a html element.
+test(function() {
+  var doc = createDocument();
+  doc.appendChild(doc.createElement("body"));
+  assert_equals(doc.body, null);
+}, "Body as the root node");
+test(function() {
+  var doc = createDocument();
+  doc.appendChild(doc.createElement("frameset"));
+  assert_equals(doc.body, null);
+}, "Frameset as the root node");
+test(function() {
+  var doc = createDocument();
+  var body = doc.appendChild(doc.createElement("body"));
+  body.appendChild(doc.createElement("frameset"));
+  assert_equals(doc.body, null);
+}, "Body as the root node with a frameset child");
+test(function() {
+  var doc = createDocument();
+  var frameset = doc.appendChild(doc.createElement("frameset"));
+  frameset.appendChild(doc.createElement("body"));
+  assert_equals(doc.body, null);
+}, "Frameset as the root node with a body child");
+test(function() {
+  var doc = createDocument();
+  doc.appendChild(doc.createElementNS("http://example.org/test", "body"));
+  assert_equals(doc.body, null);
+}, "Non-HTML body as the root node");
+test(function() {
+  var doc = createDocument();
+  doc.appendChild(doc.createElementNS("http://example.org/test", "frameset"));
+  assert_equals(doc.body, null);
+}, "Non-HTML frameset as the root node");
+
+test(function() {
+  assert_not_equals(document.body, null);
+  assert_true(document.body instanceof HTMLBodyElement, "should be HTMLBodyElement");
+  assert_equals(document.body.tagName, "BODY");
+}, "existing document's body");
+
+
+var originalBody = document.body;
+test(function() {
+  assert_throws(new TypeError(), function() {
+    document.body = "text"
+  })
+  assert_equals(document.body, originalBody);
+}, "Setting document.body to a string.")
+test(function() {
+  assert_throws("HierarchyRequestError", function() {
+    document.body = document.createElement("div")
+  })
+  assert_equals(document.body, originalBody);
+}, "Setting document.body to a div element.")
+test(function() {
+  var doc = createDocument();
+  assert_throws("HierarchyRequestError", function() {
+    doc.body = doc.createElement("body")
+  })
+  assert_equals(doc.body, null);
+}, "Setting document.body when there's no root element.")
+test(function() {
+  var doc = document.implementation.createHTMLDocument();
+
+  var new_body = doc.createElement("body");
+  assert_true(new_body instanceof HTMLBodyElement, "should be HTMLBodyElement");
+  assert_equals(new_body.tagName, "BODY");
+
+  doc.body = new_body;
+  assert_equals(doc.body, new_body);
+}, "Setting document.body to a new body element.");
+test(function() {
+  var doc = document.implementation.createHTMLDocument();
+
+  var new_frameset = doc.createElement("frameset");
+  assert_true(new_frameset instanceof HTMLFrameSetElement, "should be HTMLFrameSetElement");
+  assert_equals(new_frameset.tagName, "FRAMESET");
+
+  doc.body = new_frameset;
+  assert_equals(doc.body, new_frameset, "test6-3, append frameset to a new document");
+}, "Setting document.body to a new frameset element.");
+</script>

Modified: trunk/Source/WebCore/ChangeLog (202880 => 202881)


--- trunk/Source/WebCore/ChangeLog	2016-07-06 21:54:45 UTC (rev 202880)
+++ trunk/Source/WebCore/ChangeLog	2016-07-06 22:13:18 UTC (rev 202881)
@@ -1,3 +1,26 @@
+2016-07-06  Chris Dumez  <[email protected]>
+
+        Document.body should return the first child of the html element that is either a body / frameset element
+        https://bugs.webkit.org/show_bug.cgi?id=159488
+
+        Reviewed by Ryosuke Niwa.
+
+        Document.body should return the first child of the html element that is
+        either a body / frameset element:
+        - https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
+        - https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2
+
+        We used the first child of the *document* element that is either a
+        body / frameset element, even if the document element is not an html
+        element.
+
+        Firefox and Chrome match the specification.
+
+        Test: imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::bodyOrFrameset):
+
 2016-07-06  Dean Jackson  <[email protected]>
 
         Adopt new PiP glyph

Modified: trunk/Source/WebCore/dom/Document.cpp (202880 => 202881)


--- trunk/Source/WebCore/dom/Document.cpp	2016-07-06 21:54:45 UTC (rev 202880)
+++ trunk/Source/WebCore/dom/Document.cpp	2016-07-06 22:13:18 UTC (rev 202881)
@@ -2613,7 +2613,7 @@
 {
     // Return the first body or frameset child of the html element.
     auto* element = documentElement();
-    if (!element)
+    if (!is<HTMLHtmlElement>(element))
         return nullptr;
     for (auto& child : childrenOfType<HTMLElement>(*element)) {
         if (is<HTMLBodyElement>(child) || is<HTMLFrameSetElement>(child))
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to