Commit 8bbdf20f authored by Will Chen's avatar Will Chen Committed by Commit Bot

DevTools: add infrastructure for startup tests and migrate 1 test

This enables the new integration test framework to support startup
tests that need to exercise activities in the inspected page prior to
starting the DevTools session.

This migrates console-format-startup.js as an example test.

Bug: 667560
Change-Id: Ifdd82135494ef7e05879297197e210a9b812d3ea
Reviewed-on: https://chromium-review.googlesource.com/803909
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523549}
parent 8dd06837
......@@ -567,6 +567,8 @@ bool BlinkTestController::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetPopupBlockingEnabled,
OnSetPopupBlockingEnabled)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_TestFinished, OnTestFinished)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_NavigateSecondaryWindow,
OnNavigateSecondaryWindow)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_ShowDevTools, OnShowDevTools)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_EvaluateInDevTools,
OnEvaluateInDevTools)
......@@ -952,6 +954,16 @@ void BlinkTestController::OnSetPopupBlockingEnabled(bool block_popups) {
LayoutTestContentBrowserClient::Get()->SetPopupBlockingEnabled(block_popups);
}
void BlinkTestController::OnNavigateSecondaryWindow(const GURL& url) {
if (secondary_window_)
secondary_window_->LoadURL(url);
}
void BlinkTestController::OnInspectSecondaryWindow() {
if (devtools_bindings_)
devtools_bindings_->Attach();
}
void BlinkTestController::OnShowDevTools(const std::string& settings,
const std::string& frontend_url) {
devtools_window_ = SecondaryWindow();
......
......@@ -137,6 +137,7 @@ class BlinkTestController : public WebContentsObserver,
int sender_process_host_id,
const base::DictionaryValue& changed_layout_test_runtime_flags);
void OnTestFinishedInSecondaryRenderer();
void OnInspectSecondaryWindow();
// Makes sure that the potentially new renderer associated with |frame| is 1)
// initialized for the test, 2) kept up to date wrt test flags and 3)
......@@ -209,7 +210,7 @@ class BlinkTestController : public WebContentsObserver,
void OnOverridePreferences(const WebPreferences& prefs);
void OnSetPopupBlockingEnabled(bool block_popups);
void OnTestFinished();
void OnClearDevToolsLocalStorage();
void OnNavigateSecondaryWindow(const GURL& url);
void OnShowDevTools(const std::string& settings,
const std::string& frontend_url);
void OnEvaluateInDevTools(int call_id, const std::string& script);
......
......@@ -41,9 +41,14 @@ namespace content {
class LayoutTestDevToolsBindings::SecondaryObserver
: public WebContentsObserver {
public:
explicit SecondaryObserver(LayoutTestDevToolsBindings* bindings)
SecondaryObserver(LayoutTestDevToolsBindings* bindings, bool is_startup_test)
: WebContentsObserver(bindings->inspected_contents()),
bindings_(bindings) {}
bindings_(bindings) {
if (is_startup_test) {
bindings_->NavigateDevToolsFrontend();
bindings_ = nullptr;
}
}
// WebContentsObserver implementation.
void DocumentAvailableInMainFrame() override {
......@@ -139,6 +144,12 @@ void LayoutTestDevToolsBindings::EvaluateInFrontend(int call_id,
base::UTF8ToUTF16(source));
}
void LayoutTestDevToolsBindings::Attach() {
DCHECK(is_startup_test_);
ShellDevToolsBindings::Attach();
EvaluateInFrontend(0, "TestRunner._startupTestSetupFinished();");
}
LayoutTestDevToolsBindings::LayoutTestDevToolsBindings(
WebContents* devtools_contents,
WebContents* inspected_contents,
......@@ -148,14 +159,18 @@ LayoutTestDevToolsBindings::LayoutTestDevToolsBindings(
: ShellDevToolsBindings(devtools_contents, inspected_contents, nullptr),
frontend_url_(frontend_url) {
SetPreferences(settings);
if (new_harness) {
secondary_observer_ = std::make_unique<SecondaryObserver>(this);
NavigationController::LoadURLParams params(
GetInspectedPageURL(frontend_url));
params.transition_type = ui::PageTransitionFromInt(
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
inspected_contents->GetController().LoadURLWithParams(params);
is_startup_test_ =
frontend_url.query().find("/startup/") != std::string::npos;
secondary_observer_ =
std::make_unique<SecondaryObserver>(this, is_startup_test_);
if (!is_startup_test_) {
NavigationController::LoadURLParams params(
GetInspectedPageURL(frontend_url));
params.transition_type = ui::PageTransitionFromInt(
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
inspected_contents->GetController().LoadURLWithParams(params);
}
} else {
NavigateDevToolsFrontend();
}
......@@ -190,4 +205,10 @@ void LayoutTestDevToolsBindings::RenderFrameCreated(
BlinkTestController::Get()->HandleNewRenderFrameHost(render_frame_host);
}
void LayoutTestDevToolsBindings::DocumentAvailableInMainFrame() {
if (is_startup_test_)
return;
ShellDevToolsBindings::Attach();
}
} // namespace content
......@@ -27,6 +27,7 @@ class LayoutTestDevToolsBindings : public ShellDevToolsBindings {
bool new_harness);
void EvaluateInFrontend(int call_id, const std::string& expression);
void Attach() override;
~LayoutTestDevToolsBindings() override;
......@@ -39,10 +40,12 @@ class LayoutTestDevToolsBindings : public ShellDevToolsBindings {
// WebContentsObserver implementation.
void RenderProcessGone(base::TerminationStatus status) override;
void RenderFrameCreated(RenderFrameHost* render_frame_host) override;
void DocumentAvailableInMainFrame() override;
void NavigateDevToolsFrontend();
bool ready_for_test_ = false;
bool is_startup_test_ = false;
GURL frontend_url_;
std::vector<std::pair<int, std::string>> pending_evaluations_;
std::unique_ptr<SecondaryObserver> secondary_observer_;
......
......@@ -57,6 +57,7 @@ base::TaskRunner* LayoutTestMessageFilter::OverrideTaskRunnerForMessage(
case LayoutTestHostMsg_ResetPermissions::ID:
case LayoutTestHostMsg_LayoutTestRuntimeFlagsChanged::ID:
case LayoutTestHostMsg_TestFinishedInSecondaryRenderer::ID:
case LayoutTestHostMsg_InspectSecondaryWindow::ID:
return BrowserThread::GetTaskRunnerForThread(BrowserThread::UI).get();
}
return nullptr;
......@@ -84,6 +85,8 @@ bool LayoutTestMessageFilter::OnMessageReceived(const IPC::Message& message) {
OnLayoutTestRuntimeFlagsChanged)
IPC_MESSAGE_HANDLER(LayoutTestHostMsg_TestFinishedInSecondaryRenderer,
OnTestFinishedInSecondaryRenderer)
IPC_MESSAGE_HANDLER(LayoutTestHostMsg_InspectSecondaryWindow,
OnInspectSecondaryWindow)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
......@@ -216,4 +219,9 @@ void LayoutTestMessageFilter::OnTestFinishedInSecondaryRenderer() {
BlinkTestController::Get()->OnTestFinishedInSecondaryRenderer();
}
void LayoutTestMessageFilter::OnInspectSecondaryWindow() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BlinkTestController::Get()->OnInspectSecondaryWindow();
}
} // namespace content
......@@ -77,6 +77,7 @@ class LayoutTestMessageFilter : public BrowserMessageFilter {
void OnLayoutTestRuntimeFlagsChanged(
const base::DictionaryValue& changed_layout_test_runtime_flags);
void OnTestFinishedInSecondaryRenderer();
void OnInspectSecondaryWindow();
int render_process_id_;
......
......@@ -154,7 +154,7 @@ void ShellDevToolsBindings::ReadyToCommitNavigation(
#endif
}
void ShellDevToolsBindings::DocumentAvailableInMainFrame() {
void ShellDevToolsBindings::Attach() {
if (agent_host_)
agent_host_->DetachClient(this);
agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents_);
......@@ -191,8 +191,6 @@ void ShellDevToolsBindings::SetPreferences(const std::string& json) {
void ShellDevToolsBindings::HandleMessageFromDevToolsFrontend(
const std::string& message) {
if (!agent_host_)
return;
std::string method;
base::ListValue* params = nullptr;
base::DictionaryValue* dict = nullptr;
......@@ -207,7 +205,7 @@ void ShellDevToolsBindings::HandleMessageFromDevToolsFrontend(
if (method == "dispatchProtocolMessage" && params && params->GetSize() == 1) {
std::string protocol_message;
if (!params->GetString(0, &protocol_message))
if (!agent_host_ || !params->GetString(0, &protocol_message))
return;
agent_host_->DispatchProtocolMessage(this, protocol_message);
} else if (method == "loadCompleted") {
......@@ -289,6 +287,8 @@ void ShellDevToolsBindings::HandleMessageFromDevToolsFrontend(
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([]);"));
} else if (method == "reattach") {
if (!agent_host_)
return;
agent_host_->DetachClient(this);
agent_host_->AttachClient(this);
} else if (method == "registerExtensionsAPI") {
......
......@@ -46,6 +46,7 @@ class ShellDevToolsBindings : public WebContentsObserver,
ShellDevToolsDelegate* delegate);
void InspectElementAt(int x, int y);
virtual void Attach();
void CallClientFunction(const std::string& function_name,
const base::Value* arg1,
......@@ -67,7 +68,6 @@ class ShellDevToolsBindings : public WebContentsObserver,
private:
// WebContentsObserver overrides
void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
void DocumentAvailableInMainFrame() override;
void WebContentsDestroyed() override;
// net::URLFetcherDelegate overrides.
......
......@@ -51,6 +51,10 @@ void ShellDevToolsFrontend::Close() {
frontend_shell_->Close();
}
void ShellDevToolsFrontend::DocumentAvailableInMainFrame() {
devtools_bindings_->Attach();
}
void ShellDevToolsFrontend::WebContentsDestroyed() {
delete this;
}
......
......@@ -31,6 +31,7 @@ class ShellDevToolsFrontend : public ShellDevToolsDelegate,
private:
// WebContentsObserver overrides
void DocumentAvailableInMainFrame() override;
void WebContentsDestroyed() override;
ShellDevToolsFrontend(Shell* frontend_shell, WebContents* inspected_contents);
......
......@@ -42,6 +42,7 @@ IPC_MESSAGE_ROUTED4(LayoutTestHostMsg_SetPermission,
GURL /* origin */,
GURL /* embedding_origin */)
IPC_MESSAGE_ROUTED0(LayoutTestHostMsg_ResetPermissions)
IPC_MESSAGE_ROUTED0(LayoutTestHostMsg_InspectSecondaryWindow)
// Notifies the browser that one of renderers has changed layout test runtime
// flags (i.e. has set dump_as_text).
......
......@@ -67,6 +67,7 @@ IPC_MESSAGE_ROUTED1(ShellViewHostMsg_PrintMessage,
std::string /* message */)
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_PrintMessageToStderr,
std::string /* message */)
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_NavigateSecondaryWindow, GURL /* url */)
IPC_MESSAGE_ROUTED2(ShellViewHostMsg_ShowDevTools,
std::string /* settings */,
std::string /* frontend_url */)
......
......@@ -407,6 +407,14 @@ void BlinkTestRunner::DisableAutoResizeMode(const WebSize& new_size) {
ForceResizeRenderView(render_view(), new_size);
}
void BlinkTestRunner::NavigateSecondaryWindow(const GURL& url) {
Send(new ShellViewHostMsg_NavigateSecondaryWindow(routing_id(), url));
}
void BlinkTestRunner::InspectSecondaryWindow() {
Send(new LayoutTestHostMsg_InspectSecondaryWindow(routing_id()));
}
void BlinkTestRunner::ShowDevTools(const std::string& settings,
const std::string& frontend_url) {
Send(new ShellViewHostMsg_ShowDevTools(
......
......@@ -90,6 +90,8 @@ class BlinkTestRunner : public RenderViewObserver,
void EnableAutoResizeMode(const blink::WebSize& min_size,
const blink::WebSize& max_size) override;
void DisableAutoResizeMode(const blink::WebSize& new_size) override;
void NavigateSecondaryWindow(const GURL& url) override;
void InspectSecondaryWindow() override;
void ShowDevTools(const std::string& settings,
const std::string& frontend_url) override;
void CloseDevTools() override;
......
......@@ -252,6 +252,8 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
void SetWindowIsKey(bool value);
void SetXSSAuditorEnabled(bool enabled);
void ShowWebInspector(gin::Arguments* args);
void NavigateSecondaryWindow(const std::string& url);
void InspectSecondaryWindow();
void SimulateWebNotificationClick(gin::Arguments* args);
void SimulateWebNotificationClose(const std::string& title, bool by_user);
void UseUnfortunateSynchronousResizeMode();
......@@ -599,6 +601,10 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
.SetMethod("setXSSAuditorEnabled",
&TestRunnerBindings::SetXSSAuditorEnabled)
.SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
.SetMethod("navigateSecondaryWindow",
&TestRunnerBindings::NavigateSecondaryWindow)
.SetMethod("inspectSecondaryWindow",
&TestRunnerBindings::InspectSecondaryWindow)
.SetMethod("simulateWebNotificationClick",
&TestRunnerBindings::SimulateWebNotificationClick)
.SetMethod("simulateWebNotificationClose",
......@@ -1260,6 +1266,16 @@ void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
}
}
void TestRunnerBindings::NavigateSecondaryWindow(const std::string& url) {
if (runner_)
runner_->NavigateSecondaryWindow(GURL(url));
}
void TestRunnerBindings::InspectSecondaryWindow() {
if (runner_)
runner_->InspectSecondaryWindow();
}
void TestRunnerBindings::CloseWebInspector() {
if (runner_)
runner_->CloseWebInspector();
......@@ -2007,6 +2023,14 @@ void TestRunner::ShowDevTools(const std::string& settings,
delegate_->ShowDevTools(settings, frontend_url);
}
void TestRunner::NavigateSecondaryWindow(const GURL& url) {
delegate_->NavigateSecondaryWindow(url);
}
void TestRunner::InspectSecondaryWindow() {
delegate_->InspectSecondaryWindow();
}
class WorkItemBackForward : public TestRunner::WorkItem {
public:
explicit WorkItemBackForward(int distance) : distance_(distance) {}
......
......@@ -484,6 +484,9 @@ class TestRunner : public WebTestRunner {
const std::string& frontend_url);
void CloseWebInspector();
void NavigateSecondaryWindow(const GURL& url);
void InspectSecondaryWindow();
// Inspect chooser state
bool IsChooserShown();
......
......@@ -136,6 +136,9 @@ class WebTestDelegate {
const std::string& frontend_url) = 0;
virtual void CloseDevTools() = 0;
virtual void NavigateSecondaryWindow(const GURL& url) = 0;
virtual void InspectSecondaryWindow() = 0;
// Evaluate the given script in the DevTools agent.
virtual void EvaluateInWebInspector(int call_id,
const std::string& script) = 0;
......
......@@ -7567,7 +7567,7 @@ crbug.com/591099 http/tests/devtools/sources/debugger-pause/debugger-pause-on-pr
crbug.com/591099 http/tests/devtools/sources/debugger-ui/function-generator-details.js [ Failure ]
crbug.com/591099 http/tests/devtools/sources/debugger/live-edit-no-reveal.js [ Failure Pass ]
crbug.com/591099 http/tests/devtools/sources/debugger/properties-special.js [ Failure ]
crbug.com/591099 http/tests/devtools/startup/console/console-format-startup.html [ Failure ]
crbug.com/591099 http/tests/devtools/startup/console/console-format-startup.js [ Failure ]
crbug.com/591099 http/tests/devtools/startup/reattach-after-editing-styles.html [ Crash Pass Timeout ]
crbug.com/591099 http/tests/devtools/text-autosizing-override.js [ Failure ]
crbug.com/714962 http/tests/devtools/tracing/scroll-invalidations.js [ Failure ]
......
......@@ -38,7 +38,7 @@ crbug.com/462190 [ Linux ] inspector-protocol/heap-profiler/heap-snapshot-with-a
crbug.com/462190 [ Linux ] inspector-protocol/heap-profiler/heap-snapshot-with-detached-dom-tree.js [ Timeout ]
crbug.com/462190 [ Linux ] inspector-protocol/heap-profiler/heap-snapshot-with-event-listener.js [ Timeout ]
crbug.com/667560 [ Linux ] http/tests/devtools/startup/console/console-format-startup.html [ Timeout Pass ]
crbug.com/667560 [ Linux ] http/tests/devtools/startup/console/console-format-startup.js [ Timeout Pass ]
crbug.com/751906 [ Linux ] http/tests/devtools/console/console-correct-suggestions.js [ Timeout Pass ]
crbug.com/736370 [ Linux ] external/wpt/editing/run/removeformat.html [ Timeout ]
......
......@@ -105,7 +105,7 @@ crbug.com/420008 virtual/threaded/http/tests/devtools/tracing/ [ Slow ]
crbug.com/246190 [ Release ] http/tests/devtools/indexeddb/ [ Slow ]
crbug.com/451577 [ Mac ] http/tests/devtools/extensions/extensions-sidebar.js [ Slow ]
crbug.com/451577 [ Mac ] http/tests/devtools/extensions/extensions-events.js [ Slow ]
crbug.com/667560 http/tests/devtools/startup/console/console-format-startup.html [ Slow ]
crbug.com/667560 http/tests/devtools/startup/console/console-format-startup.js [ Slow ]
crbug.com/679833 http/tests/devtools/network/network-datareceived.js [ Slow ]
webkit.org/b/90488 [ Release ] http/tests/devtools/compiler-source-mapping-debug.js [ Slow ]
crbug.com/243492 http/tests/devtools/startup/injected-script-discard.html [ Slow ]
......
CONSOLE WARNING: line 8028: The JavaScript context bogus was not found in the frame http://127.0.0.1:8000/devtools/resources/extensions-frame-eval.html
Tests WebInspector extension API
Started extension.
......
// Copyright 2017 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() {
await TestRunner.setupStartupTest('resources/console-format-startup.html');
TestRunner.addResult('Tests console logging for messages that happen before DevTools is open.\n');
await TestRunner.loadModule('console_test_runner');
await TestRunner.showPanel('console');
TestRunner.hideInspectorView();
var total = await TestRunner.evaluateInPageRemoteObject('globals.length');
loopOverGlobals(0, total);
function loopOverGlobals(current, total) {
function advance() {
var next = current + 1;
if (next == total.description)
ConsoleTestRunner.waitForRemoteObjectsConsoleMessages(onRemoteObjectsLoaded);
else
loopOverGlobals(next, total);
}
function onRemoteObjectsLoaded() {
ConsoleTestRunner.dumpConsoleMessagesIgnoreErrorStackFrames();
TestRunner.addResult('Expanded all messages');
ConsoleTestRunner.expandConsoleMessages(
ConsoleTestRunner.expandConsoleMessagesErrorParameters.bind(this, finish), undefined, function(section) {
return section.element.firstChild.textContent !== '#text';
});
}
function finish() {
ConsoleTestRunner.dumpConsoleMessagesIgnoreErrorStackFrames();
TestRunner.completeTest();
}
TestRunner.evaluateInPage('log(' + current + ')');
TestRunner.deprecatedRunAfterPendingDispatches(evalInConsole);
function evalInConsole() {
ConsoleTestRunner.evaluateInConsole('globals[' + current + ']');
TestRunner.deprecatedRunAfterPendingDispatches(advance);
}
}
})();
\ No newline at end of file
<html>
<head>
<script src="../../../inspector/inspector-test.js"></script>
<script src="../../../inspector/console-test.js"></script>
<script type="text/javascript">
// Global Values
var globals = [];
......@@ -148,7 +144,7 @@ function onload()
];
logTable();
logCollections();
runTest();
testRunner.inspectSecondaryWindow();
}
function logTable()
......@@ -291,54 +287,8 @@ function domException()
}
return result;
}
function showInspectorAndRunTest()
{
if (window.testRunner)
testRunner.showWebInspector();
runTest();
}
</script>
<script>
async function test() {
TestRunner.hideInspectorView();
var total = await TestRunner.evaluateInPageRemoteObject('globals.length');
loopOverGlobals(0, total);
function loopOverGlobals(current, total) {
function advance() {
var next = current + 1;
if (next == total.description)
ConsoleTestRunner.waitForRemoteObjectsConsoleMessages(onRemoteObjectsLoaded);
else
loopOverGlobals(next, total);
}
function onRemoteObjectsLoaded() {
ConsoleTestRunner.dumpConsoleMessagesIgnoreErrorStackFrames();
TestRunner.addResult('Expanded all messages');
ConsoleTestRunner.expandConsoleMessages(
ConsoleTestRunner.expandConsoleMessagesErrorParameters.bind(this, finish), undefined, function(section) {
return section.element.firstChild.textContent !== '#text';
});
}
function finish() {
ConsoleTestRunner.dumpConsoleMessagesIgnoreErrorStackFrames();
TestRunner.completeTest();
}
TestRunner.evaluateInPage('log(' + current + ')');
TestRunner.deprecatedRunAfterPendingDispatches(evalInConsole);
function evalInConsole() {
ConsoleTestRunner.evaluateInConsole('globals[' + current + ']');
TestRunner.deprecatedRunAfterPendingDispatches(advance);
}
}
}
</script>
</head>
<body onload="onload()">
<p>Tests console logging for messages that happen before DevTools is open.</p>
<div id="x"></div>
<p id="p"></p>
</body>
......@@ -353,5 +303,4 @@ async function test() {
<input type="radio" name="x" value="x2" /> x2
</form>
</div>
</body>
</html>
\ No newline at end of file
</body>
\ No newline at end of file
......@@ -62,3 +62,8 @@ ExtensionsTestRunner.runExtensionTests = async function(tests) {
Extensions.extensionServer.initializeExtensions();
};
(function disableLogging() {
// Suppress console warnings from ExtensionServer.js
console.warn = () => undefined;
})();
......@@ -561,3 +561,11 @@ Host.isUnderTest = function(prefs) {
return prefs['isUnderTest'] === 'true';
return Common.settings.createSetting('isUnderTest', false).get();
};
/**
* @return {boolean}
*/
Host.isStartupTest = function() {
var test = Runtime.queryParam('test');
return !!(test && test.includes('/startup/'));
};
......@@ -280,8 +280,12 @@ Main.Main = class {
handler.handleQueryParam(value);
}
// Allow UI cycles to repaint prior to creating connection.
setTimeout(this._initializeTarget.bind(this), 0);
if (Host.isStartupTest()) {
setTimeout(() => InspectorFrontendHost.readyForTest(), 0);
} else {
// Allow UI cycles to repaint prior to creating connection.
setTimeout(this._initializeTarget.bind(this), 0);
}
Main.Main.timeEnd('Main._showAppUI');
}
......@@ -289,7 +293,8 @@ Main.Main = class {
Main.Main.time('Main._initializeTarget');
SDK.targetManager.connectToMainTarget(webSocketConnectionLost);
InspectorFrontendHost.readyForTest();
if (!Host.isStartupTest())
InspectorFrontendHost.readyForTest();
// Asynchronously run the extensions.
setTimeout(this._lateInitialization.bind(this), 100);
Main.Main.timeEnd('Main._initializeTarget');
......
......@@ -18,8 +18,6 @@ SDK.MainConnection = class {
InspectorFrontendHostAPI.Events.DispatchMessage, this._dispatchMessage, this),
InspectorFrontendHost.events.addEventListener(
InspectorFrontendHostAPI.Events.DispatchMessageChunk, this._dispatchMessageChunk, this),
InspectorFrontendHost.events.addEventListener(
InspectorFrontendHostAPI.Events.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this),
];
}
......@@ -57,31 +55,6 @@ SDK.MainConnection = class {
}
}
/**
* @param {!Common.Event} event
*/
_evaluateForTestInFrontend(event) {
if (!Host.isUnderTest())
return;
var callId = /** @type {number} */ (event.data['callId']);
var script = /** @type {number} */ (event.data['script']);
/**
* @suppressGlobalPropertiesCheck
*/
function invokeMethod() {
try {
script = script + '//# sourceURL=evaluateInWebInspector' + callId + '.js';
window.eval(script);
} catch (e) {
console.error(e.stack);
}
}
Protocol.InspectorBackend.deprecatedRunAfterPendingDispatches(invokeMethod);
}
/**
* @override
* @return {!Promise}
......
......@@ -9,9 +9,50 @@
/* eslint-disable no-console */
/** @type {!{logToStderr: function(), notifyDone: function()}|undefined} */
/** @type {!{logToStderr: function(), navigateSecondaryWindow: function(string), notifyDone: function()}|undefined} */
self.testRunner;
/**
* Only tests in /LayoutTests/http/tests/devtools/startup/ need to call
* this method because these tests need certain activities to be exercised
* in the inspected page prior to the DevTools session.
* @param {string} path
* @return {!Promise<undefined>}
*/
TestRunner.setupStartupTest = function(path) {
var absoluteURL = TestRunner.url(path);
self.testRunner.navigateSecondaryWindow(absoluteURL);
return new Promise(f => TestRunner._startupTestSetupFinished = () => {
Main.Main._instanceForTest._initializeTarget();
delete TestRunner._startupTestSetupFinished;
f();
});
};
/**
* @param {!Common.Event} event
*/
TestRunner._evaluateForTestInFrontend = function(event) {
var callId = /** @type {number} */ (event.data['callId']);
var script = /** @type {number} */ (event.data['script']);
function invokeMethod() {
try {
script = script + '//# sourceURL=TestRunner' + callId + '.js';
self.eval(script);
} catch (e) {
console.error(e.stack);
}
}
// For startup tests, the first evaluateForTestInFrontend is called
// before target has been initialized.
if (Protocol.InspectorBackend.deprecatedRunAfterPendingDispatches)
Protocol.InspectorBackend.deprecatedRunAfterPendingDispatches(invokeMethod);
else
invokeMethod();
};
TestRunner._executeTestScript = function() {
var testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
fetch(testScriptURL)
......@@ -1359,9 +1400,17 @@ TestRunner._TestObserver = class {
if (TestRunner._startedTest)
return;
TestRunner._startedTest = true;
TestRunner._printDevToolsConsole();
TestRunner._setupTestHelpers(target);
TestRunner._runTest();
if (Host.isStartupTest())
return;
TestRunner
.loadHTML(`
<head>
<base href="${TestRunner.url()}">
</head>
<body>
</body>
`).then(() => TestRunner._executeTestScript());
}
/**
......@@ -1372,18 +1421,6 @@ TestRunner._TestObserver = class {
}
};
TestRunner._runTest = async function() {
var testPath = TestRunner.url();
await TestRunner.loadHTML(`
<head>
<base href="${testPath}">
</head>
<body>
</body>
`);
TestRunner._executeTestScript();
};
/**
* @return {boolean}
*/
......@@ -1409,4 +1446,12 @@ function completeTestOnError(message, source, lineno, colno, error) {
}
self['onerror'] = completeTestOnError;
InspectorFrontendHost.events.addEventListener(
InspectorFrontendHostAPI.Events.EvaluateForTestInFrontend, TestRunner._evaluateForTestInFrontend, TestRunner);
// TODO(chenwilliam): remove check for legacy test when test migration is done.
if (!Runtime.queryParam('test'))
return;
TestRunner._printDevToolsConsole();
if (Host.isStartupTest())
TestRunner._executeTestScript();
})();
......@@ -2,7 +2,9 @@
"dependencies": [
"sdk",
"workspace",
"ui"
"ui",
"host",
"main"
],
"scripts": [
"TestRunner.js"
......
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