tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Body-FrameSet-Event-Handlers.html (4486B)


      1 <!DOCTYPE html>
      2 <html>
      3 <title>HTMLBodyElement and HTMLFrameSetElement Event Handler Tests</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 
      7 <script>
      8 function getObject(interface) {
      9    switch(interface) {
     10        case "Element":
     11            var e = document.createElementNS("http://example.com/", "example");
     12            assert_true(e instanceof Element);
     13            assert_false(e instanceof HTMLElement);
     14            assert_false(e instanceof SVGElement);
     15            return e;
     16        case "HTMLElement":
     17            var e = document.createElement("html");
     18            assert_true(e instanceof HTMLElement);
     19            return e;
     20        case "HTMLBodyElement":
     21            var e = document.createElement("body");
     22            assert_true(e instanceof HTMLBodyElement);
     23            return e;
     24        case "HTMLFormElement":
     25            var e = document.createElement("form");
     26            assert_true(e instanceof HTMLFormElement);
     27            return e;
     28        case "HTMLFrameSetElement":
     29            var e = document.createElement("frameset");
     30            assert_true(e instanceof HTMLFrameSetElement);
     31            return e;
     32        case "SVGElement":
     33            var e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
     34            assert_true(e instanceof SVGElement);
     35            return e;
     36        case "Document":
     37            assert_true(document instanceof Document);
     38            return document;
     39        case "Window":
     40            assert_true(window instanceof Window);
     41            return window;
     42    }
     43    assert_unreached();
     44 }
     45 
     46 function testSet(interface, attribute) {
     47    test(function() {
     48        var object = getObject(interface);
     49        function nop() {}
     50        assert_equals(object[attribute], null, "Initially null");
     51        object[attribute] = nop;
     52        assert_equals(object[attribute], nop, "Return same function");
     53        object[attribute] = "";
     54        assert_equals(object[attribute], null, "Return null after setting string");
     55        object[attribute] = null;
     56        assert_equals(object[attribute], null, "Finally null");
     57    }, "Set " + interface + "." + attribute);
     58 }
     59 
     60 function testReflect(interface, attribute) {
     61    test(function() {
     62        var element = getObject(interface);
     63        assert_false(element.hasAttribute(attribute), "Initially missing");
     64        element.setAttribute(attribute, "return");
     65        assert_equals(element.getAttribute(attribute), "return", "Return same string");
     66        assert_equals(typeof element[attribute], "function", "Convert to function");
     67        element.removeAttribute(attribute);
     68    }, "Reflect " + interface + "." + attribute);
     69 }
     70 
     71 function testForwardToWindow(interface, attribute) {
     72    test(function() {
     73        var element = getObject(interface);
     74        window[attribute] = null;
     75        element.setAttribute(attribute, "return");
     76        assert_equals(typeof window[attribute], "function", "Convert to function");
     77        assert_equals(window[attribute], element[attribute], "Forward content attribute");
     78        function nop() {}
     79        element[attribute] = nop;
     80        assert_equals(window[attribute], nop, "Forward IDL attribute");
     81        window[attribute] = null;
     82    }, "Forward " + interface + "." + attribute + " to Window");
     83 }
     84 
     85 // Object.propertyIsEnumerable cannot be used because it doesn't
     86 // work with properties inherited through the prototype chain.
     87 function getEnumerable(interface) {
     88    var enumerable = {};
     89    for (var attribute in getObject(interface)) {
     90        enumerable[attribute] = true;
     91    }
     92    return enumerable;
     93 }
     94 
     95 var enumerableCache = {};
     96 function testEnumerate(interface, attribute) {
     97    if (!(interface in enumerableCache)) {
     98        enumerableCache[interface] = getEnumerable(interface);
     99    }
    100    test(function() {
    101        assert_true(enumerableCache[interface][attribute]);
    102    }, "Enumerate " + interface + "." + attribute);
    103 }
    104 
    105 [
    106    "onblur",
    107    "onerror",
    108    "onfocus",
    109    "onload",
    110    "onscroll",
    111    "onresize"
    112 ].forEach(function(attribute) {
    113    testSet("HTMLBodyElement", attribute);
    114    testEnumerate("HTMLBodyElement", attribute);
    115    testReflect("HTMLBodyElement", attribute);
    116    testForwardToWindow("HTMLBodyElement", attribute);
    117    testSet("HTMLFrameSetElement", attribute);
    118    testEnumerate("HTMLFrameSetElement", attribute);
    119    testReflect("HTMLFrameSetElement", attribute);
    120    testForwardToWindow("HTMLFrameSetElement", attribute);
    121 });
    122 </script>
    123 </html>