summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/webui_js_error/webui_js_error.ts
blob: 6ae515c4175e34fb9fb92568a9b1818b2f054022 (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
73
74
75
76
77
78
79
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {$} from 'chrome://resources/js/util.m.js';

/**
 * @fileoverview This JavaScript prints an error message, throws uncaught
 * exceptions, and otherwise does erroneous things for testing.
 *
 * Note that function names and error text are referenced in integration tests
 * (particularly tast tests); do not change them without updating the tests.
 */

/**
 * Logs an error when called. This is the "during page load" error.
 */
function logsErrorDuringPageLoadOuter() {
  logsErrorDuringPageLoadInner();
}

/**
 * Logs an error when called. This is a separate function from
 * logsErrorDuringPageLoadOuter() so that we get an interesting stack.
 */
function logsErrorDuringPageLoadInner() {
  console.error('WebUI JS Error: printing error on page load');
}

/**
 * Logs an error when called. This is the "from button click" error.
 */
function logsErrorFromButtonClickHandler() {
  logsErrorFromButtonClickInner();
}

/**
 * Logs an error when called. This is a separate function from
 * logsErrorFromButtonClickHandler() so that we get an interesting stack.
 */
function logsErrorFromButtonClickInner() {
  console.error('WebUI JS Error: printing error on button click');
}

/**
 * Throws an exception when called.
 */
function throwExceptionHandler() {
  throwExceptionInner();
}

/**
 * Throws an exception when called. This is a separate function from
 * throwExceptionHandler() so that we get an interesting stack.
 */
function throwExceptionInner() {
  throw new Error('WebUI JS Error: exception button clicked');
}

/**
 * Success callback for the promise. This should never be called.
 */
function promiseSuccessful() {
  console.error('WebUI JS Error: Promise success. This should never happen');
}

/**
 * Creates a promise which will be rejected and doesn't handle the rejection.
 */
function unhandledPromiseRejection() {
  const promise =
      Promise.reject('WebUI JS Error: The rejector always rejects!');
  promise.then(promiseSuccessful);
}

$('error-button').onclick = logsErrorFromButtonClickHandler;
$('exception-button').onclick = throwExceptionHandler;
$('promise-button').onclick = unhandledPromiseRejection;
logsErrorDuringPageLoadOuter();