summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Tests/HTML/document.body.js
blob: 629bc47c7bbc0f37d22559463cc9c2ce1419161c (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
describe("body", () => {
    loadLocalPage("/res/html/misc/blank.html");

    afterInitialPageLoad(page => {
        test("Basic functionality", () => {
            expect(page.document.body).not.toBeNull();
            // FIXME: Add this in once HTMLBodyElement's constructor is implemented.
            //expect(page.document.body).toBeInstanceOf(HTMLBodyElement);
            expect(page.document.body.nodeName).toBe("BODY");
        });

        // FIXME: Add this in once set_body is fully implemented.
        test.skip("Setting body to a new body element", () => {
            // Add something to body to see if it's gone afterwards
            const p = page.document.createElement("p");
            page.document.body.appendChild(p);

            expect(page.document.body.firstChild).toBe(p);

            const newBody = page.document.createElement("body");
            page.document.body = newBody;

            expect(page.document.body).not.toBeNull();
            expect(page.document.body.nodeName).toBe("BODY");

            // FIXME: Add this in once HTMLBodyElement's constructor is implemented.
            //expect(page.document.body).toBeInstanceOf(HTMLBodyElement);

            expect(page.document.body.firstChild).toBeNull();
        });

        // FIXME: Add this in once set_body is fully implemented.
        test.skip("Setting body to a new frameset element", () => {
            const newFrameSet = page.document.createElement("frameset");
            page.document.body = newFrameSet;

            expect(page.document.body).not.toBeNull();
            expect(page.document.body.nodeName).toBe("FRAMESET");

            // FIXME: Add this in once HTMLFrameSetElement's constructor is implemented.
            //expect(page.document.body).toBeInstanceOf(HTMLFrameSetElement);
        });

        // FIXME: Add this in once set_body is fully implemented.
        test.skip("Setting body to an element that isn't body/frameset", () => {
            expect(() => {
                page.document.body = page.document.createElement("div");
            }).toThrow(DOMException);
        });

        // FIXME: Add this in once removeChild is implemented.
        test.skip("Nullable", () => {
            page.document.page.documentElement.removeChild(page.document.body);
            expect(page.document.body).toBeNull();
        });
    });
    waitForPageToLoad();
});