blob: 3d0624b6510ba6f040812c6aa2ab8675953e1f54 [file] [log] [blame]
// Copyright 2017 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.
(async function() {
TestRunner.addResult(`Tests that pause on promise rejection works.\n`);
await TestRunner.loadModule('sources_test_runner');
await TestRunner.showPanel('sources');
await TestRunner.evaluateInPagePromise(`
function createPromise()
{
var result = {};
var p = new Promise(function(resolve, reject) {
result.resolve = resolve;
result.reject = reject;
});
result.promise = p;
return result;
}
async function asyncCaught(promise) {
try {
await promise;
} catch (e) { }
}
async function asyncUncaught(promise) {
await promise;
}
function testFunction()
{
var caught = createPromise();
var uncaught = createPromise();
asyncCaught(caught.promise);
asyncUncaught(uncaught.promise);
caught.reject(new Error("caught"));
uncaught.reject(new Error("uncaught"));
}
`);
SourcesTestRunner.setQuiet(true);
SourcesTestRunner.startDebuggerTest(step1);
function waitUntilPausedNTimes(count, callback) {
function inner() {
if (count--) SourcesTestRunner.waitUntilPausedAndDumpStackAndResume(inner);
else callback();
}
inner();
}
function step1() {
TestRunner.DebuggerAgent.setPauseOnExceptions(SDK.DebuggerModel.PauseOnExceptionsState.PauseOnUncaughtExceptions);
SourcesTestRunner.showScriptSource('async-pause-on-exception.js', step2);
}
function step2() {
TestRunner.addResult('=== Pausing only on uncaught exceptions ===');
SourcesTestRunner.runTestFunction();
waitUntilPausedNTimes(1, step3);
}
function step3() {
TestRunner.DebuggerAgent.setPauseOnExceptions(SDK.DebuggerModel.PauseOnExceptionsState.PauseOnAllExceptions);
TestRunner.addResult('\n=== Pausing on all exceptions ===');
SourcesTestRunner.runTestFunction();
waitUntilPausedNTimes(2, step4);
}
function step4() {
TestRunner.DebuggerAgent.setPauseOnExceptions(SDK.DebuggerModel.PauseOnExceptionsState.DontPauseOnExceptions);
SourcesTestRunner.completeDebuggerTest();
}
})();