Commit d593f348 authored by Tricia Crichton's avatar Tricia Crichton Committed by Commit Bot

[ChromeDriver] No wait for response during connect

During ConnectIfNecessary, ChromeDriver will not wait for response to
commands issued to DevTools. The first command can take very long to
return when running in a debug build. This cl mimics the ways that other
initialization commands are sent.

Bug: 1040589
Change-Id: I4ca2fc090700f346a29d7b4a2708f486c8cbe847
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015359Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Tricia Crichton <triciac@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734604}
parent 7de5da8f
......@@ -183,51 +183,34 @@ Status DevToolsClientImpl::ConnectIfNecessary() {
if (!socket_->Connect(url_))
return Status(kDisconnected, "unable to connect to renderer");
}
if (id_ != kBrowserwideDevToolsClientId) {
base::DictionaryValue params;
std::string script =
"(function () {"
"window.cdc_adoQpoasnfa76pfcZLmcfl_Array = window.Array;"
"window.cdc_adoQpoasnfa76pfcZLmcfl_Promise = window.Promise;"
"window.cdc_adoQpoasnfa76pfcZLmcfl_Symbol = window.Symbol;"
"}) ();";
params.SetString("source", script);
Status status(kOk);
for (int attempt = 0; attempt < 3; attempt++) {
Timeout small = Timeout(base::TimeDelta::FromSeconds(1));
status = SendCommandWithTimeout("Page.addScriptToEvaluateOnNewDocument",
params, &small);
if (status.IsOk())
break;
else if (status.code() == kTimeout)
continue;
else
return status;
}
if (status.IsError())
return status;
params.Clear();
params.SetString("expression", script);
for (int attempt = 0; attempt < 3; attempt++) {
Timeout small = Timeout(base::TimeDelta::FromSeconds(1));
status = SendCommandWithTimeout("Runtime.evaluate", params, &small);
if (status.IsOk())
break;
else if (status.code() == kTimeout)
continue;
else
return status;
}
if (status.IsError())
return status;
}
}
// These lines must be before the following SendCommandXxx calls
unnotified_connect_listeners_ = listeners_;
unnotified_event_listeners_.clear();
response_info_map_.clear();
if (id_ != kBrowserwideDevToolsClientId) {
base::DictionaryValue params;
std::string script =
"(function () {"
"window.cdc_adoQpoasnfa76pfcZLmcfl_Array = window.Array;"
"window.cdc_adoQpoasnfa76pfcZLmcfl_Promise = window.Promise;"
"window.cdc_adoQpoasnfa76pfcZLmcfl_Symbol = window.Symbol;"
"}) ();";
params.SetString("source", script);
Status status = SendCommandAndIgnoreResponse(
"Page.addScriptToEvaluateOnNewDocument", params);
if (status.IsError())
return status;
params.Clear();
params.SetString("expression", script);
status = SendCommandAndIgnoreResponse("Runtime.evaluate", params);
if (status.IsError())
return status;
}
// Notify all listeners of the new connection. Do this now so that any errors
// that occur are reported now instead of later during some unrelated call.
// Also gives listeners a chance to send commands before other clients.
......
......@@ -79,6 +79,10 @@ class MockSyncWebSocket : public SyncWebSocket {
return false;
EXPECT_TRUE((*dict)->GetInteger("id", &id_));
EXPECT_TRUE((*dict)->GetString("method", method));
// Because ConnectIfNecessary is not waiting for the response, Send can
// set connect_complete to true
if (add_script_received_ && runtime_eval_received_)
connect_complete_ = true;
if (connect_complete_)
return true;
else if (*method == "Page.addScriptToEvaluateOnNewDocument")
......
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