| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 bool CreateSession::DoesPost() { return true; } | 55 bool CreateSession::DoesPost() { return true; } |
| 56 | 56 |
| 57 void CreateSession::ExecutePost(Response* const response) { | 57 void CreateSession::ExecutePost(Response* const response) { |
| 58 DictionaryValue *capabilities = NULL; | 58 DictionaryValue *capabilities = NULL; |
| 59 if (!GetDictionaryParameter("desiredCapabilities", &capabilities)) { | 59 if (!GetDictionaryParameter("desiredCapabilities", &capabilities)) { |
| 60 response->SetError(new Error( | 60 response->SetError(new Error( |
| 61 kBadRequest, "Missing or invalid 'desiredCapabilities'")); | 61 kBadRequest, "Missing or invalid 'desiredCapabilities'")); |
| 62 return; | 62 return; |
| 63 } | 63 } |
| 64 | 64 |
| 65 CommandLine command_line_options(CommandLine::NO_PROGRAM); | 65 Automation::InitOptions options; |
| 66 FilePath::StringType path; |
| 67 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) |
| 68 options.cmdline = CommandLine(FilePath(path)); |
| 69 |
| 66 ListValue* switches = NULL; | 70 ListValue* switches = NULL; |
| 67 const char* kCustomSwitchesKey = "chrome.switches"; | 71 const char* kCustomSwitchesKey = "chrome.switches"; |
| 68 if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey, | 72 if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey, |
| 69 &switches)) { | 73 &switches)) { |
| 70 for (size_t i = 0; i < switches->GetSize(); ++i) { | 74 for (size_t i = 0; i < switches->GetSize(); ++i) { |
| 71 std::string switch_string; | 75 std::string switch_string; |
| 72 if (!switches->GetString(i, &switch_string)) { | 76 if (!switches->GetString(i, &switch_string)) { |
| 73 response->SetError(new Error( | 77 response->SetError(new Error( |
| 74 kBadRequest, "Custom switch is not a string")); | 78 kBadRequest, "Custom switch is not a string")); |
| 75 return; | 79 return; |
| 76 } | 80 } |
| 77 size_t separator_index = switch_string.find("="); | 81 size_t separator_index = switch_string.find("="); |
| 78 if (separator_index != std::string::npos) { | 82 if (separator_index != std::string::npos) { |
| 79 CommandLine::StringType switch_string_native; | 83 CommandLine::StringType switch_string_native; |
| 80 if (!switches->GetString(i, &switch_string_native)) { | 84 if (!switches->GetString(i, &switch_string_native)) { |
| 81 response->SetError(new Error( | 85 response->SetError(new Error( |
| 82 kBadRequest, "Custom switch is not a string")); | 86 kBadRequest, "Custom switch is not a string")); |
| 83 return; | 87 return; |
| 84 } | 88 } |
| 85 command_line_options.AppendSwitchNative( | 89 options.cmdline.AppendSwitchNative( |
| 86 switch_string.substr(0, separator_index), | 90 switch_string.substr(0, separator_index), |
| 87 switch_string_native.substr(separator_index + 1)); | 91 switch_string_native.substr(separator_index + 1)); |
| 88 } else { | 92 } else { |
| 89 command_line_options.AppendSwitch(switch_string); | 93 options.cmdline.AppendSwitch(switch_string); |
| 90 } | 94 } |
| 91 } | 95 } |
| 92 } else if (capabilities->HasKey(kCustomSwitchesKey)) { | 96 } else if (capabilities->HasKey(kCustomSwitchesKey)) { |
| 93 response->SetError(new Error( | 97 response->SetError(new Error( |
| 94 kBadRequest, "Custom switches must be a list")); | 98 kBadRequest, "Custom switches must be a list")); |
| 95 return; | 99 return; |
| 96 } | 100 } |
| 101 |
| 97 Value* verbose_value; | 102 Value* verbose_value; |
| 98 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { | 103 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { |
| 99 bool verbose; | 104 bool verbose = false; |
| 100 if (verbose_value->GetAsBoolean(&verbose) && verbose) { | 105 if (verbose_value->GetAsBoolean(&verbose)) { |
| 101 // Since logging is shared among sessions, if any session requests verbose | 106 // Since logging is shared among sessions, if any session requests verbose |
| 102 // logging, verbose logging will be enabled for all sessions. It is not | 107 // logging, verbose logging will be enabled for all sessions. It is not |
| 103 // possible to turn it off. | 108 // possible to turn it off. |
| 104 logging::SetMinLogLevel(logging::LOG_INFO); | 109 if (verbose) |
| 110 logging::SetMinLogLevel(logging::LOG_INFO); |
| 105 } else { | 111 } else { |
| 106 response->SetError(new Error( | 112 response->SetError(new Error( |
| 107 kBadRequest, "verbose must be a boolean true or false")); | 113 kBadRequest, "verbose must be a boolean true or false")); |
| 108 return; | 114 return; |
| 109 } | 115 } |
| 110 } | 116 } |
| 111 | 117 |
| 112 FilePath browser_exe; | 118 capabilities->GetStringWithoutPathExpansion( |
| 113 FilePath::StringType path; | 119 "chrome.channel", &options.channel_id); |
| 114 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) | |
| 115 browser_exe = FilePath(path); | |
| 116 | 120 |
| 117 ScopedTempDir temp_profile_dir; | 121 ScopedTempDir temp_profile_dir; |
| 118 FilePath temp_user_data_dir; | 122 FilePath temp_user_data_dir; |
| 119 | 123 |
| 120 std::string base64_profile; | 124 std::string base64_profile; |
| 121 if (capabilities->GetStringWithoutPathExpansion("chrome.profile", | 125 if (capabilities->GetStringWithoutPathExpansion("chrome.profile", |
| 122 &base64_profile)) { | 126 &base64_profile)) { |
| 123 if (!temp_profile_dir.CreateUniqueTempDir()) { | 127 if (!temp_profile_dir.CreateUniqueTempDir()) { |
| 124 response->SetError(new Error( | 128 response->SetError(new Error( |
| 125 kBadRequest, "Could not create temporary profile directory.")); | 129 kBadRequest, "Could not create temporary profile directory.")); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 extensions.push_back(extension_file); | 174 extensions.push_back(extension_file); |
| 171 } | 175 } |
| 172 } else if (capabilities->HasKey(kExtensions)) { | 176 } else if (capabilities->HasKey(kExtensions)) { |
| 173 response->SetError(new Error( | 177 response->SetError(new Error( |
| 174 kBadRequest, "Extensions must be a list of base64 encoded strings")); | 178 kBadRequest, "Extensions must be a list of base64 encoded strings")); |
| 175 return; | 179 return; |
| 176 } | 180 } |
| 177 | 181 |
| 178 // Session manages its own liftime, so do not call delete. | 182 // Session manages its own liftime, so do not call delete. |
| 179 Session* session = new Session(); | 183 Session* session = new Session(); |
| 180 Error* error = session->Init(browser_exe, | 184 Error* error = session->Init(options); |
| 181 temp_user_data_dir, | |
| 182 command_line_options); | |
| 183 if (error) { | 185 if (error) { |
| 184 response->SetError(error); | 186 response->SetError(error); |
| 185 return; | 187 return; |
| 186 } | 188 } |
| 187 | 189 |
| 188 // Install extensions. | 190 // Install extensions. |
| 189 for (size_t i = 0; i < extensions.size(); ++i) { | 191 for (size_t i = 0; i < extensions.size(); ++i) { |
| 190 Error* error = session->InstallExtension(extensions[i]); | 192 Error* error = session->InstallExtension(extensions[i]); |
| 191 if (error) { | 193 if (error) { |
| 192 response->SetError(error); | 194 response->SetError(error); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 214 // difficult, and returning the hostname causes perf problems with the python | 216 // difficult, and returning the hostname causes perf problems with the python |
| 215 // bindings on Windows. | 217 // bindings on Windows. |
| 216 std::ostringstream stream; | 218 std::ostringstream stream; |
| 217 stream << SessionManager::GetInstance()->url_base() << "/session/" | 219 stream << SessionManager::GetInstance()->url_base() << "/session/" |
| 218 << session->id(); | 220 << session->id(); |
| 219 response->SetStatus(kSeeOther); | 221 response->SetStatus(kSeeOther); |
| 220 response->SetValue(Value::CreateStringValue(stream.str())); | 222 response->SetValue(Value::CreateStringValue(stream.str())); |
| 221 } | 223 } |
| 222 | 224 |
| 223 } // namespace webdriver | 225 } // namespace webdriver |
| OLD | NEW |