summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-processing-algorithm.html
blob: f3848b5ad903363bae0ccd69693d65db8804b245 (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
<!DOCTYPE html>
<title>Event handlers processing algorithm</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
 <body>
 <div id="foo" style="width: 100px; height: 100px; background-color: black"></div>
 <script>
 async_test(function(t) {
     var ev = new Event('mouseover', {cancelable: true});
     document.getElementById("foo").onmouseover = t.step_func(function() { return true });
     document.getElementById("foo").dispatchEvent(ev);
     assert_equals(ev.defaultPrevented, true)
     t.done();
 }, "mouseover listener returning true cancels event");

 async_test(function(t) {
     var ev = new Event('mouseover', {cancelable: true});
     document.getElementById("foo").onmouseover = t.step_func(function() { return false; });
     document.getElementById("foo").dispatchEvent(ev);
     assert_equals(ev.defaultPrevented, false);
     t.done();
 }, "mouseover listener returning false doesn't cancel event");

 async_test(function(t) {
     var ev = new Event('beforeunload', {cancelable: true});
     window.onbeforeunload = t.step_func(function() {return null});
     window.dispatchEvent(ev);
     assert_equals(ev.defaultPrevented, true);
     t.done();
 }, "beforeunload listener returning null cancels event");

 async_test(function(t) {
     var ev = new Event('beforeunload', {cancelable: true});
     window.onbeforeunload = t.step_func(function() {return true});
     window.dispatchEvent(ev);
     assert_equals(ev.defaultPrevented, false);
     t.done();
 }, "beforeunload listener returning non-null doesn't cancel event");

 async_test(function(t) {
     var ev = new Event("click", {cancelable: true});
     document.getElementById("foo").onclick = t.step_func(function() { return false; });
     document.getElementById("foo").dispatchEvent(ev);
     assert_equals(ev.defaultPrevented, true);
     t.done();
 }, "click listener returning false cancels event");

 async_test(function(t) {
     var ev = new Event("blur", {cancelable: true});
     document.getElementById("foo").onblur = t.step_func(function() { return false; });
     document.getElementById("foo").dispatchEvent(ev);
     assert_equals(ev.defaultPrevented, true);
     t.done();
 }, "blur listener returning false cancels event");

 async_test(function(t) {
     var ev = new Event("dblclick", {cancelable: true});
     document.getElementById("foo").ondblclick = t.step_func(function() { return false; });
     document.getElementById("foo").dispatchEvent(ev);
     assert_equals(ev.defaultPrevented, true);
     t.done();
 }, "dblclick listener returning false cancels event");
</script>