Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Side by Side Diff: chrome/test/webdriver/commands/implicit_wait_command.cc

Issue 6532068: Fix a bug in ImplicitWaitCommand: we must explicitly check if the ms param... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Reverting changes added while debugging Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/stringprintf.h"
7 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
8 #include "chrome/test/webdriver/commands/implicit_wait_command.h" 9 #include "chrome/test/webdriver/commands/implicit_wait_command.h"
9 10
10 namespace webdriver { 11 namespace webdriver {
11 12
12 ImplicitWaitCommand::ImplicitWaitCommand( 13 ImplicitWaitCommand::ImplicitWaitCommand(
13 const std::vector<std::string>& path_segments, 14 const std::vector<std::string>& path_segments,
14 const DictionaryValue* const parameters) 15 const DictionaryValue* const parameters)
15 : WebDriverCommand(path_segments, parameters), 16 : WebDriverCommand(path_segments, parameters) {}
16 ms_to_wait_(0) {}
17 17
18 ImplicitWaitCommand::~ImplicitWaitCommand() {} 18 ImplicitWaitCommand::~ImplicitWaitCommand() {}
19 19
20 bool ImplicitWaitCommand::Init(Response* const response) {
21 if (!(WebDriverCommand::Init(response))) {
22 SET_WEBDRIVER_ERROR(response, "Failure on Init for find element",
23 kInternalServerError);
24 return false;
25 }
26
27 // Record the requested wait time.
28 if (!GetIntegerParameter("ms", &ms_to_wait_)) {
29 SET_WEBDRIVER_ERROR(response, "Request missing ms parameter",
30 kBadRequest);
31 return false;
32 }
33
34 return true;
35 }
36
37 bool ImplicitWaitCommand::DoesPost() { 20 bool ImplicitWaitCommand::DoesPost() {
38 return true; 21 return true;
39 } 22 }
40 23
41 void ImplicitWaitCommand::ExecutePost(Response* const response) { 24 void ImplicitWaitCommand::ExecutePost(Response* const response) {
42 // Validate the wait time before setting it to the session. 25 if (!HasParameter("ms")) {
43 if (ms_to_wait_ < 0) { 26 SET_WEBDRIVER_ERROR(response, "Request missing ms parameter", kBadRequest);
44 SET_WEBDRIVER_ERROR(response, "Wait must be non-negative",
45 kBadRequest);
46 return; 27 return;
47 } 28 }
48 29
49 session_->set_implicit_wait(ms_to_wait_); 30 int ms_to_wait;
50 LOG(INFO) << "Implicit wait set to: " << ms_to_wait_ << " ms"; 31 if (!GetIntegerParameter("ms", &ms_to_wait)) {
32 // Client may have sent us a floating point number. Since DictionaryValue
33 // will not do a down cast for us, we must explicitly check for it here.
34 // Note webdriver only supports whole milliseconds for a timeout value, so
35 // we are safe to downcast.
36 double ms;
37 if (!GetDoubleParameter("ms", &ms)) {
38 SET_WEBDRIVER_ERROR(response, "ms parameter is not a number",
39 kBadRequest);
40 return;
41 }
42 ms_to_wait = static_cast<int>(ms);
43 }
44
45 // Validate the wait time before setting it to the session.
46 if (ms_to_wait < 0) {
47 SET_WEBDRIVER_ERROR(response,
48 base::StringPrintf("Wait must be non-negative: %d", ms_to_wait).c_str(),
49 kBadRequest);
50 return;
51 }
52
53 session_->set_implicit_wait(ms_to_wait);
54 LOG(INFO) << "Implicit wait set to: " << ms_to_wait << " ms";
51 55
52 response->set_value(new StringValue("success")); 56 response->set_value(new StringValue("success"));
53 response->set_status(kSuccess); 57 response->set_status(kSuccess);
54 } 58 }
55 59
56 bool ImplicitWaitCommand::RequiresValidTab() { 60 bool ImplicitWaitCommand::RequiresValidTab() {
57 return true; 61 return true;
58 } 62 }
59 63
60 } // namespace webdriver 64 } // namespace webdriver
61 65
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698