summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_error_events.html
blob: 62cbb68dea4ed8d6088951d131410b7662058d40 (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
72
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test for error events being ErrorEvent</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
  setup({allow_uncaught_exception:true});
  var errorEvent;
  var file;
  var line;
  var msg;
  var column;
  var error;
  window.addEventListener("error", function errorListener(e) {
    window.removeEventListener("error", errorListener);
    errorEvent = e;
  });
  var oldOnerror = window.onerror;
  window.onerror = function(message, filename, lineno, columnno, errorObject) {
    window.onerror = oldOnerror;
    file = filename;
    line = lineno;
    msg = message;
    column = columnno;
    error = errorObject;
  }
  var thrown = new Error("hello");
  throw thrown;
</script>
<script>
  generate_tests(assert_equals, [
    [ "Event filename", errorEvent.filename, location.href ],
    [ "Callback filename", file, location.href ],
    [ "Event line number", errorEvent.lineno, 28 ],
    [ "Callback line number", line, 28 ],
    [ "Event message", errorEvent.message, "Error: hello" ],
    [ "Callback message", msg, "Error: hello" ],
    [ "Event error-object", errorEvent.error, thrown],
    [ "Callback error-object", error, thrown ],
    [ "Event column", errorEvent.colno, 16 ],
    [ "Callback column", column, 16 ]
  ]);
</script>
<script>
  var workerLocation = location.protocol + "//" + location.host +
    location.pathname.replace("test_error_events.html", "error_event_worker.js");
  var eventFileTest = async_test("Worker event filename");
  var eventLineTest = async_test("Worker event line number");
  var eventMessageTest = async_test("Worker event message");
  var callbackFileTest = async_test("Worker callback filename");
  var callbackLineTest = async_test("Worker callback line number");
  var callbackMessageTest = async_test("Worker callback message");
  var w = new Worker("error_event_worker.js");
  w.addEventListener("message", function(msg) {
    if (msg.data.type == "event") {
      eventFileTest.step(function() { assert_equals(msg.data.filename, workerLocation); });
      eventFileTest.done();
      eventLineTest.step(function() { assert_equals(msg.data.lineno, 15); });
      eventLineTest.done();
      eventMessageTest.step(function() { assert_equals(msg.data.message, "Error: workerhello"); });
      eventMessageTest.done();
    } else {
      callbackFileTest.step(function() { assert_equals(msg.data.filename, workerLocation); });
      callbackFileTest.done();
      callbackLineTest.step(function() { assert_equals(msg.data.lineno, 15); });
      callbackLineTest.done();
      callbackMessageTest.step(function() { assert_equals(msg.data.message, "Error: workerhello"); });
      callbackMessageTest.done();
    }
  });
</script>