OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/session_commands.h" | 5 #include "chrome/test/chromedriver/session_commands.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if (status.IsOk()) { | 98 if (status.IsOk()) { |
99 chrome_caps->SetString( | 99 chrome_caps->SetString( |
100 "userDataDir", | 100 "userDataDir", |
101 desktop->command().GetSwitchValueNative("user-data-dir")); | 101 desktop->command().GetSwitchValueNative("user-data-dir")); |
102 } | 102 } |
103 | 103 |
104 caps->Set("chrome", chrome_caps.release()); | 104 caps->Set("chrome", chrome_caps.release()); |
105 return caps.Pass(); | 105 return caps.Pass(); |
106 } | 106 } |
107 | 107 |
| 108 Status CheckSessionCreated(Session* session) { |
| 109 WebView* web_view = NULL; |
| 110 Status status = session->GetTargetWindow(&web_view); |
| 111 if (status.IsError()) |
| 112 return Status(kSessionNotCreatedException, status); |
| 113 |
| 114 status = web_view->ConnectIfNecessary(); |
| 115 if (status.IsError()) |
| 116 return Status(kSessionNotCreatedException, status); |
| 117 |
| 118 base::ListValue args; |
| 119 scoped_ptr<base::Value> result(new base::FundamentalValue(0)); |
| 120 status = web_view->CallFunction(session->GetCurrentFrameId(), |
| 121 "function(s) { return 1; }", args, &result); |
| 122 if (status.IsError()) |
| 123 return Status(kSessionNotCreatedException, status); |
| 124 |
| 125 int response; |
| 126 if (!result->GetAsInteger(&response) || response != 1) { |
| 127 return Status(kSessionNotCreatedException, |
| 128 "unexpected response from browser"); |
| 129 } |
| 130 |
| 131 return Status(kOk); |
| 132 } |
| 133 |
108 Status InitSessionHelper( | 134 Status InitSessionHelper( |
109 const InitSessionParams& bound_params, | 135 const InitSessionParams& bound_params, |
110 Session* session, | 136 Session* session, |
111 const base::DictionaryValue& params, | 137 const base::DictionaryValue& params, |
112 scoped_ptr<base::Value>* value) { | 138 scoped_ptr<base::Value>* value) { |
113 session->driver_log.reset( | 139 session->driver_log.reset( |
114 new WebDriverLog(WebDriverLog::kDriverType, Log::kAll)); | 140 new WebDriverLog(WebDriverLog::kDriverType, Log::kAll)); |
115 const base::DictionaryValue* desired_caps; | 141 const base::DictionaryValue* desired_caps; |
116 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) | 142 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) |
117 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); | 143 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (status.IsError() || web_view_ids.empty()) { | 184 if (status.IsError() || web_view_ids.empty()) { |
159 return status.IsError() ? status : | 185 return status.IsError() ? status : |
160 Status(kUnknownError, "unable to discover open window in chrome"); | 186 Status(kUnknownError, "unable to discover open window in chrome"); |
161 } | 187 } |
162 | 188 |
163 session->window = web_view_ids.front(); | 189 session->window = web_view_ids.front(); |
164 session->detach = capabilities.detach; | 190 session->detach = capabilities.detach; |
165 session->force_devtools_screenshot = capabilities.force_devtools_screenshot; | 191 session->force_devtools_screenshot = capabilities.force_devtools_screenshot; |
166 session->capabilities = CreateCapabilities(session->chrome.get()); | 192 session->capabilities = CreateCapabilities(session->chrome.get()); |
167 value->reset(session->capabilities->DeepCopy()); | 193 value->reset(session->capabilities->DeepCopy()); |
168 return Status(kOk); | 194 return CheckSessionCreated(session); |
169 } | 195 } |
170 | 196 |
171 } // namespace | 197 } // namespace |
172 | 198 |
173 Status ExecuteInitSession( | 199 Status ExecuteInitSession( |
174 const InitSessionParams& bound_params, | 200 const InitSessionParams& bound_params, |
175 Session* session, | 201 Session* session, |
176 const base::DictionaryValue& params, | 202 const base::DictionaryValue& params, |
177 scoped_ptr<base::Value>* value) { | 203 scoped_ptr<base::Value>* value) { |
178 Status status = InitSessionHelper(bound_params, session, params, value); | 204 Status status = InitSessionHelper(bound_params, session, params, value); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 Status ExecuteSetAutoReporting( | 674 Status ExecuteSetAutoReporting( |
649 Session* session, | 675 Session* session, |
650 const base::DictionaryValue& params, | 676 const base::DictionaryValue& params, |
651 scoped_ptr<base::Value>* value) { | 677 scoped_ptr<base::Value>* value) { |
652 bool enabled; | 678 bool enabled; |
653 if (!params.GetBoolean("enabled", &enabled)) | 679 if (!params.GetBoolean("enabled", &enabled)) |
654 return Status(kUnknownError, "missing parameter 'enabled'"); | 680 return Status(kUnknownError, "missing parameter 'enabled'"); |
655 session->auto_reporting_enabled = enabled; | 681 session->auto_reporting_enabled = enabled; |
656 return Status(kOk); | 682 return Status(kOk); |
657 } | 683 } |
OLD | NEW |