summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/commands/implicit_wait_command.cc
blob: e7eb725a04e1f079e3c767097d1fd618a321cb83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2010 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.

#include <string>

#include "base/utf_string_conversions.h"
#include "chrome/test/webdriver/commands/implicit_wait_command.h"

namespace webdriver {

ImplicitWaitCommand::ImplicitWaitCommand(
    const std::vector<std::string>& path_segments,
    const DictionaryValue* const parameters)
    : WebDriverCommand(path_segments, parameters),
      ms_to_wait_(0) {}

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) {
  // 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);
    return;
  }

  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);
}

bool ImplicitWaitCommand::RequiresValidTab() {
  return true;
}

}  // namespace webdriver