From 6cb102aab2070730da90a0f2baee202e36f146b2 Mon Sep 17 00:00:00 2001 From: Tatiana Buldina Date: Thu, 14 Mar 2019 21:48:25 +0000 Subject: [PATCH] [ChromeDriver] Allow null value for script timeout Bug: chromedriver:2796 Change-Id: If8ea3747baac59a7deb6a63c5abb15ca9695abda Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1521768 Reviewed-by: John Chen Commit-Queue: Tatiana Buldina Cr-Commit-Position: refs/heads/master@{#640940} --- chrome/test/chromedriver/capabilities.cc | 18 ++++++++--- chrome/test/chromedriver/session_commands.cc | 32 +++++++++++++++----- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/chrome/test/chromedriver/capabilities.cc b/chrome/test/chromedriver/capabilities.cc index 1d43bf2df3db45..a2b42ba45ac436 100644 --- a/chrome/test/chromedriver/capabilities.cc +++ b/chrome/test/chromedriver/capabilities.cc @@ -225,12 +225,20 @@ Status ParseTimeouts(const base::Value& option, Capabilities* capabilities) { return Status(kInvalidArgument, "'timeouts' must be a JSON object"); for (const auto& it : timeouts->DictItems()) { int64_t timeout_ms_int64 = -1; - if (!GetOptionalSafeInt(timeouts, it.first, &timeout_ms_int64) - || timeout_ms_int64 < 0) - return Status(kInvalidArgument, "value must be a non-negative integer"); - base::TimeDelta timeout = - base::TimeDelta::FromMilliseconds(timeout_ms_int64); + base::TimeDelta timeout; const std::string& type = it.first; + if (it.second.is_none()) { + if (type == "script") + timeout = base::TimeDelta::Max(); + else + return Status(kInvalidArgument, "timeout can not be null"); + } else { + if (!GetOptionalSafeInt(timeouts, it.first, &timeout_ms_int64) || + timeout_ms_int64 < 0) + return Status(kInvalidArgument, "value must be a non-negative integer"); + else + timeout = base::TimeDelta::FromMilliseconds(timeout_ms_int64); + } if (type == "script") { capabilities->script_timeout = timeout; } else if (type == "pageLoad") { diff --git a/chrome/test/chromedriver/session_commands.cc b/chrome/test/chromedriver/session_commands.cc index abe005318fa5a8..055ad1a9586ea5 100644 --- a/chrome/test/chromedriver/session_commands.cc +++ b/chrome/test/chromedriver/session_commands.cc @@ -133,8 +133,11 @@ std::unique_ptr CreateCapabilities( } else { caps->SetBoolean("setWindowRect", true); } - SetSafeInt(caps.get(), "timeouts.script", - session->script_timeout.InMilliseconds()); + if (session->script_timeout == base::TimeDelta::Max()) + caps->SetPath({"timeouts", "script"}, base::Value()); + else + SetSafeInt(caps.get(), "timeouts.script", + session->script_timeout.InMilliseconds()); SetSafeInt(caps.get(), "timeouts.pageLoad", session->page_load_timeout.InMilliseconds()); SetSafeInt(caps.get(), "timeouts.implicit", @@ -755,12 +758,21 @@ Status ExecuteSetTimeoutsW3C(Session* session, std::unique_ptr* value) { for (const auto& setting : params.DictItems()) { int64_t timeout_ms_int64 = -1; - if (!GetOptionalSafeInt(¶ms, setting.first, &timeout_ms_int64) || - timeout_ms_int64 < 0) - return Status(kInvalidArgument, "value must be a non-negative integer"); - base::TimeDelta timeout = - base::TimeDelta::FromMilliseconds(timeout_ms_int64); + base::TimeDelta timeout; const std::string& type = setting.first; + if (setting.second.is_none()) { + if (type == "script") + timeout = base::TimeDelta::Max(); + else + return Status(kInvalidArgument, "timeout can not be null"); + } else { + if (!GetOptionalSafeInt(¶ms, setting.first, &timeout_ms_int64) + || timeout_ms_int64 < 0) + return Status(kInvalidArgument, + "value must be a non-negative integer"); + else + timeout = base::TimeDelta::FromMilliseconds(timeout_ms_int64); + } if (type == "script") { session->script_timeout = timeout; } else if (type == "pageLoad") { @@ -791,7 +803,11 @@ Status ExecuteGetTimeouts(Session* session, const base::DictionaryValue& params, std::unique_ptr* value) { base::DictionaryValue timeouts; - SetSafeInt(&timeouts, "script", session->script_timeout.InMilliseconds()); + if (session->script_timeout == base::TimeDelta::Max()) + timeouts.SetKey("script", base::Value()); + else + SetSafeInt(&timeouts, "script", session->script_timeout.InMilliseconds()); + SetSafeInt(&timeouts, "pageLoad", session->page_load_timeout.InMilliseconds()); SetSafeInt(&timeouts, "implicit", session->implicit_wait.InMilliseconds());