summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/events/Body-FrameSet-Event-Handlers.html
blob: 3a891158d5f8637c24b5efd270e5c920e6c7c1dd (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<title>HTMLBodyElement and HTMLFrameSetElement Event Handler Tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
function getObject(interface) {
    switch(interface) {
        case "Element":
            var e = document.createElementNS("http://example.com/", "example");
            assert_true(e instanceof Element);
            assert_false(e instanceof HTMLElement);
            assert_false(e instanceof SVGElement);
            return e;
        case "HTMLElement":
            var e = document.createElement("html");
            assert_true(e instanceof HTMLElement);
            return e;
        case "HTMLBodyElement":
            var e = document.createElement("body");
            assert_true(e instanceof HTMLBodyElement);
            return e;
        case "HTMLFormElement":
            var e = document.createElement("form");
            assert_true(e instanceof HTMLFormElement);
            return e;
        case "HTMLFrameSetElement":
            var e = document.createElement("frameset");
            assert_true(e instanceof HTMLFrameSetElement);
            return e;
        case "SVGElement":
            var e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
            assert_true(e instanceof SVGElement);
            return e;
        case "Document":
            assert_true(document instanceof Document);
            return document;
        case "Window":
            assert_true(window instanceof Window);
            return window;
    }
    assert_unreached();
}

function testSet(interface, attribute) {
    test(function() {
        var object = getObject(interface);
        function nop() {}
        assert_equals(object[attribute], null, "Initially null");
        object[attribute] = nop;
        assert_equals(object[attribute], nop, "Return same function");
        object[attribute] = "";
        assert_equals(object[attribute], null, "Return null after setting string");
        object[attribute] = null;
        assert_equals(object[attribute], null, "Finally null");
    }, "Set " + interface + "." + attribute);
}

function testReflect(interface, attribute) {
    test(function() {
        var element = getObject(interface);
        assert_false(element.hasAttribute(attribute), "Initially missing");
        element.setAttribute(attribute, "return");
        assert_equals(element.getAttribute(attribute), "return", "Return same string");
        assert_equals(typeof element[attribute], "function", "Convert to function");
        element.removeAttribute(attribute);
    }, "Reflect " + interface + "." + attribute);
}

function testForwardToWindow(interface, attribute) {
    test(function() {
        var element = getObject(interface);
        window[attribute] = null;
        element.setAttribute(attribute, "return");
        assert_equals(typeof window[attribute], "function", "Convert to function");
        assert_equals(window[attribute], element[attribute], "Forward content attribute");
        function nop() {}
        element[attribute] = nop;
        assert_equals(window[attribute], nop, "Forward IDL attribute");
        window[attribute] = null;
    }, "Forward " + interface + "." + attribute + " to Window");
}

// Object.propertyIsEnumerable cannot be used because it doesn't
// work with properties inherited through the prototype chain.
function getEnumerable(interface) {
    var enumerable = {};
    for (var attribute in getObject(interface)) {
        enumerable[attribute] = true;
    }
    return enumerable;
}

var enumerableCache = {};
function testEnumerate(interface, attribute) {
    if (!(interface in enumerableCache)) {
        enumerableCache[interface] = getEnumerable(interface);
    }
    test(function() {
        assert_true(enumerableCache[interface][attribute]);
    }, "Enumerate " + interface + "." + attribute);
}

[
    "onblur",
    "onerror",
    "onfocus",
    "onload",
    "onscroll",
    "onresize"
].forEach(function(attribute) {
    testSet("HTMLBodyElement", attribute);
    testEnumerate("HTMLBodyElement", attribute);
    testReflect("HTMLBodyElement", attribute);
    testForwardToWindow("HTMLBodyElement", attribute);
    testSet("HTMLFrameSetElement", attribute);
    testEnumerate("HTMLFrameSetElement", attribute);
    testReflect("HTMLFrameSetElement", attribute);
    testForwardToWindow("HTMLFrameSetElement", attribute);
});
</script>
</html>