1414
1515namespace webdriver {
1616
17+ const int SetTimeoutCommand::DEFAULT_TIMEOUT = 60000 ;
18+
1719SetTimeoutCommand::SetTimeoutCommand (
1820 const std::vector<std::string>& path_segments,
1921 const DictionaryValue* const parameters) :
@@ -49,13 +51,53 @@ void SetTimeoutCommand::ExecutePost(Response* const response) {
4951 ms_to_wait = static_cast <int >(ms);
5052 }
5153
52- // Validate the wait time before setting it to the session.
53- if (ms_to_wait < 0 ) {
54- response->SetError (new Error (kBadRequest , " Timeout must be non-negative" ));
54+ Error* error = NULL ;
55+ scoped_ptr<Error> err (error);
56+
57+ // Timeout type as string
58+ const char kTimeoutTypeKey [] = " type" ;
59+ std::string type_of_operation;
60+ if (!HasParameter (kTimeoutTypeKey )) {
61+ error = SetTimeout (ms_to_wait);
62+ if (error)
63+ response->SetError (error);
5564 return ;
5665 }
66+ if (!GetStringParameter (kTimeoutTypeKey , &type_of_operation)) {
67+ response->SetError (new Error (
68+ kBadRequest , " 'type' parameter must be a string" ));
69+ return ;
70+ }
71+ error = SetTimeout (ms_to_wait, type_of_operation);
72+ if (error)
73+ response->SetError (error);
74+ }
5775
58- SetTimeout (ms_to_wait);
76+ Error* SetTimeoutCommand::SetTimeout (int timeout_ms) {
77+ return new Error (kUnknownError , " Request missing 'type' parameter" );
78+ }
79+
80+ Error* SetTimeoutCommand::SetTimeout (int timeout_ms, std::string type) {
81+ if (!type.compare (" implicit" )) {
82+ // timeouts value has a lower bound of 0 for implicit wait.
83+ if (timeout_ms < 0 )
84+ return new Error (kUnknownError , " Timeout for implicit wait must be non-negative" );
85+ session_->set_implicit_wait (timeout_ms);
86+ return NULL ;
87+ } else {
88+ // Validate the wait time before setting it to the session.
89+ if (timeout_ms < 0 )
90+ timeout_ms = DEFAULT_TIMEOUT;
91+ if (!type.compare (" page load" )) {
92+ session_->set_page_load_timeout (timeout_ms);
93+ return NULL ;
94+ } else if (!type.compare (" script" )) {
95+ session_->set_async_script_timeout (timeout_ms);
96+ return NULL ;
97+ } else {
98+ return new Error (kUnknownError , " Unknown type of timeout:" + type);
99+ }
100+ }
59101}
60102
61103SetAsyncScriptTimeoutCommand::SetAsyncScriptTimeoutCommand (
@@ -65,8 +107,11 @@ SetAsyncScriptTimeoutCommand::SetAsyncScriptTimeoutCommand(
65107
66108SetAsyncScriptTimeoutCommand::~SetAsyncScriptTimeoutCommand () {}
67109
68- void SetAsyncScriptTimeoutCommand::SetTimeout (int timeout_ms) {
110+ Error* SetAsyncScriptTimeoutCommand::SetTimeout (int timeout_ms) {
111+ if (timeout_ms < 0 )
112+ timeout_ms = DEFAULT_TIMEOUT;
69113 session_->set_async_script_timeout (timeout_ms);
114+ return NULL ;
70115}
71116
72117ImplicitWaitCommand::ImplicitWaitCommand (
@@ -76,8 +121,12 @@ ImplicitWaitCommand::ImplicitWaitCommand(
76121
77122ImplicitWaitCommand::~ImplicitWaitCommand () {}
78123
79- void ImplicitWaitCommand::SetTimeout (int timeout_ms) {
124+ Error* ImplicitWaitCommand::SetTimeout (int timeout_ms) {
125+ // timeouts value has a lower bound of 0 for implicit wait.
126+ if (timeout_ms < 0 )
127+ return new Error (kUnknownError , " Timeout for implicit wait must be non-negative" );
80128 session_->set_implicit_wait (timeout_ms);
129+ return NULL ;
81130}
82131
83132} // namespace webdriver
0 commit comments