haikuwebkit/LayoutTests/inspector/unit-tests/globals-unhandled-rejection...

18 lines
464 B
HTML
Raw Permalink Normal View History

Web Inspector: Test.html should support globals reportInternalError, reportUnhandledRejection, reportUncaughtException https://bugs.webkit.org/show_bug.cgi?id=161358 <rdar://problem/28066446> Reviewed by Joseph Pecoraro. Source/WebInspectorUI: We have a hodgepodge of redundant code that reports uncaught exceptions in the inspector page. There is better handling of uncaught exceptions in the inspected page, such as including stack traces. This patch consolidates a lot of this code and makes it possible to report unhandled promise rejections, top-level uncaught exceptions, and exceptions caught in a try-catch block. The formatting and sanitization code for all of these things is shared and consistent. Finally, some tests have been added to catch regressions in unhandled rejection/uncaught exception reporting. * UserInterface/Test/FrontendTestHarness.js: (FrontendTestHarness): Explicitly set initial flag state here so it's easy to find all flags. (FrontendTestHarness.prototype.redirectConsoleToTestOutput): Extract this code to sanitize stack frames and put it in TestHarness. It is used by other methods that need to print stack frames. (FrontendTestHarness.prototype.reportUnhandledRejection): (FrontendTestHarness.prototype.reportUncaughtException): Added. Sanitize stack trace data so it is deterministic. Log the message to the original window.console but don't exit early. Sometimes the test page is not fully loaded if we throw an exception quite early in the test() method, and there's no harm in not early returning. If we do early return in this case, then a test that uses reportUncaughtException on purpose may not complete because the call to completeTest() would be skipped by returning early. (FrontendTestHarness.prototype.reportUncaughtExceptionFromEvent): Renamed from reportUncaughtException since the signature of that method suggests it should have a single exception argument rather than lots of data arguments. * UserInterface/Test/Test.js: Add globals. * UserInterface/Test/TestHarness.js: (TestHarness): Document class flags. (TestHarness.sanitizeURL): (TestHarness.sanitizeStackFrame): (TestHarness.prototype.sanitizeStack): Extract this code from other parts of the test harness. Make sanitizeStack an instance method so that there is only one place that needs to check the 'suppressStackTraces' flag. * UserInterface/Test/TestSuite.js: (TestSuite.prototype.logThrownObject): (TestSuite): (AsyncTestSuite.prototype.runTestCases): (AsyncTestSuite): (SyncTestSuite.prototype.runTestCases): (SyncTestSuite): (TestSuite.messageFromThrownObject): Deleted. Inline some helpers with only one use-site and consolidate redundant code for adding an exception and message to the test results. LayoutTests: Improve uncaught exception reporting and add some tests to document new and existing behavior. * http/tests/inspector/resources/inspector-test.js: (runTest.runTestMethodInFrontend): (runTest): Outsource reporting of an uncaught exception while injecting a method into the frontend. By doing this, we can make the report using the actual exception object since it doesn't go through window.onerror. * inspector/unit-tests/async-test-suite-expected.txt: * inspector/unit-tests/async-test-suite.html: * inspector/unit-tests/sync-test-suite-expected.txt: * inspector/unit-tests/sync-test-suite.html: Rebaseline and force suppression of stack traces, which are not deterministic across commits due to logging specific lines and columns in TestCombined.js. * inspector/unit-tests/globals-uncaught-exception-from-timer-callback-expected.txt: Added. * inspector/unit-tests/globals-uncaught-exception-from-timer-callback.html: Added. * inspector/unit-tests/globals-uncaught-exception-in-test-function-expected.txt: Added. * inspector/unit-tests/globals-uncaught-exception-in-test-function.html: Added. * inspector/unit-tests/globals-uncaught-exception-in-test-suite-expected.txt: Added. * inspector/unit-tests/globals-uncaught-exception-in-test-suite.html: Added. * inspector/unit-tests/globals-unhandled-rejection-in-test-function-expected.txt: Added. * inspector/unit-tests/globals-unhandled-rejection-in-test-function.html: Added. * inspector/unit-tests/globals-unhandled-rejection-in-test-suite-expected.txt: Added. * inspector/unit-tests/globals-unhandled-rejection-in-test-suite.html: Added. * inspector/unit-tests/globals-unhandled-rejection-in-timer-callback-expected.txt: Added. * inspector/unit-tests/globals-unhandled-rejection-in-timer-callback.html: Added. Canonical link: https://commits.webkit.org/183877@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210367 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-01-05 20:07:44 +00:00
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
InspectorTest.suppressStackTraces = true;
reportUnhandledRejection(new Error("This is an exception thrown in the inspector page."));
}
</script>
</head>
<body onload="runTest()">
<p>Test that the unhandled hook will immediately terminate the test and print the associated exception and stack trace.</p>
</body>
</html>