v8/test/inspector/debugger/resource-name-to-url.js
Alexey Kozyatinskiy dbfcc4878a [inspector] added V8InspectorClient::resourceNameToUrl
Some clients (see Node.js) use platform path as ScriptOrigin.
Reporting platform path in protocol makes using protocol much harder.
This CL introduced V8InspectorClient::resourceNameToUrl method that
is called for any reported using protocol url.
V8Inspector uses url internally as well so protocol client may generate
pattern for blackboxing with file urls only and does not need to build
complicated regexp that covers files urls and platform paths on
different platforms.

R=lushnikov@chromium.org
TBR=yangguo@chromium.org

Bug: none
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iff302e7441df922fa5d689fe510f5a9bfd470b9b
Reviewed-on: https://chromium-review.googlesource.com/1164624
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55029}
2018-08-09 21:36:24 +00:00

50 lines
1.9 KiB
JavaScript

// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start(
'Tests V8InspectorClient::resourceNameToUrl.');
(async function test(){
Protocol.Runtime.enable();
await Protocol.Debugger.enable();
contextGroup.addScript(`inspector.setResourceNamePrefix('prefix://')`);
await Protocol.Debugger.onceScriptParsed();
InspectorTest.log('Check script with url:');
contextGroup.addScript('function foo(){}', 0, 0, 'url');
InspectorTest.logMessage(await Protocol.Debugger.onceScriptParsed());
InspectorTest.log('Check script with sourceURL comment:');
contextGroup.addScript('function foo(){} //# sourceURL=foo.js', 0, 0, 'url');
InspectorTest.logMessage(await Protocol.Debugger.onceScriptParsed());
InspectorTest.log('Check script failed to parse:');
contextGroup.addScript('function foo(){', 0, 0, 'url');
InspectorTest.logMessage(await Protocol.Debugger.onceScriptFailedToParse());
InspectorTest.log('Check script failed to parse with sourceURL comment:');
contextGroup.addScript('function foo(){ //# sourceURL=foo.js', 0, 0, 'url');
InspectorTest.logMessage(await Protocol.Debugger.onceScriptFailedToParse());
InspectorTest.log('Test runtime stack trace:');
contextGroup.addScript(`
function foo() {
console.log(42);
}
eval('foo(); //# sourceURL=boo.js');
`, 0, 0, 'url');
InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
InspectorTest.log('Test debugger stack trace:');
contextGroup.addScript(`
function foo() {
debugger;
}
eval('foo(); //# sourceURL=boo.js');
`, 0, 0, 'url');
const {params:{callFrames}} = await Protocol.Debugger.oncePaused();
InspectorTest.logMessage(callFrames.map(frame => frame.url));
InspectorTest.completeTest();
})();