| 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 24 matching lines...) Expand all Loading... |
| 35 bool CreateSession::DoesPost() { return true; } | 35 bool CreateSession::DoesPost() { return true; } |
| 36 | 36 |
| 37 void CreateSession::ExecutePost(Response* const response) { | 37 void CreateSession::ExecutePost(Response* const response) { |
| 38 DictionaryValue *capabilities = NULL; | 38 DictionaryValue *capabilities = NULL; |
| 39 if (!GetDictionaryParameter("desiredCapabilities", &capabilities)) { | 39 if (!GetDictionaryParameter("desiredCapabilities", &capabilities)) { |
| 40 response->SetError(new Error( | 40 response->SetError(new Error( |
| 41 kBadRequest, "Missing or invalid 'desiredCapabilities'")); | 41 kBadRequest, "Missing or invalid 'desiredCapabilities'")); |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 | 44 |
| 45 CommandLine command_line_options(CommandLine::NO_PROGRAM); | 45 Automation::InitOptions options; |
| 46 FilePath::StringType path; |
| 47 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) |
| 48 options.cmdline = CommandLine(FilePath(path)); |
| 49 |
| 46 ListValue* switches = NULL; | 50 ListValue* switches = NULL; |
| 47 const char* kCustomSwitchesKey = "chrome.switches"; | 51 const char* kCustomSwitchesKey = "chrome.switches"; |
| 48 if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey, | 52 if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey, |
| 49 &switches)) { | 53 &switches)) { |
| 50 for (size_t i = 0; i < switches->GetSize(); ++i) { | 54 for (size_t i = 0; i < switches->GetSize(); ++i) { |
| 51 std::string switch_string; | 55 std::string switch_string; |
| 52 if (!switches->GetString(i, &switch_string)) { | 56 if (!switches->GetString(i, &switch_string)) { |
| 53 response->SetError(new Error( | 57 response->SetError(new Error( |
| 54 kBadRequest, "Custom switch is not a string")); | 58 kBadRequest, "Custom switch is not a string")); |
| 55 return; | 59 return; |
| 56 } | 60 } |
| 57 size_t separator_index = switch_string.find("="); | 61 size_t separator_index = switch_string.find("="); |
| 58 if (separator_index != std::string::npos) { | 62 if (separator_index != std::string::npos) { |
| 59 CommandLine::StringType switch_string_native; | 63 CommandLine::StringType switch_string_native; |
| 60 if (!switches->GetString(i, &switch_string_native)) { | 64 if (!switches->GetString(i, &switch_string_native)) { |
| 61 response->SetError(new Error( | 65 response->SetError(new Error( |
| 62 kBadRequest, "Custom switch is not a string")); | 66 kBadRequest, "Custom switch is not a string")); |
| 63 return; | 67 return; |
| 64 } | 68 } |
| 65 command_line_options.AppendSwitchNative( | 69 options.cmdline.AppendSwitchNative( |
| 66 switch_string.substr(0, separator_index), | 70 switch_string.substr(0, separator_index), |
| 67 switch_string_native.substr(separator_index + 1)); | 71 switch_string_native.substr(separator_index + 1)); |
| 68 } else { | 72 } else { |
| 69 command_line_options.AppendSwitch(switch_string); | 73 options.cmdline.AppendSwitch(switch_string); |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 } else if (capabilities->HasKey(kCustomSwitchesKey)) { | 76 } else if (capabilities->HasKey(kCustomSwitchesKey)) { |
| 73 response->SetError(new Error( | 77 response->SetError(new Error( |
| 74 kBadRequest, "Custom switches must be a list")); | 78 kBadRequest, "Custom switches must be a list")); |
| 75 return; | 79 return; |
| 76 } | 80 } |
| 81 |
| 77 Value* verbose_value; | 82 Value* verbose_value; |
| 78 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { | 83 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { |
| 79 bool verbose; | 84 bool verbose = false; |
| 80 if (verbose_value->GetAsBoolean(&verbose) && verbose) { | 85 if (verbose_value->GetAsBoolean(&verbose)) { |
| 81 // Since logging is shared among sessions, if any session requests verbose | 86 // Since logging is shared among sessions, if any session requests verbose |
| 82 // logging, verbose logging will be enabled for all sessions. It is not | 87 // logging, verbose logging will be enabled for all sessions. It is not |
| 83 // possible to turn it off. | 88 // possible to turn it off. |
| 84 logging::SetMinLogLevel(logging::LOG_INFO); | 89 if (verbose) |
| 90 logging::SetMinLogLevel(logging::LOG_INFO); |
| 85 } else { | 91 } else { |
| 86 response->SetError(new Error( | 92 response->SetError(new Error( |
| 87 kBadRequest, "verbose must be a boolean true or false")); | 93 kBadRequest, "verbose must be a boolean true or false")); |
| 88 return; | 94 return; |
| 89 } | 95 } |
| 90 } | 96 } |
| 91 | 97 |
| 92 FilePath browser_exe; | 98 capabilities->GetStringWithoutPathExpansion( |
| 93 FilePath::StringType path; | 99 "chrome.channel", &options.channel_id); |
| 94 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) | |
| 95 browser_exe = FilePath(path); | |
| 96 | 100 |
| 97 ScopedTempDir temp_dir; | 101 ScopedTempDir temp_dir; |
| 98 FilePath temp_user_data_dir; | 102 FilePath temp_user_data_dir; |
| 99 | 103 |
| 100 std::string base64_profile; | 104 std::string base64_profile; |
| 101 if (capabilities->GetStringWithoutPathExpansion("chrome.profile", | 105 if (capabilities->GetStringWithoutPathExpansion("chrome.profile", |
| 102 &base64_profile)) { | 106 &base64_profile)) { |
| 103 if (!temp_dir.CreateUniqueTempDir()) { | 107 if (!temp_dir.CreateUniqueTempDir()) { |
| 104 response->SetError(new Error( | 108 response->SetError(new Error( |
| 105 kUnknownError, "Could not create temporary directory.")); | 109 kUnknownError, "Could not create temporary directory.")); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 123 temp_user_data_dir = temp_dir.path().AppendASCII("user_data_dir"); | 127 temp_user_data_dir = temp_dir.path().AppendASCII("user_data_dir"); |
| 124 if (!Unzip(temp_profile_zip, temp_user_data_dir)) { | 128 if (!Unzip(temp_profile_zip, temp_user_data_dir)) { |
| 125 response->SetError(new Error( | 129 response->SetError(new Error( |
| 126 kBadRequest, "Could not unarchive provided user profile")); | 130 kBadRequest, "Could not unarchive provided user profile")); |
| 127 return; | 131 return; |
| 128 } | 132 } |
| 129 } | 133 } |
| 130 | 134 |
| 131 // Session manages its own liftime, so do not call delete. | 135 // Session manages its own liftime, so do not call delete. |
| 132 Session* session = new Session(); | 136 Session* session = new Session(); |
| 133 Error* error = session->Init(browser_exe, | 137 Error* error = session->Init(options); |
| 134 temp_user_data_dir, | |
| 135 command_line_options); | |
| 136 if (error) { | 138 if (error) { |
| 137 response->SetError(error); | 139 response->SetError(error); |
| 138 return; | 140 return; |
| 139 } | 141 } |
| 140 | 142 |
| 141 bool native_events_required = false; | 143 bool native_events_required = false; |
| 142 Value* native_events_value = NULL; | 144 Value* native_events_value = NULL; |
| 143 if (capabilities->GetWithoutPathExpansion( | 145 if (capabilities->GetWithoutPathExpansion( |
| 144 "chrome.nativeEvents", &native_events_value)) { | 146 "chrome.nativeEvents", &native_events_value)) { |
| 145 if (native_events_value->GetAsBoolean(&native_events_required)) { | 147 if (native_events_value->GetAsBoolean(&native_events_required)) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 158 // difficult, and returning the hostname causes perf problems with the python | 160 // difficult, and returning the hostname causes perf problems with the python |
| 159 // bindings on Windows. | 161 // bindings on Windows. |
| 160 std::ostringstream stream; | 162 std::ostringstream stream; |
| 161 stream << SessionManager::GetInstance()->url_base() << "/session/" | 163 stream << SessionManager::GetInstance()->url_base() << "/session/" |
| 162 << session->id(); | 164 << session->id(); |
| 163 response->SetStatus(kSeeOther); | 165 response->SetStatus(kSeeOther); |
| 164 response->SetValue(Value::CreateStringValue(stream.str())); | 166 response->SetValue(Value::CreateStringValue(stream.str())); |
| 165 } | 167 } |
| 166 | 168 |
| 167 } // namespace webdriver | 169 } // namespace webdriver |
| OLD | NEW |