summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis/scripting/events/event-handler-processing-algorithm-error/window-synthetic-errorevent.html
blob: 2d62d8a204fba8433333c41ccc17adf8864e8c2c (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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Event handlers processing algorithm: error events</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-event-handler-processing-algorithm">
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">

<div id="log"></div>

<script>
"use strict";
setup({ allow_uncaught_exception: true });

promise_test(t => {
  window.onerror = t.step_func((...args) => {
    assert_greater_than(args.length, 1);
    return true;
  });

  const eventWatcher = new EventWatcher(t, window, "error");
  const promise = eventWatcher.wait_for("error").then(e => {
    assert_equals(e.defaultPrevented, true);
  });

  window.dispatchEvent(new ErrorEvent("error", { cancelable: true }));

  return promise;
}, "error event is weird (return true cancels; many args) on Window, with a synthetic ErrorEvent");

promise_test(t => {
  const theError = { the: "error object" };

  window.onerror = t.step_func(function (message, filename, lineno, colno, error) {
    assert_equals(arguments.length, 5, "There must be exactly 5 arguments");
    assert_equals(message, "message");
    assert_equals(filename, "filename");
    assert_equals(lineno, 1);
    assert_equals(colno, 2);
    assert_equals(error, theError);
    return true;
  });

  const eventWatcher = new EventWatcher(t, window, "error");
  const promise = eventWatcher.wait_for("error");

  window.dispatchEvent(new ErrorEvent("error", {
    message: "message",
    filename: "filename",
    lineno: 1,
    colno: 2,
    error: theError
  }));

  return promise;
}, "error event has the right 5 args on Window, with a synthetic ErrorEvent");
</script>