11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<html>
31cb0ef41Sopenharmony_ci<title>HTMLBodyElement and HTMLFrameSetElement Event Handler Tests</title>
41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci<script>
81cb0ef41Sopenharmony_cifunction getObject(interface) {
91cb0ef41Sopenharmony_ci    switch(interface) {
101cb0ef41Sopenharmony_ci        case "Element":
111cb0ef41Sopenharmony_ci            var e = document.createElementNS("http://example.com/", "example");
121cb0ef41Sopenharmony_ci            assert_true(e instanceof Element);
131cb0ef41Sopenharmony_ci            assert_false(e instanceof HTMLElement);
141cb0ef41Sopenharmony_ci            assert_false(e instanceof SVGElement);
151cb0ef41Sopenharmony_ci            return e;
161cb0ef41Sopenharmony_ci        case "HTMLElement":
171cb0ef41Sopenharmony_ci            var e = document.createElement("html");
181cb0ef41Sopenharmony_ci            assert_true(e instanceof HTMLElement);
191cb0ef41Sopenharmony_ci            return e;
201cb0ef41Sopenharmony_ci        case "HTMLBodyElement":
211cb0ef41Sopenharmony_ci            var e = document.createElement("body");
221cb0ef41Sopenharmony_ci            assert_true(e instanceof HTMLBodyElement);
231cb0ef41Sopenharmony_ci            return e;
241cb0ef41Sopenharmony_ci        case "HTMLFormElement":
251cb0ef41Sopenharmony_ci            var e = document.createElement("form");
261cb0ef41Sopenharmony_ci            assert_true(e instanceof HTMLFormElement);
271cb0ef41Sopenharmony_ci            return e;
281cb0ef41Sopenharmony_ci        case "HTMLFrameSetElement":
291cb0ef41Sopenharmony_ci            var e = document.createElement("frameset");
301cb0ef41Sopenharmony_ci            assert_true(e instanceof HTMLFrameSetElement);
311cb0ef41Sopenharmony_ci            return e;
321cb0ef41Sopenharmony_ci        case "SVGElement":
331cb0ef41Sopenharmony_ci            var e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
341cb0ef41Sopenharmony_ci            assert_true(e instanceof SVGElement);
351cb0ef41Sopenharmony_ci            return e;
361cb0ef41Sopenharmony_ci        case "Document":
371cb0ef41Sopenharmony_ci            assert_true(document instanceof Document);
381cb0ef41Sopenharmony_ci            return document;
391cb0ef41Sopenharmony_ci        case "Window":
401cb0ef41Sopenharmony_ci            assert_true(window instanceof Window);
411cb0ef41Sopenharmony_ci            return window;
421cb0ef41Sopenharmony_ci    }
431cb0ef41Sopenharmony_ci    assert_unreached();
441cb0ef41Sopenharmony_ci}
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_cifunction testSet(interface, attribute) {
471cb0ef41Sopenharmony_ci    test(function() {
481cb0ef41Sopenharmony_ci        var object = getObject(interface);
491cb0ef41Sopenharmony_ci        function nop() {}
501cb0ef41Sopenharmony_ci        assert_equals(object[attribute], null, "Initially null");
511cb0ef41Sopenharmony_ci        object[attribute] = nop;
521cb0ef41Sopenharmony_ci        assert_equals(object[attribute], nop, "Return same function");
531cb0ef41Sopenharmony_ci        object[attribute] = "";
541cb0ef41Sopenharmony_ci        assert_equals(object[attribute], null, "Return null after setting string");
551cb0ef41Sopenharmony_ci        object[attribute] = null;
561cb0ef41Sopenharmony_ci        assert_equals(object[attribute], null, "Finally null");
571cb0ef41Sopenharmony_ci    }, "Set " + interface + "." + attribute);
581cb0ef41Sopenharmony_ci}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_cifunction testReflect(interface, attribute) {
611cb0ef41Sopenharmony_ci    test(function() {
621cb0ef41Sopenharmony_ci        var element = getObject(interface);
631cb0ef41Sopenharmony_ci        assert_false(element.hasAttribute(attribute), "Initially missing");
641cb0ef41Sopenharmony_ci        element.setAttribute(attribute, "return");
651cb0ef41Sopenharmony_ci        assert_equals(element.getAttribute(attribute), "return", "Return same string");
661cb0ef41Sopenharmony_ci        assert_equals(typeof element[attribute], "function", "Convert to function");
671cb0ef41Sopenharmony_ci        element.removeAttribute(attribute);
681cb0ef41Sopenharmony_ci    }, "Reflect " + interface + "." + attribute);
691cb0ef41Sopenharmony_ci}
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_cifunction testForwardToWindow(interface, attribute) {
721cb0ef41Sopenharmony_ci    test(function() {
731cb0ef41Sopenharmony_ci        var element = getObject(interface);
741cb0ef41Sopenharmony_ci        window[attribute] = null;
751cb0ef41Sopenharmony_ci        element.setAttribute(attribute, "return");
761cb0ef41Sopenharmony_ci        assert_equals(typeof window[attribute], "function", "Convert to function");
771cb0ef41Sopenharmony_ci        assert_equals(window[attribute], element[attribute], "Forward content attribute");
781cb0ef41Sopenharmony_ci        function nop() {}
791cb0ef41Sopenharmony_ci        element[attribute] = nop;
801cb0ef41Sopenharmony_ci        assert_equals(window[attribute], nop, "Forward IDL attribute");
811cb0ef41Sopenharmony_ci        window[attribute] = null;
821cb0ef41Sopenharmony_ci    }, "Forward " + interface + "." + attribute + " to Window");
831cb0ef41Sopenharmony_ci}
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci// Object.propertyIsEnumerable cannot be used because it doesn't
861cb0ef41Sopenharmony_ci// work with properties inherited through the prototype chain.
871cb0ef41Sopenharmony_cifunction getEnumerable(interface) {
881cb0ef41Sopenharmony_ci    var enumerable = {};
891cb0ef41Sopenharmony_ci    for (var attribute in getObject(interface)) {
901cb0ef41Sopenharmony_ci        enumerable[attribute] = true;
911cb0ef41Sopenharmony_ci    }
921cb0ef41Sopenharmony_ci    return enumerable;
931cb0ef41Sopenharmony_ci}
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_civar enumerableCache = {};
961cb0ef41Sopenharmony_cifunction testEnumerate(interface, attribute) {
971cb0ef41Sopenharmony_ci    if (!(interface in enumerableCache)) {
981cb0ef41Sopenharmony_ci        enumerableCache[interface] = getEnumerable(interface);
991cb0ef41Sopenharmony_ci    }
1001cb0ef41Sopenharmony_ci    test(function() {
1011cb0ef41Sopenharmony_ci        assert_true(enumerableCache[interface][attribute]);
1021cb0ef41Sopenharmony_ci    }, "Enumerate " + interface + "." + attribute);
1031cb0ef41Sopenharmony_ci}
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ci[
1061cb0ef41Sopenharmony_ci    "onblur",
1071cb0ef41Sopenharmony_ci    "onerror",
1081cb0ef41Sopenharmony_ci    "onfocus",
1091cb0ef41Sopenharmony_ci    "onload",
1101cb0ef41Sopenharmony_ci    "onscroll",
1111cb0ef41Sopenharmony_ci    "onresize"
1121cb0ef41Sopenharmony_ci].forEach(function(attribute) {
1131cb0ef41Sopenharmony_ci    testSet("HTMLBodyElement", attribute);
1141cb0ef41Sopenharmony_ci    testEnumerate("HTMLBodyElement", attribute);
1151cb0ef41Sopenharmony_ci    testReflect("HTMLBodyElement", attribute);
1161cb0ef41Sopenharmony_ci    testForwardToWindow("HTMLBodyElement", attribute);
1171cb0ef41Sopenharmony_ci    testSet("HTMLFrameSetElement", attribute);
1181cb0ef41Sopenharmony_ci    testEnumerate("HTMLFrameSetElement", attribute);
1191cb0ef41Sopenharmony_ci    testReflect("HTMLFrameSetElement", attribute);
1201cb0ef41Sopenharmony_ci    testForwardToWindow("HTMLFrameSetElement", attribute);
1211cb0ef41Sopenharmony_ci});
1221cb0ef41Sopenharmony_ci</script>
1231cb0ef41Sopenharmony_ci</html>
124