| Index: chrome/test/webdriver/commands/implicit_wait_command.cc
|
| ===================================================================
|
| --- chrome/test/webdriver/commands/implicit_wait_command.cc (revision 75464)
|
| +++ chrome/test/webdriver/commands/implicit_wait_command.cc (working copy)
|
| @@ -4,6 +4,7 @@
|
|
|
| #include <string>
|
|
|
| +#include "base/stringprintf.h"
|
| #include "base/utf_string_conversions.h"
|
| #include "chrome/test/webdriver/commands/implicit_wait_command.h"
|
|
|
| @@ -12,42 +13,45 @@
|
| ImplicitWaitCommand::ImplicitWaitCommand(
|
| const std::vector<std::string>& path_segments,
|
| const DictionaryValue* const parameters)
|
| - : WebDriverCommand(path_segments, parameters),
|
| - ms_to_wait_(0) {}
|
| + : WebDriverCommand(path_segments, parameters) {}
|
|
|
| ImplicitWaitCommand::~ImplicitWaitCommand() {}
|
|
|
| -bool ImplicitWaitCommand::Init(Response* const response) {
|
| - if (!(WebDriverCommand::Init(response))) {
|
| - SET_WEBDRIVER_ERROR(response, "Failure on Init for find element",
|
| - kInternalServerError);
|
| - return false;
|
| - }
|
| -
|
| - // Record the requested wait time.
|
| - if (!GetIntegerParameter("ms", &ms_to_wait_)) {
|
| - SET_WEBDRIVER_ERROR(response, "Request missing ms parameter",
|
| - kBadRequest);
|
| - return false;
|
| - }
|
| -
|
| - return true;
|
| -}
|
| -
|
| bool ImplicitWaitCommand::DoesPost() {
|
| return true;
|
| }
|
|
|
| void ImplicitWaitCommand::ExecutePost(Response* const response) {
|
| + if (!HasParameter("ms")) {
|
| + SET_WEBDRIVER_ERROR(response, "Request missing ms parameter", kBadRequest);
|
| + return;
|
| + }
|
| +
|
| + int ms_to_wait;
|
| + if (!GetIntegerParameter("ms", &ms_to_wait)) {
|
| + // Client may have sent us a floating point number. Since DictionaryValue
|
| + // will not do a down cast for us, we must explicitly check for it here.
|
| + // Note webdriver only supports whole milliseconds for a timeout value, so
|
| + // we are safe to downcast.
|
| + double ms;
|
| + if (!GetDoubleParameter("ms", &ms)) {
|
| + SET_WEBDRIVER_ERROR(response, "ms parameter is not a number",
|
| + kBadRequest);
|
| + return;
|
| + }
|
| + ms_to_wait = static_cast<int>(ms);
|
| + }
|
| +
|
| // Validate the wait time before setting it to the session.
|
| - if (ms_to_wait_ < 0) {
|
| - SET_WEBDRIVER_ERROR(response, "Wait must be non-negative",
|
| - kBadRequest);
|
| + if (ms_to_wait < 0) {
|
| + SET_WEBDRIVER_ERROR(response,
|
| + base::StringPrintf("Wait must be non-negative: %d", ms_to_wait).c_str(),
|
| + kBadRequest);
|
| return;
|
| }
|
|
|
| - session_->set_implicit_wait(ms_to_wait_);
|
| - LOG(INFO) << "Implicit wait set to: " << ms_to_wait_ << " ms";
|
| + session_->set_implicit_wait(ms_to_wait);
|
| + LOG(INFO) << "Implicit wait set to: " << ms_to_wait << " ms";
|
|
|
| response->set_value(new StringValue("success"));
|
| response->set_status(kSuccess);
|
|
|