⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 202893 in webkit


Ignore:
Timestamp:
Jul 6, 2016, 9:14:28 PM (10 years ago)
Author:
Chris Dumez
Message:

Align Document.body setter with the HTML specification
https://bugs.webkit.org/show_bug.cgi?id=159490

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline existing W3C test now that one more check is passing.

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

Source/WebCore:

Align Document.body setter with the HTML specification:

In particular, the following web-exposed changes were made:

  • It is now possible to set document.body to a frameset element.
  • We no longer call importNode() on the passed in body. Therefore, if the body comes from another document, its will be adopted / transferred rather than cloned.

Both changes match the behavior of Firefox and Chrome.

No new tests, updated / rebaselined existing tests.

  • dom/Document.cpp:

(WebCore::Document::setBodyOrFrameset):

LayoutTests:

Update existing test that was setting a document's body to another frame's body
as it was expecting the body element to get cloned rather than adopted / transferred.

  • fast/dom/document-set-body-expected.txt:
  • fast/dom/document-set-body.html:
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r202887 r202893  
     12016-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Align Document.body setter with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=159490
     5
     6        Reviewed by Alex Christensen.
     7
     8        Update existing test that was setting a document's body to another frame's body
     9        as it was expecting the body element to get cloned rather than adopted / transferred.
     10
     11        * fast/dom/document-set-body-expected.txt:
     12        * fast/dom/document-set-body.html:
     13
    1142016-07-06  Brent Fulgham  <bfulgham@apple.com>
    215
  • trunk/LayoutTests/fast/dom/document-set-body-expected.txt

    r134435 r202893  
    1 Tests setting document.body
     1Tests setting document.body to another frame's body
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    44
    55
    6 PASS document1.body = iframe1 threw exception Error: HierarchyRequestError: DOM Exception 3.
    7 PASS iframe1.parentNode is document.body
    8 PASS document1.body = document1.createElement('iframe') threw exception Error: HierarchyRequestError: DOM Exception 3.
    9 PASS document1.body != document.body is true
    10 PASS document1.body is body1
     6PASS document1.body is not null
     7PASS document2.body is null
     8PASS document2.body = document1.body did not throw exception.
     9PASS document2.body is not null
     10PASS document1.body is null
    1111PASS successfullyParsed is true
    1212
    1313TEST COMPLETE
    14 
     14 
  • trunk/LayoutTests/fast/dom/document-set-body.html

    r155265 r202893  
    1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
     1<!DOCTYPE html>
    22<html>
    33<head>
     
    55</head>
    66<body>
     7<iframe id="testFrame1" srcdoc="<html><body></body></html>"></iframe>
     8<iframe id="testFrame2" srcdoc="<html></html>"></iframe>
    79<script>
    8 description("Tests setting document.body");
     10description("Tests setting document.body to another frame's body");
    911
    10 iframe1 = document.createElement('iframe');
    11 document.body.appendChild(iframe1);
    12 document1 = iframe1.contentDocument.implementation.createHTMLDocument("document");
     12var document1 = document.getElementById("testFrame1").contentDocument;
     13var document2 = document.getElementById("testFrame2").contentDocument;
     14if (document2.body)
     15    document2.documentElement.removeChild(document2.body);
    1316
    14 shouldThrow("document1.body = iframe1", "'Error: HierarchyRequestError: DOM Exception 3'");
    15 shouldBe("iframe1.parentNode", "document.body");
     17shouldNotBe("document1.body", "null");
     18shouldBeNull("document2.body");
    1619
    17 shouldThrow("document1.body = document1.createElement('iframe')", "'Error: HierarchyRequestError: DOM Exception 3'");
     20shouldNotThrow("document2.body = document1.body");
    1821
    19 document1.body = document.body;
    20 shouldBeTrue("document1.body != document.body");
     22shouldNotBe("document2.body", "null");
     23shouldBeNull("document1.body");
    2124
    22 body1 = document1.createElement('body');
    23 document1.body = body1;
    24 shouldBe("document1.body", "body1")
    2525</script>
    2626<script src="../../resources/js-test-post.js"></script>
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r202881 r202893  
     12016-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Align Document.body setter with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=159490
     5
     6        Reviewed by Alex Christensen.
     7
     8        Rebaseline existing W3C test now that one more check is passing.
     9
     10        * web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt:
     11
    1122016-07-06  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt

    r202881 r202893  
    2121PASS Setting document.body when there's no root element.
    2222PASS Setting document.body to a new body element.
    23 FAIL Setting document.body to a new frameset element. HierarchyRequestError: DOM Exception 3
     23PASS Setting document.body to a new frameset element.
    2424
  • trunk/Source/WebCore/ChangeLog

    r202892 r202893  
     12016-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Align Document.body setter with the HTML specification
     4        https://bugs.webkit.org/show_bug.cgi?id=159490
     5
     6        Reviewed by Alex Christensen.
     7
     8        Align Document.body setter with the HTML specification:
     9        - https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
     10
     11        In particular, the following web-exposed changes were made:
     12        - It is now possible to set document.body to a frameset element.
     13        - We no longer call importNode() on the passed in body. Therefore,
     14          if the body comes from another document, its will be adopted /
     15          transferred rather than cloned.
     16
     17        Both changes match the behavior of Firefox and Chrome.
     18
     19        No new tests, updated / rebaselined existing tests.
     20
     21        * dom/Document.cpp:
     22        (WebCore::Document::setBodyOrFrameset):
     23
    1242016-07-06  Brady Eidson  <beidson@apple.com>
    225
  • trunk/Source/WebCore/dom/Document.cpp

    r202881 r202893  
    26252625void Document::setBodyOrFrameset(RefPtr<HTMLElement>&& newBody, ExceptionCode& ec)
    26262626{
    2627     // FIXME: This does not support setting a <frameset> Element, only a <body>. This does
    2628     // not match the HTML specification:
    2629     // https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
    2630     if (!newBody || !documentElement() || !newBody->hasTagName(bodyTag)) {
     2627    if (!is<HTMLBodyElement>(newBody.get()) && !is<HTMLFrameSetElement>(newBody.get())) {
    26312628        ec = HIERARCHY_REQUEST_ERR;
    26322629        return;
    26332630    }
    26342631
    2635     if (&newBody->document() != this) {
    2636         ec = 0;
    2637         RefPtr<Node> node = importNode(*newBody, true, ec);
    2638         if (ec)
    2639             return;
    2640        
    2641         newBody = downcast<HTMLElement>(node.get());
    2642     }
    2643 
    2644     if (auto* body = bodyOrFrameset())
    2645         documentElement()->replaceChild(*newBody, *body, ec);
    2646     else
    2647         documentElement()->appendChild(*newBody, ec);
     2632    auto* currentBody = bodyOrFrameset();
     2633    if (newBody == currentBody)
     2634        return;
     2635
     2636    if (currentBody) {
     2637        documentElement()->replaceChild(*newBody, *currentBody, ec);
     2638        return;
     2639    }
     2640
     2641    if (!documentElement()) {
     2642        ec = HIERARCHY_REQUEST_ERR;
     2643        return;
     2644    }
     2645
     2646    documentElement()->appendChild(*newBody, ec);
    26482647}
    26492648
Note: See TracChangeset for help on using the changeset viewer.