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