Skip to content

Commit

Permalink
[DevTools] Migrate inspector-protocol/runtime tests to new harness
Browse files Browse the repository at this point in the history
BUG=734762

Review-Url: https://codereview.chromium.org/2954093003
Cr-Commit-Position: refs/heads/master@{#482493}
  • Loading branch information
dgozman authored and Commit Bot committed Jun 27, 2017
1 parent 43eb70f commit 9ea908c
Show file tree
Hide file tree
Showing 74 changed files with 1,118 additions and 1,842 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16504,8 +16504,8 @@ crbug.com/591099 inspector-protocol/layout-fonts/languages-emoji-rare-glyphs.htm
crbug.com/591099 inspector-protocol/network/resource-type.html [ Crash Failure ]
crbug.com/591099 inspector-protocol/network/websocket-initiator.html [ Failure ]
crbug.com/591099 inspector-protocol/page/get-layout-metrics.html [ Failure ]
crbug.com/591099 inspector-protocol/runtime/runtime-console-log-handle-navigate.html [ Failure Pass ]
crbug.com/591099 inspector-protocol/runtime/runtime-shouldnt-crash-after-inspected-context-destroyed.html [ Crash ]
crbug.com/591099 inspector-protocol/runtime/runtime-console-log-handle-navigate.js [ Failure Pass ]
crbug.com/591099 inspector-protocol/runtime/runtime-shouldnt-crash-after-inspected-context-destroyed.js [ Crash ]
crbug.com/591099 inspector/agents-enable-disable.html [ Failure ]
crbug.com/591099 inspector/animation/animation-KeyframeEffectReadOnly-crash.html [ Crash ]
crbug.com/591099 inspector/animation/animation-empty-web-animations.html [ Crash Failure ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ var TestRunner = class {
return this._baseURL + relative;
}

async runTestSuite(testSuite) {
for (var test of testSuite) {
this.log('\nRunning test: ' + test.name);
try {
await test();
} catch (e) {
this.log(`Error during test: ${e}\n${e.stack}`);
}
}
this.completeTest();
}

_checkExpectation(fail, name, messageObject) {
if (fail === !!messageObject.error) {
this.log('PASS: ' + name);
Expand All @@ -117,6 +129,11 @@ var TestRunner = class {
throw new Error(message);
}

fail(message) {
this.log('FAIL: ' + message);
this.completeTest();
}

async loadScript(url) {
var source = await this._fetch(this.url(url));
return eval(`${source}\n//# sourceURL=${url}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ Running test: testRejectedPromiseWithStack
parent : {
callFrames : [
[0] : {
columnNumber : 4
columnNumber : 6
functionName : rejectPromise
lineNumber : 21
lineNumber : 14
scriptId : 0
url :
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
(async function(testRunner) {
let {page, session, dp} = await testRunner.startBlank('Tests that Runtime.awaitPromise works.');

function dumpResult(result) {
if (result.exceptionDetails) {
if (result.exceptionDetails.stackTrace && result.exceptionDetails.stackTrace.parent) {
for (var frame of result.exceptionDetails.stackTrace.parent.callFrames) {
frame.scriptId = 0;
frame.url = '';
}
}
result.exceptionDetails.exceptionId = 0;
if (result.exceptionDetails.exception)
result.exceptionDetails.exception.objectId = 0;
}
testRunner.logObject(result);
}

await session.evaluate(`
var resolveCallback;
var rejectCallback;
function createPromise() {
return new Promise((resolve, reject) => { resolveCallback = resolve; rejectCallback = reject });
}
function resolvePromise() {
resolveCallback(239);
resolveCallback = undefined;
rejectCallback = undefined;
}
function rejectPromise() {
rejectCallback(239);
resolveCallback = undefined;
rejectCallback = undefined;
}
function runGC() {
if (window.gc)
window.gc();
}
`);

await dp.Debugger.enable();
await dp.Debugger.setAsyncCallStackDepth({ maxDepth: 128 });

await testRunner.runTestSuite([
async function testResolvedPromise() {
var result = await dp.Runtime.evaluate({ expression: 'Promise.resolve(239)'});
result = await dp.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId, returnByValue: false, generatePreview: true });
dumpResult(result.result);
},

async function testRejectedPromise() {
var result = await dp.Runtime.evaluate({ expression: 'Promise.reject({ a : 1 })'});
result = await dp.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId, returnByValue: true, generatePreview: false });
dumpResult(result.result);
},

async function testRejectedPromiseWithStack() {
var result = await dp.Runtime.evaluate({ expression: 'createPromise()'});
var promise = dp.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId });
dp.Runtime.evaluate({ expression: 'rejectPromise()' });
result = await promise;
dumpResult(result.result);
},

async function testPendingPromise() {
var result = await dp.Runtime.evaluate({ expression: 'createPromise()'});
var promise = dp.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId });
dp.Runtime.evaluate({ expression: 'resolvePromise()' });
result = await promise;
dumpResult(result.result);
},

async function testResolvedWithoutArgsPromise() {
var result = await dp.Runtime.evaluate({ expression: 'Promise.resolve()'});
result = await dp.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId, returnByValue: true, generatePreview: false });
dumpResult(result.result);
},

async function testGarbageCollectedPromise() {
var result = await dp.Runtime.evaluate({ expression: 'new Promise(() => undefined)'});
var objectId = result.result.result.objectId;
var promise = dp.Runtime.awaitPromise({ promiseObjectId: objectId });
dp.Runtime.releaseObject({ objectId: objectId}).then(() => dp.Runtime.evaluate({ expression: 'runGC()' }));
result = await promise;
testRunner.logObject(result.error);
}
]);
})
Loading

0 comments on commit 9ea908c

Please sign in to comment.