Commit e76a0ffd authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

Prepare web tests for upcoming source mapping asyncification

This CL prepares the remaining web tests for asynchronous source
mapping. This includes properly awaiting methods that will be marked
async or waiting for live location updates in links.

Bug: chromium:1032016
Change-Id: I828296aeb6b256ce60247440556e40f3efce6c3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2069321Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744204}
parent 1247e7af
...@@ -54,10 +54,10 @@ ...@@ -54,10 +54,10 @@
var uiSourceCode2 = var uiSourceCode2 =
Workspace.workspace.uiSourceCodeForURL('http://127.0.0.1:8000/devtools/resources/source2.js'); Workspace.workspace.uiSourceCodeForURL('http://127.0.0.1:8000/devtools/resources/source2.js');
SourcesTestRunner.checkUILocation(uiSourceCode1, 4, 4, uiLocation(script, 0, 81)); SourcesTestRunner.checkUILocation(uiSourceCode1, 4, 4, await uiLocation(script, 0, 81));
SourcesTestRunner.checkUILocation(uiSourceCode1, 5, 4, uiLocation(script, 0, 93)); SourcesTestRunner.checkUILocation(uiSourceCode1, 5, 4, await uiLocation(script, 0, 93));
SourcesTestRunner.checkUILocation(uiSourceCode2, 7, 4, uiLocation(script, 1, 151)); SourcesTestRunner.checkUILocation(uiSourceCode2, 7, 4, await uiLocation(script, 1, 151));
SourcesTestRunner.checkUILocation(originalUISourceCode, 1, 200, uiLocation(script, 1, 200)); SourcesTestRunner.checkUILocation(originalUISourceCode, 1, 200, await uiLocation(script, 1, 200));
SourcesTestRunner.checkRawLocation( SourcesTestRunner.checkRawLocation(
script, 0, 48, (await Bindings.debuggerWorkspaceBinding.uiLocationToRawLocations(uiSourceCode1, 3, 10))[0]); script, 0, 48, (await Bindings.debuggerWorkspaceBinding.uiLocationToRawLocations(uiSourceCode1, 3, 10))[0]);
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
async function originalUISourceCodeAdded(uiSourceCode) { async function originalUISourceCodeAdded(uiSourceCode) {
TestRunner.addResult('source3.js UISourceCode arrived'); TestRunner.addResult('source3.js UISourceCode arrived');
SourcesTestRunner.checkUILocation(uiSourceCode, 2, 4, uiLocation(script, 0, 18)); SourcesTestRunner.checkUILocation(uiSourceCode, 2, 4, await uiLocation(script, 0, 18));
SourcesTestRunner.checkRawLocation( SourcesTestRunner.checkRawLocation(
script, 0, 18, (await Bindings.debuggerWorkspaceBinding.uiLocationToRawLocations(uiSourceCode, 2, 4))[0]); script, 0, 18, (await Bindings.debuggerWorkspaceBinding.uiLocationToRawLocations(uiSourceCode, 2, 4))[0]);
...@@ -134,12 +134,12 @@ ...@@ -134,12 +134,12 @@
TestRunner.debuggerModel.sourceMapManager().addEventListener( TestRunner.debuggerModel.sourceMapManager().addEventListener(
SDK.SourceMapManager.Events.SourceMapFailedToAttach, onSourceMapLoaded, this); SDK.SourceMapManager.Events.SourceMapFailedToAttach, onSourceMapLoaded, this);
function onSourceMapLoaded(event) { async function onSourceMapLoaded(event) {
var script = event.data; var script = event.data;
if (script.sourceMapURL !== 'http://127.0.0.1:8000/devtools/resources/source-map.json_') if (script.sourceMapURL !== 'http://127.0.0.1:8000/devtools/resources/source-map.json_')
return; return;
TestRunner.addResult('SourceMap Failed to load.'); TestRunner.addResult('SourceMap Failed to load.');
var location = uiLocation(script, 0, 0); var location = await uiLocation(script, 0, 0);
TestRunner.addResult(location.uiSourceCode.url().replace(/VM\d+/g, 'VM')); TestRunner.addResult(location.uiSourceCode.url().replace(/VM\d+/g, 'VM'));
next(); next();
} }
......
...@@ -65,11 +65,16 @@ ...@@ -65,11 +65,16 @@
function consoleMessageAdded() { function consoleMessageAdded() {
SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAdded, wrappedConsoleMessageAdded); SDK.consoleModel.removeEventListener(SDK.ConsoleModel.Events.MessageAdded, wrappedConsoleMessageAdded);
Console.ConsoleView.instance()._invalidateViewport(); Console.ConsoleView.instance()._invalidateViewport();
var xpathResult = document.evaluate("//span[@class='devtools-link' and starts-with(., 'extensions-panel.html')]", Console.ConsoleView.instance()._viewport.element, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
var click = document.createEvent("MouseEvent"); // Trigger link creation so we can properly await pending live location updates. Needed so we can
click.initMouseEvent("click", true, true); // click the link in the first place.
xpathResult.singleNodeValue.dispatchEvent(click); for (const messageView of Console.ConsoleView.instance()._visibleViewMessages) messageView.element();
TestRunner.waitForPendingLiveLocationUpdates().then(() => {
var xpathResult = document.evaluate("//span[@class='devtools-link' and starts-with(., 'extensions-panel.html')]", Console.ConsoleView.instance()._viewport.element, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
var click = document.createEvent("MouseEvent");
click.initMouseEvent("click", true, true);
xpathResult.singleNodeValue.dispatchEvent(click);
});
} }
} }
......
...@@ -11,12 +11,18 @@ ...@@ -11,12 +11,18 @@
TestRunner.clickOnURL = function() { TestRunner.clickOnURL = function() {
UI.viewManager.showView("console").then(() => { UI.viewManager.showView("console").then(() => {
Console.ConsoleView.instance()._updateMessageList(); Console.ConsoleView.instance()._updateMessageList();
var xpathResult = document.evaluate("//span[@class='devtools-link' and starts-with(., 'test-script.js')]",
Console.ConsoleView.instance().element, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
var click = document.createEvent("MouseEvent"); // Trigger link creation so we can properly await pending live location updates. Needed so we can
click.initMouseEvent("click", true, true); // click the link in the first place.
xpathResult.singleNodeValue.dispatchEvent(click); for (const messageView of Console.ConsoleView.instance()._visibleViewMessages) messageView.element();
TestRunner.waitForPendingLiveLocationUpdates().then(() => {
var xpathResult = document.evaluate("//span[@class='devtools-link' and starts-with(., 'test-script.js')]",
Console.ConsoleView.instance().element, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
var click = document.createEvent("MouseEvent");
click.initMouseEvent("click", true, true);
xpathResult.singleNodeValue.dispatchEvent(click);
});
}); });
} }
......
...@@ -30,7 +30,11 @@ ...@@ -30,7 +30,11 @@
var xhrNode = await NetworkTestRunner.waitForNetworkLogViewNodeForRequest(request); var xhrNode = await NetworkTestRunner.waitForNetworkLogViewNodeForRequest(request);
UI.panels.network._networkLogView._refresh(); UI.panels.network._networkLogView._refresh();
for (var columnName of columnsToTest) for (var columnName of columnsToTest) {
TestRunner.addResult(columnName + ': ' + xhrNode.createCell(columnName).textContent); const cell = xhrNode.createCell(columnName);
// Cell may contain live locations that are unresolved.
await TestRunner.waitForPendingLiveLocationUpdates();
TestRunner.addResult(columnName + ': ' + cell.textContent);
}
TestRunner.completeTest(); TestRunner.completeTest();
})(); })();
...@@ -19,12 +19,16 @@ ...@@ -19,12 +19,16 @@
} }
pageFunction();`); pageFunction();`);
function checkFunction(tree, name) { async function checkFunction(tree, name) {
let node = tree.children[0]; let node = tree.children[0];
if (!node) if (!node)
TestRunner.addResult('no node'); TestRunner.addResult('no node');
while (node) { while (node) {
const url = node.element().children[2].lastChild.textContent; // Ordering is important here, as accessing the element the first time around
// triggers live location creation and updates which we need to await properly.
const element = node.element();
await TestRunner.waitForPendingLiveLocationUpdates();
const url = element.children[2].lastChild.textContent;
if (node.functionName === name) { if (node.functionName === name) {
TestRunner.addResult(`found ${name} ${url}`); TestRunner.addResult(`found ${name} ${url}`);
return; return;
...@@ -34,12 +38,12 @@ ...@@ -34,12 +38,12 @@
TestRunner.addResult(name + ' not found'); TestRunner.addResult(name + ' not found');
} }
function findPageFunctionInProfileView(view) { async function findPageFunctionInProfileView(view) {
const tree = view.profileDataGridTree; const tree = view.profileDataGridTree;
if (!tree) if (!tree)
TestRunner.addResult('no tree'); TestRunner.addResult('no tree');
checkFunction(tree, 'pageFunction'); await checkFunction(tree, 'pageFunction');
checkFunction(tree, '(anonymous)'); await checkFunction(tree, '(anonymous)');
next(); next();
} }
}]); }]);
......
...@@ -26,16 +26,20 @@ ...@@ -26,16 +26,20 @@
const tree = view.profileDataGridTree; const tree = view.profileDataGridTree;
if (!tree) if (!tree)
TestRunner.addResult('no tree'); TestRunner.addResult('no tree');
checkFunction(tree, 'pageFunction'); await checkFunction(tree, 'pageFunction');
checkFunction(tree, '(anonymous)'); await checkFunction(tree, '(anonymous)');
next(); next();
function checkFunction(tree, name) { async function checkFunction(tree, name) {
let node = tree.children[0]; let node = tree.children[0];
if (!node) if (!node)
TestRunner.addResult('no node'); TestRunner.addResult('no node');
while (node) { while (node) {
const url = node.element().children[2].lastChild.textContent; const element = node.element();
// Ordering is important here, as accessing the element the first time around
// triggers live location creation and updates which we need to await properly.
await TestRunner.waitForPendingLiveLocationUpdates();
const url = element.children[2].lastChild.textContent;
if (node.functionName === name) { if (node.functionName === name) {
TestRunner.addResult(`found ${name} ${url}`); TestRunner.addResult(`found ${name} ${url}`);
return; return;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
SourcesTestRunner.showScriptSource('linkifier.html', debuggerTest); SourcesTestRunner.showScriptSource('linkifier.html', debuggerTest);
} }
function debuggerTest() { async function debuggerTest() {
for (var scriptCandidate of TestRunner.debuggerModel.scripts()) { for (var scriptCandidate of TestRunner.debuggerModel.scripts()) {
if (scriptCandidate.sourceURL === resourceURL && scriptCandidate.lineOffset === 4) { if (scriptCandidate.sourceURL === resourceURL && scriptCandidate.lineOffset === 4) {
script = scriptCandidate; script = scriptCandidate;
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
var count1 = liveLocationsCount(); var count1 = liveLocationsCount();
link = linkifier.linkifyScriptLocation( link = linkifier.linkifyScriptLocation(
SDK.targetManager.mainTarget(), null, resourceURL, 8, 0, 'dummy-class'); SDK.targetManager.mainTarget(), null, resourceURL, 8, 0, 'dummy-class');
// The script location in the link is a live location that may be unresolved.
await TestRunner.waitForPendingLiveLocationUpdates();
var count2 = liveLocationsCount(); var count2 = liveLocationsCount();
TestRunner.addResult('listeners added on raw source code: ' + (count2 - count1)); TestRunner.addResult('listeners added on raw source code: ' + (count2 - count1));
...@@ -54,7 +56,8 @@ ...@@ -54,7 +56,8 @@
var formattedContent = (await Formatter.sourceFormatter._formattedSourceCodes.get(uiSourceCode).formatData.formattedSourceCode.requestContent()).content; var formattedContent = (await Formatter.sourceFormatter._formattedSourceCodes.get(uiSourceCode).formatData.formattedSourceCode.requestContent()).content;
TestRunner.addResult('pretty printed content:'); TestRunner.addResult('pretty printed content:');
TestRunner.addResult(formattedContent); TestRunner.addResult(formattedContent);
Formatter.sourceFormatter.discardFormattedUISourceCode(UI.panels.sources.visibleView.uiSourceCode()); await Formatter.sourceFormatter.discardFormattedUISourceCode(UI.panels.sources.visibleView.uiSourceCode());
await TestRunner.waitForPendingLiveLocationUpdates();
TestRunner.addResult('reverted location: ' + link.textContent); TestRunner.addResult('reverted location: ' + link.textContent);
var count1 = liveLocationsCount(); var count1 = liveLocationsCount();
......
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