summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/document-body-getter-setter.html
blob: 44385e92e981d8a6b0298e25535ddbf1cdc2fa72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>

<script src="../../resources/js-test.js"></script>

<script>
description('Tests getting and assigning values to document.body');

onload = function() {
    frame = document.createElement('iframe');
    document.body.appendChild(frame);

    shouldThrow('frame.contentDocument.body = document.createElement("div")', '"HierarchyRequestError: Failed to set the \'body\' property on \'Document\': The new body element is of type \'DIV\'. It must be either a \'BODY\' or \'FRAMESET\' element."');
    shouldNotThrow('frame.contentDocument.body = document.createElement("frameset")');
    shouldBe('frame.contentDocument.documentElement.childNodes.length', '2');
    shouldNotThrow('frame.contentDocument.body = document.createElement("body")');
    shouldBe('frame.contentDocument.documentElement.childNodes.length', '2');

    observer = new MutationObserver(function(records) { });
    observer.observe(frame.contentDocument, { subtree: true, childList: true });
    // If the nodes are the same this should be a noop.
    frame.contentDocument.body = frame.contentDocument.body;
    shouldBe('observer.takeRecords().length', '0');

    // WebKit calls importNode() and appends a clone instead of the element you wanted.
    newBody = document.createElement("body");
    frame.contentDocument.body = newBody;
    shouldBe('frame.contentDocument.body', 'newBody');

    newBody = frame.contentDocument.createElement('body');
    frame.contentDocument.body = newBody;
    shouldBe("frame.contentDocument.body", "newBody")

    var html = frame.contentDocument.documentElement;
    html.appendChild(document.createElement('body'));
    html.appendChild(document.createElement('frameset'));
    shouldBeEqualToString('frame.contentDocument.body.tagName', 'BODY');
};
</script>