Commit e1d57afb authored by Will Chen's avatar Will Chen Committed by Commit Bot

DevTools: fix TestRunner.navigate(...) & migrate a test as example

This fixes TestRunner.navigate(...) which is used by a handful of tests
currently and will be needed by more because of the new test structure.

This migrates debug-inlined-scripts-fragment-id.js to verify that this
method works.

Bug: 667560
Change-Id: I658736139aed90e20836cebea016f20ddfa8d9fb
Reviewed-on: https://chromium-review.googlesource.com/727471Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510127}
parent c6c4cb32
...@@ -4,8 +4,8 @@ window.location: #hash ...@@ -4,8 +4,8 @@ window.location: #hash
Script source was shown. Script source was shown.
Script execution paused. Script execution paused.
Call stack: Call stack:
0) f4 (debug-inlined-scripts-fragment-id.html:6) 0) f4 (inline-scripts.html:6)
1) (debug-inlined-scripts-fragment-id.html:8) 1) (inline-scripts.html:8)
==Source frame contents start== ==Source frame contents start==
<html> <html>
<head> <head>
...@@ -16,73 +16,7 @@ function f4() ...@@ -16,73 +16,7 @@ function f4()
} }
f4(); f4();
</script> </script>
<script src="../../../inspector/inspector-test.js"></script>
<script src="../../../inspector/debugger-test.js"></script>
<script>
var test = function() {
SourcesTestRunner.startDebuggerTest(step0, true);
function step0() {
TestRunner.evaluateInPage('window.location="#hash"', step1);
}
function step1(loc) {
TestRunner.addResult('window.location: ' + loc.description);
SourcesTestRunner.showScriptSource('debug-inlined-scripts-fragment-id.html', step2);
}
function step2(sourceFrame) {
TestRunner.addResult('Script source was shown.');
SourcesTestRunner.setBreakpoint(sourceFrame, 5, '', true);
SourcesTestRunner.waitUntilPaused(step3);
TestRunner.reloadPage(SourcesTestRunner.completeDebuggerTest.bind(InspectorTest));
}
function step3(callFrames) {
TestRunner.addResult('Script execution paused.');
SourcesTestRunner.captureStackTrace(callFrames);
SourcesTestRunner.showScriptSource('debug-inlined-scripts-fragment-id.html', step4);
}
function step4(sourceFrame) {
SourcesTestRunner.dumpSourceFrameContents(sourceFrame);
SourcesTestRunner.resumeExecution(SourcesTestRunner.waitUntilPaused.bind(null, step5));
}
function step5(callFrames) {
if (callFrames[0].location.lineNumber !== 9) {
SourcesTestRunner.resumeExecution(SourcesTestRunner.waitUntilPaused.bind(null, step5));
return;
}
TestRunner.addResult('Script execution paused.');
SourcesTestRunner.captureStackTrace(callFrames);
SourcesTestRunner.showScriptSource('debug-inlined-scripts-fragment-id.html', step6);
}
function step6(sourceFrame) {
SourcesTestRunner.dumpSourceFrameContents(sourceFrame);
SourcesTestRunner.resumeExecution(SourcesTestRunner.waitUntilPaused.bind(null, step7));
}
function step7() {
SourcesTestRunner.resumeExecution(SourcesTestRunner.waitUntilPaused.bind(null, step5));
}
};
</script>
</head> </head>
<body onload="runTest()">
<p>
Tests that all inlined scripts from the same document are shown in the same source frame with html script tags.
<a id="hash" href="https://bugs.webkit.org/show_bug.cgi?id=54544">Bug 54544.</a>
</p>
</body>
</html> </html>
==Source frame contents end== ==Source frame contents end==
......
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script> // found in the LICENSE file.
function f4()
{
return 0;
}
f4();
</script>
<script src="../../../inspector/inspector-test.js"></script> (async function() {
<script src="../../../inspector/debugger-test.js"></script> TestRunner.addResult(
`Tests that all inlined scripts from the same document are shown in the same source frame with html script tags. Bug 54544.\n`);
await TestRunner.loadModule('sources_test_runner');
await TestRunner.showPanel('sources');
<script> await TestRunner.navigatePromise('resources/inline-scripts.html');
var test = function() {
SourcesTestRunner.startDebuggerTest(step0, true); SourcesTestRunner.startDebuggerTest(step0, true);
function step0() { function step0() {
...@@ -22,20 +18,20 @@ var test = function() { ...@@ -22,20 +18,20 @@ var test = function() {
function step1(loc) { function step1(loc) {
TestRunner.addResult('window.location: ' + loc.description); TestRunner.addResult('window.location: ' + loc.description);
SourcesTestRunner.showScriptSource('debug-inlined-scripts-fragment-id.html', step2); SourcesTestRunner.showScriptSource('inline-scripts.html', step2);
} }
function step2(sourceFrame) { function step2(sourceFrame) {
TestRunner.addResult('Script source was shown.'); TestRunner.addResult('Script source was shown.');
SourcesTestRunner.setBreakpoint(sourceFrame, 5, '', true); SourcesTestRunner.setBreakpoint(sourceFrame, 5, '', true);
SourcesTestRunner.waitUntilPaused(step3); SourcesTestRunner.waitUntilPaused(step3);
TestRunner.reloadPage(SourcesTestRunner.completeDebuggerTest.bind(InspectorTest)); TestRunner.reloadPage(SourcesTestRunner.completeDebuggerTest.bind(SourcesTestRunner));
} }
function step3(callFrames) { function step3(callFrames) {
TestRunner.addResult('Script execution paused.'); TestRunner.addResult('Script execution paused.');
SourcesTestRunner.captureStackTrace(callFrames); SourcesTestRunner.captureStackTrace(callFrames);
SourcesTestRunner.showScriptSource('debug-inlined-scripts-fragment-id.html', step4); SourcesTestRunner.showScriptSource('inline-scripts.html', step4);
} }
function step4(sourceFrame) { function step4(sourceFrame) {
...@@ -50,7 +46,7 @@ var test = function() { ...@@ -50,7 +46,7 @@ var test = function() {
} }
TestRunner.addResult('Script execution paused.'); TestRunner.addResult('Script execution paused.');
SourcesTestRunner.captureStackTrace(callFrames); SourcesTestRunner.captureStackTrace(callFrames);
SourcesTestRunner.showScriptSource('debug-inlined-scripts-fragment-id.html', step6); SourcesTestRunner.showScriptSource('inline-scripts.html', step6);
} }
function step6(sourceFrame) { function step6(sourceFrame) {
...@@ -61,17 +57,4 @@ var test = function() { ...@@ -61,17 +57,4 @@ var test = function() {
function step7() { function step7() {
SourcesTestRunner.resumeExecution(SourcesTestRunner.waitUntilPaused.bind(null, step5)); SourcesTestRunner.resumeExecution(SourcesTestRunner.waitUntilPaused.bind(null, step5));
} }
}; })();
</script>
</head>
<body onload="runTest()">
<p>
Tests that all inlined scripts from the same document are shown in the same source frame with html script tags.
<a id="hash" href="https://bugs.webkit.org/show_bug.cgi?id=54544">Bug 54544.</a>
</p>
</body>
</html>
<html>
<head>
<script>
function f4()
{
return 0;
}
f4();
</script>
</head>
</html>
...@@ -842,6 +842,9 @@ TestRunner.assertGreaterOrEqual = function(a, b, message) { ...@@ -842,6 +842,9 @@ TestRunner.assertGreaterOrEqual = function(a, b, message) {
*/ */
TestRunner.navigate = function(url, callback) { TestRunner.navigate = function(url, callback) {
TestRunner._pageLoadedCallback = TestRunner.safeWrap(callback); TestRunner._pageLoadedCallback = TestRunner.safeWrap(callback);
TestRunner.resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, TestRunner._pageNavigated);
// Note: injected <base> means that url is relative to test
// and not the inspected page
TestRunner.evaluateInPageAnonymously('window.location.replace(\'' + url + '\')'); TestRunner.evaluateInPageAnonymously('window.location.replace(\'' + url + '\')');
}; };
...@@ -852,6 +855,11 @@ TestRunner.navigatePromise = function(url) { ...@@ -852,6 +855,11 @@ TestRunner.navigatePromise = function(url) {
return new Promise(fulfill => TestRunner.navigate(url, fulfill)); return new Promise(fulfill => TestRunner.navigate(url, fulfill));
}; };
TestRunner._pageNavigated = function() {
TestRunner.resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, TestRunner._pageNavigated);
TestRunner._handlePageLoaded();
};
/** /**
* @param {function():void} callback * @param {function():void} callback
*/ */
...@@ -886,6 +894,10 @@ TestRunner._innerReloadPage = function(hardReload, callback) { ...@@ -886,6 +894,10 @@ TestRunner._innerReloadPage = function(hardReload, callback) {
TestRunner.pageLoaded = function() { TestRunner.pageLoaded = function() {
TestRunner.resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, TestRunner.pageLoaded); TestRunner.resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, TestRunner.pageLoaded);
TestRunner.addResult('Page reloaded.'); TestRunner.addResult('Page reloaded.');
TestRunner._handlePageLoaded();
};
TestRunner._handlePageLoaded = function() {
if (TestRunner._pageLoadedCallback) { if (TestRunner._pageLoadedCallback) {
var callback = TestRunner._pageLoadedCallback; var callback = TestRunner._pageLoadedCallback;
delete TestRunner._pageLoadedCallback; delete TestRunner._pageLoadedCallback;
......
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