summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-attributes-windowless-body.html
blob: 9b81d42ff729399d57e182abc8b8950cef503e12 (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
<!doctype html>
<meta charset="utf-8">
<title></title>
<body></body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="resources/event-handler-body.js"></script>
<script>
setup({ explicit_done: true });
const elements = ['body', 'frameset'];
handlersListPromise.then(({ shadowedHandlers, notShadowedHandlers }) => {
  elements.forEach(function (elementName) {
    shadowedHandlers.forEach(function (eventName) {
      var handlerName = "on" + eventName;

      test(function() {
        var windowHandler = function () { return "Handler attached to the window"; };
        window[handlerName] = windowHandler;

        var d = (new DOMParser).parseFromString('', 'text/html');
        var b = d.createElement(elementName);

        assert_equals(b[handlerName], null);

        window[handlerName] = null;
      }, "Return null when getting the " + eventName + " event handler of a windowless " + elementName);

      test(function() {
        var windowHandler = function () { return "Handler attached to the window"; };
        window[handlerName] = windowHandler;

        var d = (new DOMParser).parseFromString('', 'text/html');
        var b = d.createElement(elementName);
        b[handlerName] = function() { return "Handler attached to windowless element"; };

        assert_equals(window[handlerName], windowHandler);
        assert_equals(b[handlerName], null);

        // Clean up window event handler
        window[handlerName] = null;
      }, "Ignore setting of " + eventName + " window event handlers on windowless " + elementName);
    });

    notShadowedHandlers.forEach(function (eventName) {
      var handlerName = "on" + eventName;

      test(function() {
        var windowHandler = function () { return "Handler attached to the window"; };
        window[handlerName] = windowHandler;

        var d = (new DOMParser).parseFromString('', 'text/html');
        var b = d.createElement(elementName);

        assert_equals(b[handlerName], null);

        var elementHandler = function () { return "Handler attached to the element"; };
        b[handlerName] = elementHandler;

        assert_equals(window[handlerName], windowHandler);
        assert_equals(b[handlerName], elementHandler);

        // Clean up window event handler
        window[handlerName] = null;
      }, eventName + " is unaffected on a windowless " + elementName);
    });
  });

  done();
});
</script>