Commit 9a3b9b7b authored by Will Chen's avatar Will Chen Committed by Commit Bot

DevTools: improve TestRunner.evaluateInPage* API

Most of the call sites simply unwrap the value from the SDK.RemoteObject
returned from evaluateInPage*, this updates the API so it returns the plain
value and adds additional methods evaluateInPageRemoteObject{|Promise} for
the handful of callsites that need a RemoteObject.

Bug: 667560
Change-Id: I067b338056089f8263b0972f6630aa1e821eb846
Reviewed-on: https://chromium-review.googlesource.com/792010
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519914}
parent 81d9e65f
......@@ -25,7 +25,7 @@
TestRunner.addResult('Expected score must be equal to the actual score');
function step1(filePaths) {
var files = filePaths.value.split(':');
var files = filePaths.split(':');
TestRunner.addResult('Test set size: ' + files.length);
for (var i = 0; i < TestQueries.length; ++i) {
runQuery(files, TestQueries[i][0], TestQueries[i][1]);
......
......@@ -131,7 +131,7 @@
}
function dumpCounter(result) {
TestRunner.addResult('window.counter = ' + result.value);
TestRunner.addResult('window.counter = ' + result);
requestMyClassWithMixinCompletions();
}
......
......@@ -112,7 +112,7 @@
ConsoleTestRunner.evaluateInConsole('runTestsInPage(getEventListeners)', async function() {
const output = await TestRunner.evaluateInPageAsync('JSON.stringify(self._output)');
TestRunner.addResults(JSON.parse(output.value));
TestRunner.addResults(JSON.parse(output));
TestRunner.completeTest();
});
})();
......@@ -38,7 +38,7 @@
}
function step5(result) {
var text = result.description;
var text = result;
TestRunner.assertEquals(15, text.length, 'text length');
TestRunner.assertEquals(8, countTextNodes(text), 'nodes count');
TestRunner.assertEquals(1, countTextNodes('"' + text + '"'), 'nodes with quoted text count');
......
......@@ -46,7 +46,7 @@
function advance() {
var next = current + 1;
if (next == total.description)
if (next == total)
finish();
else
loopOverGlobals(next, total);
......
......@@ -127,7 +127,7 @@
function loopOverGlobals(current, total) {
function advance() {
var next = current + 1;
if (next == total.description)
if (next == total)
ConsoleTestRunner.waitForRemoteObjectsConsoleMessages(onRemoteObjectsLoaded);
else
loopOverGlobals(next, total);
......
......@@ -41,7 +41,7 @@
}
function dumpAccessedGetAndExpand(result) {
TestRunner.addResult('window.accessedGet = ' + result.value);
TestRunner.addResult('window.accessedGet = ' + result);
ConsoleTestRunner.expandConsoleMessages(dumpExpandedConsoleMessages);
}
......@@ -54,7 +54,7 @@
}
function dumpAccessedGetAndCompleteTest(result) {
TestRunner.addResult('window.accessedGet = ' + result.value);
TestRunner.addResult('window.accessedGet = ' + result);
TestRunner.completeTest();
}
......
......@@ -106,7 +106,7 @@
TestRunner.evaluateInPage('runNextPromiseTest()', callback);
function callback(result) {
if (!result.value)
if (!result)
ConsoleTestRunner.expandConsoleMessages(dump);
}
}
......
......@@ -26,7 +26,7 @@
var codeSnippetText;
function onCodeSnippet(result) {
codeSnippetText = result.value;
codeSnippetText = result;
TestRunner.runTestSuite(testSuite);
}
......
......@@ -31,7 +31,7 @@
var codeSnippetText;
function onCodeSnippet(result) {
codeSnippetText = result.value;
codeSnippetText = result;
TestRunner.runTestSuite(testSuite);
}
......
......@@ -48,7 +48,7 @@ function submitWord(url) {
TestRunner.evaluateInPage('codeSnippet();', onCodeSnippet);
function onCodeSnippet(result) {
var codeLines = result.value;
var codeLines = result;
textEditor.setText(codeLines);
TestRunner.runTestSuite(testSuite);
}
......
......@@ -48,7 +48,7 @@ function submitWord(url) {
TestRunner.evaluateInPage('codeSnippet();', onCodeSnippet);
function onCodeSnippet(result) {
var codeLines = result.value;
var codeLines = result;
textEditor.setText(codeLines);
TestRunner.runTestSuite(testSuite);
}
......
......@@ -40,7 +40,7 @@ while (sum &gt; 0) {
textEditor.element.focus();
function step2(result) {
var codeLines = result.value;
var codeLines = result;
SourcesTestRunner.typeIn(textEditor, codeLines, step3);
}
......
......@@ -29,7 +29,7 @@
var codeSnippetText;
function onCodeSnippet(result) {
codeSnippetText = result.value;
codeSnippetText = result;
TestRunner.runTestSuite(testSuite);
}
......
......@@ -127,7 +127,7 @@ c
var command = 'codeSnippet(\'' + snippetName + '\');';
TestRunner.evaluateInPage(command, step2);
function step2(result) {
textEditor.setText(result.value);
textEditor.setText(result);
var indent = textEditor.indent();
var description = indent === TextUtils.TextUtils.Indent.TabCharacter ? 'Tab' : indent.length + ' spaces';
TestRunner.addResult('Autodetected indentation for ' + snippetName + ': ' + description);
......@@ -137,8 +137,8 @@ c
function onTestNumberReceived(result) {
var testSuite = [];
TestRunner.addResult('Tests number: ' + result.value);
for (var i = 1; i <= result.value; ++i)
TestRunner.addResult('Tests number: ' + result);
for (var i = 1; i <= result; ++i)
testSuite.push(genericTest.bind(this, 'test' + i));
TestRunner.runTestSuite(testSuite);
......
......@@ -111,7 +111,7 @@
TestRunner.evaluateInPage('matchingElements(\'' + escapedPath + '\')', callback);
function callback(result) {
TestRunner.assertEquals(1, result.value);
TestRunner.assertEquals(1, result);
dumpNodeData();
}
}
......
......@@ -140,7 +140,7 @@
TestRunner.evaluateInPagePromise('pseudoIframeVisibility()').then(function(result) {
TestRunner.addResult('=== Added hide shortcut in frame ===');
TestRunner.addResult('=== Frame node is hidden ===');
TestRunner.addResult('visibility: ' + result.value + ';');
TestRunner.addResult('visibility: ' + result + ';');
next();
});
}
......@@ -156,7 +156,7 @@
function callback() {
var pseudoNodeTypeArg = pseudoNode.pseudoType() ? ('"' + pseudoNode.pseudoType() + '"') : 'undefined';
TestRunner.evaluateInPagePromise('pseudoVisibility(' + pseudoNodeTypeArg + ')').then(function(result) {
TestRunner.addResult('::' + pseudoNode.pseudoType() + ' node visibility: \'' + result.value + '\'');
TestRunner.addResult('::' + pseudoNode.pseudoType() + ' node visibility: \'' + result + '\'');
next();
});
}
......
......@@ -15,11 +15,9 @@
</p>
`);
TestRunner.evaluateInPage('document', didReceiveDocumentObject);
async function didReceiveDocumentObject(remoteObject) {
TestRunner.addResult('didReceiveDocumentObject');
var nodeId = await TestRunner.DOMAgent.requestNode(remoteObject.objectId);
TestRunner.addResult('didRequestNode error = ' + (nodeId ? 'null' : 'error'));
TestRunner.completeTest();
}
var remoteObject = await TestRunner.evaluateInPageRemoteObject('document');
TestRunner.addResult('didReceiveDocumentObject');
var nodeId = await TestRunner.DOMAgent.requestNode(remoteObject.objectId);
TestRunner.addResult('didRequestNode error = ' + (nodeId ? 'null' : 'error'));
TestRunner.completeTest();
})();
......@@ -20,13 +20,11 @@
}
`);
TestRunner.evaluateInPage('whitespaceChild()', childCallback);
var childObject = await TestRunner.evaluateInPageRemoteObject('whitespaceChild()');
function childCallback(childObject) {
ElementsTestRunner.firstElementsTreeOutline().addEventListener(
Elements.ElementsTreeOutline.Events.SelectedNodeChanged, selectedNodeChanged);
Common.Revealer.reveal(childObject);
}
ElementsTestRunner.firstElementsTreeOutline().addEventListener(
Elements.ElementsTreeOutline.Events.SelectedNodeChanged, selectedNodeChanged);
Common.Revealer.reveal(childObject);
function selectedNodeChanged(event) {
var node = event.data.node;
......
......@@ -71,7 +71,7 @@ function test() {
}
function onStyleFetched(result) {
Formatter.formatterWorkerPool().parseCSS(result.value, onRulesParsed);
Formatter.formatterWorkerPool().parseCSS(result, onRulesParsed);
}
TestRunner.evaluateInPage('getCSS()', onStyleFetched);
......
......@@ -12,7 +12,7 @@
`);
function callback(result) {
TestRunner.addResult('2 + 2 = ' + result.description);
TestRunner.addResult('2 + 2 = ' + result);
TestRunner.completeTest();
}
TestRunner.evaluateInPage('sum(2, 2)', callback);
......
......@@ -27,7 +27,7 @@
function checkGreetingSet(next) {
TestRunner.evaluateInPage('getGreeting()', callback);
function callback(result) {
TestRunner.addResult('Received: ' + result.value);
TestRunner.addResult('Received: ' + result);
next();
}
},
......
......@@ -48,7 +48,7 @@
async function callback() {
const output = await TestRunner.evaluateInPageAsync('originalJSONStringify(self._output)');
TestRunner.addResults(JSON.parse(output.value));
TestRunner.addResults(JSON.parse(output));
TestRunner.completeTest();
}
......
......@@ -41,7 +41,7 @@
async function step2() {
const output = await TestRunner.evaluateInPageAsync('JSON.stringify(self._output)');
TestRunner.addResults(JSON.parse(output.value));
TestRunner.addResults(JSON.parse(output));
var request1 = NetworkTestRunner.networkRequests().pop();
TestRunner.addResult(request1.url());
TestRunner.addResult('resource.type: ' + request1.resourceType());
......
......@@ -14,7 +14,7 @@
NetworkTestRunner.makeFetchInWorker('resource.php', {}, fetchCallback);
function fetchCallback(result) {
TestRunner.addResult('Fetch in worker result: ' + result.value);
TestRunner.addResult('Fetch in worker result: ' + result);
var requests = NetworkTestRunner.networkRequests();
requests.forEach((request) => {
......
......@@ -23,7 +23,7 @@
TestRunner.callFunctionInPageAsync('makeFetchesInWorker', [['./resource.php?1', './resource.php?2']])
.then((result) => {
TestRunner.addResult('Parallel fetch in worker result: ' + result.value);
TestRunner.addResult('Parallel fetch in worker result: ' + result);
var requests = NetworkTestRunner.networkRequests();
requests.forEach((request) => {
TestRunner.addResult(request.url());
......
......@@ -12,7 +12,7 @@
NetworkTestRunner.makeFetchInWorker('resource.php', {}, fetchCallback);
function fetchCallback(result) {
TestRunner.addResult('Fetch in worker result: ' + result.value);
TestRunner.addResult('Fetch in worker result: ' + result);
var requests = NetworkTestRunner.networkRequests();
requests.forEach((request) => {
......
......@@ -5,10 +5,7 @@
(async function() {
TestRunner.addResult(`Tests formatting of different types of remote objects.\n`);
function callback(result) {
TestRunner.addResult('date = ' + result.description.substring(0, 25));
TestRunner.completeTest();
}
TestRunner.evaluateInPage('new Date(2011, 11, 7, 12, 01)', callback);
var result = await TestRunner.evaluateInPageRemoteObject('new Date(2011, 11, 7, 12, 01)');
TestRunner.addResult('date = ' + result.description.substring(0, 25));
TestRunner.completeTest();
})();
......@@ -17,7 +17,7 @@
}
var result = await TestRunner.RuntimeAgent.callFunctionOn(sum.toString(), obj1.objectId);
TestRunner.addResult(result.value);
TestRunner.addResult(result);
next();
},
......@@ -31,7 +31,7 @@
var result =
await TestRunner.RuntimeAgent.callFunctionOn(format.toString(), obj1.objectId, [obj1, obj2, {value: 4}, {}]);
TestRunner.addResult(result.value);
TestRunner.addResult(result);
next();
}
]);
......
......@@ -13,7 +13,7 @@
TestRunner.evaluateInPage('dump()', dumpCallback);
function dumpCallback(result) {
TestRunner.addResult(result.value);
TestRunner.addResult(result);
next();
}
}
......@@ -49,7 +49,7 @@
TestRunner.evaluateInPage('dump()', dumpCallback);
function dumpCallback(result) {
original = result.value;
original = result;
next();
}
},
......@@ -94,7 +94,7 @@
}
function dumpCallback(result) {
TestRunner.addResult('Equals to initial: ' + (original === result.value ? 'true' : 'false'));
TestRunner.addResult('Equals to initial: ' + (original === result ? 'true' : 'false'));
next();
}
}
......
......@@ -19,7 +19,7 @@
ApplicationTestRunner.makeFetchInServiceWorker(scope, '../../network/resources/resource.php', {}, fetchCallback);
function fetchCallback(result) {
TestRunner.addResult('Fetch in worker result: ' + result.value);
TestRunner.addResult('Fetch in worker result: ' + result);
var requests = NetworkTestRunner.networkRequests();
requests.forEach((request) => {
......
......@@ -17,7 +17,7 @@
ApplicationTestRunner.makeFetchInServiceWorker(scope, '../../network/resources/resource.php', {}, fetchCallback);
function fetchCallback(result) {
TestRunner.addResult('Fetch in worker result: ' + result.value);
TestRunner.addResult('Fetch in worker result: ' + result);
var requests = NetworkTestRunner.networkRequests();
requests.forEach((request) => {
......
......@@ -41,7 +41,7 @@
function dumpInterceptedRequests() {
return TestRunner.callFunctionInPageAsync('takeInterceptedRequests', [scope]).then((data) => {
TestRunner.addResult('Intercepted requests:');
JSON.parse(data.value).forEach((request) => {
JSON.parse(data).forEach((request) => {
TestRunner.addResult(' url: ' + request.url);
TestRunner.addResult(' mode: ' + request.mode);
});
......@@ -52,15 +52,15 @@
TestRunner.addResult('CORS fetch(): ' + index);
return TestRunner.callFunctionInPageAsync('fetchInIframe', [target + '?type=txt&fetch' + index, frameId])
.then((data) => {
if (data.value !== 'hello') {
TestRunner.addResult('fetch response miss match: ' + data.value);
if (data !== 'hello') {
TestRunner.addResult('fetch response miss match: ' + data);
}
TestRunner.addResult('CORS XHR: ' + index);
return TestRunner.callFunctionInPageAsync('xhrInIframe', [target + '?type=txt&xhr' + index, frameId]);
})
.then((data) => {
if (data.value !== 'hello') {
TestRunner.addResult('XHR response miss match: ' + data.value);
if (data !== 'hello') {
TestRunner.addResult('XHR response miss match: ' + data);
}
TestRunner.addResult('CORS image: ' + index);
return TestRunner.callFunctionInPageAsync('corsImageInIframe', [target + '?type=img&img' + index, frameId]);
......
......@@ -28,7 +28,7 @@
return TestRunner.callFunctionInPageAsync('getIframeBodyText', [frame_id]);
})
.then((data) => {
TestRunner.addResult(' body: ' + data.value);
TestRunner.addResult(' body: ' + data);
});
}
......
......@@ -6,7 +6,7 @@
<script src="../../inspector/console-test.js"></script>
<script>
function test() {
async function test() {
const scriptURL = 'http://127.0.0.1:8000/devtools/service-workers/resources/changing-worker.php';
const scope = 'http://127.0.0.1:8000/devtools/service-workers/resources/service-worker-redundant-scope/';
const frameId = 'frame_id';
......@@ -15,58 +15,57 @@ function test() {
let secondVersionId = -1;
Resources.ServiceWorkersView._noThrottle = true;
TestRunner.evaluateInPage('frontendReopeningCount', function(result) {
if (result._description == '0') {
TestRunner.addSniffer(Resources.ServiceWorkersView.prototype, '_updateRegistration', updateRegistration, true);
function updateRegistration(registration) {
if (registration.scopeURL != scope)
return;
for (let version of registration.versions.values()) {
if (step == 0 && version.isRunning() && version.isActivated()) {
++step;
firstVersionId = version.id;
TestRunner.addResult('The first ServiceWorker is activated.');
TestRunner.addResult('==== ServiceWorkersView ====');
TestRunner.addResult(ApplicationTestRunner.dumpServiceWorkersView([scope]));
TestRunner.addResult('============================');
TestRunner.addIframe(scope, {id: frameId});
} else if (step == 1 && version.isRunning() && version.isInstalled()) {
++step;
secondVersionId = version.id;
TestRunner.addResult('The second Serviceworker is installed.');
TestRunner.addResult('==== ServiceWorkersView ====');
TestRunner.addResult(ApplicationTestRunner.dumpServiceWorkersView([scope]));
TestRunner.addResult('============================');
TestRunner.evaluateInPagePromise(`document.getElementById('${frameId}').remove();`);
}
}
if (step != 2)
return;
const firstVersion = registration.versions.get(firstVersionId);
const secondVersion = registration.versions.get(secondVersionId);
if ((!firstVersion || (firstVersion.isStopped() && firstVersion.isRedundant())) &&
secondVersion.isActivated() && secondVersion.isRunning()) {
var result = await TestRunner.evaluateInPageRemoteObject('frontendReopeningCount');
if (result._description == '0') {
TestRunner.addSniffer(Resources.ServiceWorkersView.prototype, '_updateRegistration', updateRegistration, true);
function updateRegistration(registration) {
if (registration.scopeURL != scope)
return;
for (let version of registration.versions.values()) {
if (step == 0 && version.isRunning() && version.isActivated()) {
++step;
firstVersionId = version.id;
TestRunner.addResult('The first ServiceWorker is activated.');
TestRunner.addResult('==== ServiceWorkersView ====');
TestRunner.addResult(ApplicationTestRunner.dumpServiceWorkersView([scope]));
TestRunner.addResult('============================');
TestRunner.addIframe(scope, {id: frameId});
} else if (step == 1 && version.isRunning() && version.isInstalled()) {
++step;
TestRunner.addResult('The first ServiceWorker worker became redundant and stopped.');
secondVersionId = version.id;
TestRunner.addResult('The second Serviceworker is installed.');
TestRunner.addResult('==== ServiceWorkersView ====');
TestRunner.addResult(ApplicationTestRunner.dumpServiceWorkersView([scope]));
TestRunner.addResult('============================');
TestRunner.flushResults();
TestRunner.evaluateInPage('reopenFrontend()');
TestRunner.evaluateInPagePromise(`document.getElementById('${frameId}').remove();`);
}
}
UI.panels.resources._sidebar.serviceWorkersTreeElement.select();
ApplicationTestRunner.registerServiceWorker(scriptURL, scope);
} else {
TestRunner.addResult('DevTools frontend is reopened.');
UI.panels.resources._sidebar.serviceWorkersTreeElement.select();
TestRunner.addResult('==== ServiceWorkersView ====');
TestRunner.addResult(ApplicationTestRunner.dumpServiceWorkersView([scope]));
TestRunner.addResult('============================');
ApplicationTestRunner.deleteServiceWorkerRegistration(scope);
TestRunner.completeTest();
if (step != 2)
return;
const firstVersion = registration.versions.get(firstVersionId);
const secondVersion = registration.versions.get(secondVersionId);
if ((!firstVersion || (firstVersion.isStopped() && firstVersion.isRedundant())) &&
secondVersion.isActivated() && secondVersion.isRunning()) {
++step;
TestRunner.addResult('The first ServiceWorker worker became redundant and stopped.');
TestRunner.addResult('==== ServiceWorkersView ====');
TestRunner.addResult(ApplicationTestRunner.dumpServiceWorkersView([scope]));
TestRunner.addResult('============================');
TestRunner.flushResults();
TestRunner.evaluateInPage('reopenFrontend()');
}
}
});
UI.panels.resources._sidebar.serviceWorkersTreeElement.select();
ApplicationTestRunner.registerServiceWorker(scriptURL, scope);
} else {
TestRunner.addResult('DevTools frontend is reopened.');
UI.panels.resources._sidebar.serviceWorkersTreeElement.select();
TestRunner.addResult('==== ServiceWorkersView ====');
TestRunner.addResult(ApplicationTestRunner.dumpServiceWorkersView([scope]));
TestRunner.addResult('============================');
ApplicationTestRunner.deleteServiceWorkerRegistration(scope);
TestRunner.completeTest();
}
}
</script>
......
......@@ -79,7 +79,7 @@
async function step4() {
const output = await TestRunner.evaluateInPageAsync('JSON.stringify(self._output)');
TestRunner.addResults(JSON.parse(output.value));
TestRunner.addResults(JSON.parse(output));
TestRunner.completeTest();
}
})();
......@@ -110,7 +110,7 @@
async function step10() {
const output = await TestRunner.evaluateInPageAsync('JSON.stringify(self._output)');
TestRunner.addResults(JSON.parse(output.value));
TestRunner.addResults(JSON.parse(output));
TestRunner.completeTest();
}
})();
......@@ -72,7 +72,7 @@
async function step4() {
const output = await TestRunner.evaluateInPageAsync('JSON.stringify(self._output)');
TestRunner.addResults(JSON.parse(output.value));
TestRunner.addResults(JSON.parse(output));
TestRunner.completeTest();
}
})();
......@@ -59,7 +59,7 @@
async function step6() {
const output = await TestRunner.evaluateInPageAsync('JSON.stringify(self._output)');
TestRunner.addResults(JSON.parse(output.value));
TestRunner.addResults(JSON.parse(output));
TestRunner.completeTest();
}
})();
......@@ -117,28 +117,26 @@
end();
}
function performStandardTestCase(pageExpression, next) {
TestRunner.evaluateInPage(pageExpression, didEvaluate);
async function didEvaluate(remote) {
TestRunner.addResult(pageExpression + ' type = ' + remote.type);
var response =
await TestRunner.RuntimeAgent.invoke_getProperties({objectId: remote.objectId, isOwnProperty: false});
var propertiesMap = new Map();
for (var prop of response.internalProperties)
propertiesMap.set(prop.name, prop);
for (var prop of response.result) {
if (prop.name === 'name' && prop.value && prop.value.type === 'string')
propertiesMap.set('name', prop);
if (prop.name === 'displayName' && prop.value && prop.value.type === 'string') {
propertiesMap.set('name', prop);
break;
}
async function performStandardTestCase(pageExpression, next) {
var remote = await TestRunner.evaluateInPageRemoteObject(pageExpression);
TestRunner.addResult(pageExpression + ' type = ' + remote.type);
var response =
await TestRunner.RuntimeAgent.invoke_getProperties({objectId: remote.objectId, isOwnProperty: false});
var propertiesMap = new Map();
for (var prop of response.internalProperties)
propertiesMap.set(prop.name, prop);
for (var prop of response.result) {
if (prop.name === 'name' && prop.value && prop.value.type === 'string')
propertiesMap.set('name', prop);
if (prop.name === 'displayName' && prop.value && prop.value.type === 'string') {
propertiesMap.set('name', prop);
break;
}
dumpFunctionDetails(propertiesMap);
loadAndDumpScopeObjects(propertiesMap.get('[[Scopes]]'), next);
}
dumpFunctionDetails(propertiesMap);
loadAndDumpScopeObjects(propertiesMap.get('[[Scopes]]'), next);
}
SourcesTestRunner.runDebuggerTestSuite([
......
......@@ -35,13 +35,11 @@
var panel = UI.panels.sources;
function performStandardTestCase(pageExpression, next) {
async function performStandardTestCase(pageExpression, next) {
TestRunner.addSniffer(panel, 'showUISourceCode', showUISourceCodeHook);
TestRunner.evaluateInPage(pageExpression, didEvaluate);
var remote = await TestRunner.evaluateInPageRemoteObject(pageExpression);
function didEvaluate(remote) {
remote.getOwnPropertiesPromise().then(revealLocation.bind(null, remote));
}
remote.getOwnPropertiesPromise().then(revealLocation.bind(null, remote));
function revealLocation(remote, properties) {
var loc;
......
......@@ -17,7 +17,7 @@
}
function step1(loc) {
TestRunner.addResult('window.location: ' + loc.description);
TestRunner.addResult('window.location: ' + loc);
SourcesTestRunner.showScriptSource('inline-scripts.html', step2);
}
......
......@@ -22,11 +22,8 @@
didEditScriptSource);
}
function didEditScriptSource() {
TestRunner.evaluateInPage('f()', didEvaluateInPage);
}
function didEvaluateInPage(result) {
async function didEditScriptSource() {
var result = await TestRunner.evaluateInPageRemoteObject('f()');
TestRunner.assertEquals(
'live-edited string', result.description,
'edited function returns wrong result');
......@@ -52,9 +49,12 @@
SourcesTestRunner.showScriptSource(
'edit-me-when-paused.js', didShowScriptSource);
function didShowScriptSource(sourceFrame) {
async function didShowScriptSource(sourceFrame) {
SourcesTestRunner.waitUntilPaused(paused);
TestRunner.evaluateInPage('f1()', didEvaluateInPage);
var result = await TestRunner.evaluateInPageRemoteObject('f1()');
TestRunner.assertEquals(
'3', result.description, 'edited function returns wrong result');
next();
}
function paused(callFrames) {
......@@ -66,12 +66,6 @@
function didEditScriptSource() {
SourcesTestRunner.resumeExecution();
}
function didEvaluateInPage(result) {
TestRunner.assertEquals(
'3', result.description, 'edited function returns wrong result');
next();
}
},
function testNoCrashWhenOnlyOneFunctionOnStack(next) {
......
......@@ -300,10 +300,10 @@ function showInspectorAndRunTest()
}
</script>
<script>
function test() {
async function test() {
TestRunner.hideInspectorView();
TestRunner.evaluateInPage('globals.length', loopOverGlobals.bind(this, 0));
var total = await TestRunner.evaluateInPageRemoteObject('globals.length');
loopOverGlobals(0, total);
function loopOverGlobals(current, total) {
function advance() {
var next = current + 1;
......
......@@ -27,23 +27,23 @@ async function test() {
var result = await TestRunner.RuntimeAgent.evaluate('window.objectId');
if (result.type !== 'string') {
TestRunner.evaluateInPage('console.log(\'Opening front-end for the first time\')');
TestRunner.evaluateInPageAnonymously('console.log(\'Opening front-end for the first time\')');
result = await TestRunner.RuntimeAgent.evaluate(`({ handle : "handle" })`);
checkHandleInInjectedScript(result.objectId, reopenInspector);
} else {
TestRunner.evaluateInPage('console.log(\'Opening front-end second time\')');
TestRunner.evaluateInPageAnonymously('console.log(\'Opening front-end second time\')');
checkHandleInInjectedScript(result.value, TestRunner.completeTest);
}
function reopenInspector() {
TestRunner.evaluateInPage('reopenWebInspector(\'' + escape(result.objectId) + '\')');
TestRunner.evaluateInPageAnonymously('reopenWebInspector(\'' + escape(result.objectId) + '\')');
}
async function checkHandleInInjectedScript(objectId, callback) {
var properties = await TestRunner.RuntimeAgent.getProperties(objectId, false);
TestRunner.evaluateInPage(
!properties ? 'console.log(\'Error resolving object\')' : 'console.log(\'Resolved object successfully\')',
callback);
var result = await TestRunner.evaluateInPageRemoteObject(
!properties ? 'console.log(\'Error resolving object\')' : 'console.log(\'Resolved object successfully\')');
callback(result);
}
}
......
......@@ -23,7 +23,7 @@
function assertAutosizingResult(expected, callback) {
function resultCallback(jsonResult) {
var result = JSON.parse(jsonResult.value);
var result = JSON.parse(jsonResult);
var actual = result.textHeight > 200;
TestRunner.addResult(
'Text ' + (actual ? 'was' : 'was not') + ' autosized. ' + (expected == actual ? 'PASS' : 'FAIL'));
......
......@@ -23,7 +23,7 @@
TestRunner.evaluateInPage('navigator.userAgent', step2);
function step2(result) {
TestRunner.addResult(result.value);
TestRunner.addResult(result);
TestRunner.completeTest();
}
})();
......@@ -50,7 +50,20 @@ InspectorTest.evaluateInPage = async function(code, callback)
objectGroup: "console"
});
if (!response[Protocol.Error])
InspectorTest.safeWrap(callback)(InspectorTest.runtimeModel.createRemoteObject(response.result), response.exceptionDetails);
InspectorTest.safeWrap(callback)(response.result.value, response.exceptionDetails);
}
/**
* TestRunner.evaluateInPageRemoteObject inserts sourceURL by inspecting the call stack.
*/
InspectorTest.evaluateInPageRemoteObject = async function(code, callback)
{
var response = await InspectorTest.RuntimeAgent.invoke_evaluate({
expression: code,
objectGroup: "console"
});
if (!response[Protocol.Error])
return InspectorTest.runtimeModel.createRemoteObject(response.result);
}
InspectorTest.addResult = function(text)
......
......@@ -351,14 +351,33 @@ TestRunner._setupTestHelpers = function(target) {
TestRunner.mainTarget = target;
};
/**
* @param {string} code
* @return {!Promise<*>}
*/
TestRunner.evaluateInPageRemoteObject = async function(code) {
var response = await TestRunner._evaluateInPage(code);
return TestRunner.runtimeModel.createRemoteObject(response.result);
};
/**
* @param {string} code
* @param {function(*, !Protocol.Runtime.ExceptionDetails=):void} callback
*/
TestRunner.evaluateInPage = async function(code, callback) {
var response = await TestRunner._evaluateInPage(code);
TestRunner.safeWrap(callback)(response.result.value, response.exceptionDetails);
};
/** @type {number} */
TestRunner._evaluateInPageCounter = 0;
/**
* @param {string|!Function} code
* @param {!Function} callback
* @param {string} code
* @return {!Promise<{response: !SDK.RemoteObject,
* exceptionDetails: (!Protocol.Runtime.ExceptionDetails|undefined)}>}
*/
TestRunner.evaluateInPage = async function(code, callback) {
TestRunner._evaluateInPage = async function(code) {
var lines = new Error().stack.split('at ');
// Handles cases where the function is safe wrapped
......@@ -374,22 +393,25 @@ TestRunner.evaluateInPage = async function(code, callback) {
if (code.indexOf('sourceURL=') === -1)
code += `//# sourceURL=${sourceURL}`;
var response = await TestRunner.RuntimeAgent.invoke_evaluate({expression: code, objectGroup: 'console'});
if (!response[Protocol.Error]) {
TestRunner.safeWrap(callback)(
TestRunner.runtimeModel.createRemoteObject(response.result), response.exceptionDetails);
var error = response[Protocol.Error];
if (error) {
TestRunner.addResult('Error: ' + error);
TestRunner.completeTest();
return;
}
return response;
};
/**
* Doesn't append sourceURL to snippets evaluated in inspected page
* to avoid churning test expectations
* @param {string} code
* @return {!Promise<undefined>}
* @return {!Promise<*>}
*/
TestRunner.evaluateInPageAnonymously = async function(code) {
var response = await TestRunner.RuntimeAgent.invoke_evaluate({expression: code, objectGroup: 'console'});
if (!response[Protocol.Error])
return Promise.resolve();
return response.result.value;
TestRunner.addResult(
'Error: ' +
(response.exceptionDetails && response.exceptionDetails.text || 'exception from evaluateInPageAnonymously.'));
......@@ -397,8 +419,8 @@ TestRunner.evaluateInPageAnonymously = async function(code) {
};
/**
* @param {string|!Function} code
* @return {!Promise<!SDK.RemoteObject>}
* @param {string} code
* @return {!Promise<*>}
*/
TestRunner.evaluateInPagePromise = function(code) {
return new Promise(success => TestRunner.evaluateInPage(code, success));
......@@ -406,7 +428,7 @@ TestRunner.evaluateInPagePromise = function(code) {
/**
* @param {string} code
* @return {!Promise<!SDK.RemoteObject|undefined>}
* @return {!Promise<*>}
*/
TestRunner.evaluateInPageAsync = async function(code) {
var response = await TestRunner.RuntimeAgent.invoke_evaluate(
......@@ -414,7 +436,7 @@ TestRunner.evaluateInPageAsync = async function(code) {
var error = response[Protocol.Error];
if (!error && !response.exceptionDetails)
return TestRunner.runtimeModel.createRemoteObject(response.result);
return response.result.value;
TestRunner.addResult(
'Error: ' +
(error || response.exceptionDetails && response.exceptionDetails.text || 'exception while evaluation in page.'));
......@@ -424,7 +446,7 @@ TestRunner.evaluateInPageAsync = async function(code) {
/**
* @param {string} name
* @param {!Array<*>} args
* @return {!Promise<!SDK.RemoteObject|undefined>}
* @return {!Promise<*>}
*/
TestRunner.callFunctionInPageAsync = function(name, args) {
args = args || [];
......@@ -483,7 +505,7 @@ TestRunner.deprecatedRunAfterPendingDispatches = function(callback) {
* are relative to the test file and not the inspected page
* (i.e. http/tests/devtools/resources/inspected-page.html).
* @param {string} html
* @return {!Promise<undefined>}
* @return {!Promise<*>}
*/
TestRunner.loadHTML = function(html) {
if (!html.includes('<base')) {
......@@ -501,7 +523,7 @@ TestRunner.loadHTML = function(html) {
/**
* @param {string} path
* @return {!Promise<!SDK.RemoteObject|undefined>}
* @return {!Promise<*>}
*/
TestRunner.addScriptTag = function(path) {
return TestRunner.evaluateInPageAsync(`
......@@ -516,7 +538,7 @@ TestRunner.addScriptTag = function(path) {
/**
* @param {string} path
* @return {!Promise<!SDK.RemoteObject|undefined>}
* @return {!Promise<*>}
*/
TestRunner.addStylesheetTag = function(path) {
return TestRunner.evaluateInPageAsync(`
......@@ -541,7 +563,7 @@ TestRunner.addStylesheetTag = function(path) {
/**
* @param {string} path
* @param {!Object|undefined} options
* @return {!Promise<!SDK.RemoteObject|undefined>}
* @return {!Promise<*>}
*/
TestRunner.addIframe = function(path, options = {}) {
options.id = options.id || '';
......@@ -1279,8 +1301,8 @@ TestRunner._printDevToolsConsole = function() {
* @param {string} querySelector
*/
TestRunner.dumpInspectedPageElementText = async function(querySelector) {
var remoteObject = await TestRunner.evaluateInPageAsync(`document.querySelector('${querySelector}').innerText`);
TestRunner.addResult(remoteObject.value);
var value = await TestRunner.evaluateInPageAsync(`document.querySelector('${querySelector}').innerText`);
TestRunner.addResult(value);
};
/** @type {boolean} */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment