OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webdriver/commands/create_session.h" | 5 #include "chrome/test/webdriver/commands/create_session.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 bool CreateSession::DoesPost() { return true; } | 66 bool CreateSession::DoesPost() { return true; } |
67 | 67 |
68 void CreateSession::ExecutePost(Response* const response) { | 68 void CreateSession::ExecutePost(Response* const response) { |
69 DictionaryValue *capabilities = NULL; | 69 DictionaryValue *capabilities = NULL; |
70 if (!GetDictionaryParameter("desiredCapabilities", &capabilities)) { | 70 if (!GetDictionaryParameter("desiredCapabilities", &capabilities)) { |
71 response->SetError(new Error( | 71 response->SetError(new Error( |
72 kBadRequest, "Missing or invalid 'desiredCapabilities'")); | 72 kBadRequest, "Missing or invalid 'desiredCapabilities'")); |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
76 Automation::BrowserOptions browser_options; | 76 CommandLine command_line_options(CommandLine::NO_PROGRAM); |
77 FilePath::StringType path; | |
78 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) | |
79 browser_options.cmdline = CommandLine(FilePath(path)); | |
80 | |
81 ListValue* switches = NULL; | 77 ListValue* switches = NULL; |
82 const char* kCustomSwitchesKey = "chrome.switches"; | 78 const char* kCustomSwitchesKey = "chrome.switches"; |
83 if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey, | 79 if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey, |
84 &switches)) { | 80 &switches)) { |
85 for (size_t i = 0; i < switches->GetSize(); ++i) { | 81 for (size_t i = 0; i < switches->GetSize(); ++i) { |
86 std::string switch_string; | 82 std::string switch_string; |
87 if (!switches->GetString(i, &switch_string)) { | 83 if (!switches->GetString(i, &switch_string)) { |
88 response->SetError(new Error( | 84 response->SetError(new Error( |
89 kBadRequest, "Custom switch is not a string")); | 85 kBadRequest, "Custom switch is not a string")); |
90 return; | 86 return; |
91 } | 87 } |
92 size_t separator_index = switch_string.find("="); | 88 size_t separator_index = switch_string.find("="); |
93 if (separator_index != std::string::npos) { | 89 if (separator_index != std::string::npos) { |
94 CommandLine::StringType switch_string_native; | 90 CommandLine::StringType switch_string_native; |
95 if (!switches->GetString(i, &switch_string_native)) { | 91 if (!switches->GetString(i, &switch_string_native)) { |
96 response->SetError(new Error( | 92 response->SetError(new Error( |
97 kBadRequest, "Custom switch is not a string")); | 93 kBadRequest, "Custom switch is not a string")); |
98 return; | 94 return; |
99 } | 95 } |
100 browser_options.cmdline.AppendSwitchNative( | 96 command_line_options.AppendSwitchNative( |
101 switch_string.substr(0, separator_index), | 97 switch_string.substr(0, separator_index), |
102 switch_string_native.substr(separator_index + 1)); | 98 switch_string_native.substr(separator_index + 1)); |
103 } else { | 99 } else { |
104 browser_options.cmdline.AppendSwitch(switch_string); | 100 command_line_options.AppendSwitch(switch_string); |
105 } | 101 } |
106 } | 102 } |
107 } else if (capabilities->HasKey(kCustomSwitchesKey)) { | 103 } else if (capabilities->HasKey(kCustomSwitchesKey)) { |
108 response->SetError(new Error( | 104 response->SetError(new Error( |
109 kBadRequest, "Custom switches must be a list")); | 105 kBadRequest, "Custom switches must be a list")); |
110 return; | 106 return; |
111 } | 107 } |
112 | |
113 Value* verbose_value; | 108 Value* verbose_value; |
114 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { | 109 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { |
115 bool verbose = false; | 110 bool verbose; |
116 if (verbose_value->GetAsBoolean(&verbose)) { | 111 if (verbose_value->GetAsBoolean(&verbose) && verbose) { |
117 // Since logging is shared among sessions, if any session requests verbose | 112 // Since logging is shared among sessions, if any session requests verbose |
118 // logging, verbose logging will be enabled for all sessions. It is not | 113 // logging, verbose logging will be enabled for all sessions. It is not |
119 // possible to turn it off. | 114 // possible to turn it off. |
120 if (verbose) | 115 logging::SetMinLogLevel(logging::LOG_INFO); |
121 logging::SetMinLogLevel(logging::LOG_INFO); | |
122 } else { | 116 } else { |
123 response->SetError(new Error( | 117 response->SetError(new Error( |
124 kBadRequest, "verbose must be a boolean true or false")); | 118 kBadRequest, "verbose must be a boolean true or false")); |
125 return; | 119 return; |
126 } | 120 } |
127 } | 121 } |
128 | 122 |
129 capabilities->GetStringWithoutPathExpansion( | 123 FilePath browser_exe; |
130 "chrome.channel", &browser_options.channel_id); | 124 FilePath::StringType path; |
| 125 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) |
| 126 browser_exe = FilePath(path); |
131 | 127 |
132 ScopedTempDir temp_profile_dir; | 128 ScopedTempDir temp_profile_dir; |
133 FilePath temp_user_data_dir; | 129 FilePath temp_user_data_dir; |
134 | 130 |
135 std::string base64_profile; | 131 std::string base64_profile; |
136 if (capabilities->GetStringWithoutPathExpansion("chrome.profile", | 132 if (capabilities->GetStringWithoutPathExpansion("chrome.profile", |
137 &base64_profile)) { | 133 &base64_profile)) { |
138 if (!temp_profile_dir.CreateUniqueTempDir()) { | 134 if (!temp_profile_dir.CreateUniqueTempDir()) { |
139 response->SetError(new Error( | 135 response->SetError(new Error( |
140 kBadRequest, "Could not create temporary profile directory.")); | 136 kBadRequest, "Could not create temporary profile directory.")); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 return; | 179 return; |
184 } | 180 } |
185 extensions.push_back(extension_file); | 181 extensions.push_back(extension_file); |
186 } | 182 } |
187 } else if (capabilities->HasKey(kExtensions)) { | 183 } else if (capabilities->HasKey(kExtensions)) { |
188 response->SetError(new Error( | 184 response->SetError(new Error( |
189 kBadRequest, "Extensions must be a list of base64 encoded strings")); | 185 kBadRequest, "Extensions must be a list of base64 encoded strings")); |
190 return; | 186 return; |
191 } | 187 } |
192 | 188 |
193 Session::Options session_options; | 189 Session::Options options; |
194 Error* error = NULL; | 190 Error* error = NULL; |
195 error = GetBooleanCapability(capabilities, "chrome.nativeEvents", | 191 error = GetBooleanCapability(capabilities, "chrome.nativeEvents", |
196 &session_options.use_native_events); | 192 &options.use_native_events); |
197 if (!error) { | 193 if (!error) { |
198 error = GetBooleanCapability(capabilities, "chrome.loadAsync", | 194 error = GetBooleanCapability(capabilities, "chrome.loadAsync", |
199 &session_options.load_async); | 195 &options.load_async); |
200 } | 196 } |
201 if (error) { | 197 if (error) { |
202 response->SetError(error); | 198 response->SetError(error); |
203 return; | 199 return; |
204 } | 200 } |
205 | 201 |
206 // Session manages its own liftime, so do not call delete. | 202 // Session manages its own liftime, so do not call delete. |
207 Session* session = new Session(session_options); | 203 Session* session = new Session(options); |
208 error = session->Init(browser_options); | 204 error = session->Init(browser_exe, |
| 205 temp_user_data_dir, |
| 206 command_line_options); |
209 if (error) { | 207 if (error) { |
210 response->SetError(error); | 208 response->SetError(error); |
211 return; | 209 return; |
212 } | 210 } |
213 | 211 |
214 // Install extensions. | 212 // Install extensions. |
215 for (size_t i = 0; i < extensions.size(); ++i) { | 213 for (size_t i = 0; i < extensions.size(); ++i) { |
216 Error* error = session->InstallExtension(extensions[i]); | 214 Error* error = session->InstallExtension(extensions[i]); |
217 if (error) { | 215 if (error) { |
218 response->SetError(error); | 216 response->SetError(error); |
219 return; | 217 return; |
220 } | 218 } |
221 } | 219 } |
222 | 220 |
223 LOG(INFO) << "Created session " << session->id(); | 221 LOG(INFO) << "Created session " << session->id(); |
224 // Redirect to a relative URI. Although prohibited by the HTTP standard, | 222 // Redirect to a relative URI. Although prohibited by the HTTP standard, |
225 // this is what the IEDriver does. Finding the actual IP address is | 223 // this is what the IEDriver does. Finding the actual IP address is |
226 // difficult, and returning the hostname causes perf problems with the python | 224 // difficult, and returning the hostname causes perf problems with the python |
227 // bindings on Windows. | 225 // bindings on Windows. |
228 std::ostringstream stream; | 226 std::ostringstream stream; |
229 stream << SessionManager::GetInstance()->url_base() << "/session/" | 227 stream << SessionManager::GetInstance()->url_base() << "/session/" |
230 << session->id(); | 228 << session->id(); |
231 response->SetStatus(kSeeOther); | 229 response->SetStatus(kSeeOther); |
232 response->SetValue(Value::CreateStringValue(stream.str())); | 230 response->SetValue(Value::CreateStringValue(stream.str())); |
233 } | 231 } |
234 | 232 |
235 } // namespace webdriver | 233 } // namespace webdriver |
OLD | NEW |