Commit 0e3033a6 authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Chromium LUCI CQ

DevTools: add a test for chrome.devtools.inspectedWindow.eval using correct execution context

See also: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2602710

Bug: v8:11268, chromium:1101897
Change-Id: If57b53a910afe8945453f35689b63168c076db7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602709Reviewed-by: default avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839375}
parent 17cc9e53
Tests that webInspector.inspectedWindow.eval() only evaluates in the correct execution context
Started extension.
Running tests...
RUNNING TEST: extension_testEvaluateInFixedExecutionContext
error: Request Runtime.evaluate failed. {"code":-32602,"message":"uniqueContextId not found"}
error: uniqueContextId not found
error: Extension server error: Inspector protocol error: uniqueContextId not found
Got error, as expected: {"code":"E_PROTOCOLERROR","description":"Inspector protocol error: %s","details":["uniqueContextId not found"],"isError":true}
All tests done.
// 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.
(async function() {
TestRunner.addResult(
`Tests that webInspector.inspectedWindow.eval() only evaluates in the correct execution context\n`);
await TestRunner.loadModule('extensions_test_runner');
// First navigate to a new page to force a nice, clean renderer with predictable context ids.
await TestRunner.navigatePromise('http://devtools.a.test:8000/devtools/resources/empty.html');
let pendingInterceptionPromiseCallback;
TestRunner.startNavigation = async function(callback) {
SDK.multitargetNetworkManager.setInterceptionHandlerForPatterns([{
urlPattern: '*'}], interceptionHandler);
TestRunner.navigatePromise('http://devtools.b.test:8000/devtools/resources/empty.html');
function interceptionHandler(request) {
callback();
return new Promise(resolve => pendingInterceptionPromiseCallback = resolve);
}
}
TestRunner.completeNavigation = function() {
pendingInterceptionPromiseCallback();
}
await ExtensionsTestRunner.runExtensionTests([
async function extension_testEvaluateInFixedExecutionContext(nextTest) {
await evaluateOnFrontendPromise('TestRunner.startNavigation(reply)');
webInspector.inspectedWindow.eval('location.href', onEvaluate);
evaluateOnFrontendPromise('TestRunner.completeNavigation()');
function onEvaluate(result, error) {
if (result) {
output(`FAIL: expected error, got result: ${JSON.stringify(result)}`);
} else {
output(`Got error, as expected: ${JSON.stringify(error)}`);;
}
nextTest();
}
}
]);
})();
...@@ -50,6 +50,11 @@ function evaluateOnFrontend(expression, callback) ...@@ -50,6 +50,11 @@ function evaluateOnFrontend(expression, callback)
window._extensionServerForTests.sendRequest({ command: "evaluateForTestInFrontEnd", expression: expression }, callback); window._extensionServerForTests.sendRequest({ command: "evaluateForTestInFrontEnd", expression: expression }, callback);
} }
function evaluateOnFrontendPromise(expression, callback)
{
return new Promise(resolve => evaluateOnFrontend(expression, resolve));
}
function invokePageFunctionAsync(functionName, callback) function invokePageFunctionAsync(functionName, callback)
{ {
evaluateOnFrontend("TestRunner.callFunctionInPageAsync('" + functionName + "').then(() => reply())", callback); evaluateOnFrontend("TestRunner.callFunctionInPageAsync('" + functionName + "').then(() => reply())", callback);
......
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