| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Automation::BrowserOptions browser_options; |
| 77 FilePath::StringType path; | 77 FilePath::StringType path; |
| 78 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) | 78 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) |
| 79 browser_options.command = CommandLine(FilePath(path)); | 79 browser_options.cmdline = CommandLine(FilePath(path)); |
| 80 | 80 |
| 81 ListValue* switches = NULL; | 81 ListValue* switches = NULL; |
| 82 const char* kCustomSwitchesKey = "chrome.switches"; | 82 const char* kCustomSwitchesKey = "chrome.switches"; |
| 83 if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey, | 83 if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey, |
| 84 &switches)) { | 84 &switches)) { |
| 85 for (size_t i = 0; i < switches->GetSize(); ++i) { | 85 for (size_t i = 0; i < switches->GetSize(); ++i) { |
| 86 std::string switch_string; | 86 std::string switch_string; |
| 87 if (!switches->GetString(i, &switch_string)) { | 87 if (!switches->GetString(i, &switch_string)) { |
| 88 response->SetError(new Error( | 88 response->SetError(new Error( |
| 89 kBadRequest, "Custom switch is not a string")); | 89 kBadRequest, "Custom switch is not a string")); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 size_t separator_index = switch_string.find("="); | 92 size_t separator_index = switch_string.find("="); |
| 93 if (separator_index != std::string::npos) { | 93 if (separator_index != std::string::npos) { |
| 94 CommandLine::StringType switch_string_native; | 94 CommandLine::StringType switch_string_native; |
| 95 if (!switches->GetString(i, &switch_string_native)) { | 95 if (!switches->GetString(i, &switch_string_native)) { |
| 96 response->SetError(new Error( | 96 response->SetError(new Error( |
| 97 kBadRequest, "Custom switch is not a string")); | 97 kBadRequest, "Custom switch is not a string")); |
| 98 return; | 98 return; |
| 99 } | 99 } |
| 100 browser_options.command.AppendSwitchNative( | 100 browser_options.cmdline.AppendSwitchNative( |
| 101 switch_string.substr(0, separator_index), | 101 switch_string.substr(0, separator_index), |
| 102 switch_string_native.substr(separator_index + 1)); | 102 switch_string_native.substr(separator_index + 1)); |
| 103 } else { | 103 } else { |
| 104 browser_options.command.AppendSwitch(switch_string); | 104 browser_options.cmdline.AppendSwitch(switch_string); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 } else if (capabilities->HasKey(kCustomSwitchesKey)) { | 107 } else if (capabilities->HasKey(kCustomSwitchesKey)) { |
| 108 response->SetError(new Error( | 108 response->SetError(new Error( |
| 109 kBadRequest, "Custom switches must be a list")); | 109 kBadRequest, "Custom switches must be a list")); |
| 110 return; | 110 return; |
| 111 } | 111 } |
| 112 | 112 |
| 113 Value* verbose_value; | 113 Value* verbose_value; |
| 114 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { | 114 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { |
| 115 bool verbose = false; | 115 bool verbose = false; |
| 116 if (verbose_value->GetAsBoolean(&verbose)) { | 116 if (verbose_value->GetAsBoolean(&verbose)) { |
| 117 // Since logging is shared among sessions, if any session requests verbose | 117 // Since logging is shared among sessions, if any session requests verbose |
| 118 // 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 |
| 119 // possible to turn it off. | 119 // possible to turn it off. |
| 120 if (verbose) | 120 if (verbose) |
| 121 logging::SetMinLogLevel(logging::LOG_INFO); | 121 logging::SetMinLogLevel(logging::LOG_INFO); |
| 122 } else { | 122 } else { |
| 123 response->SetError(new Error( | 123 response->SetError(new Error( |
| 124 kBadRequest, "verbose must be a boolean true or false")); | 124 kBadRequest, "verbose must be a boolean true or false")); |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 capabilities->GetStringWithoutPathExpansion( | 129 capabilities->GetStringWithoutPathExpansion( |
| 130 "chrome.channel", &browser_options.channel_id); | 130 "chrome.channel", &browser_options.channel_id); |
| 131 | 131 |
| 132 ScopedTempDir temp_profile_dir; | 132 ScopedTempDir temp_profile_dir; |
| 133 FilePath temp_user_data_dir; |
| 134 |
| 133 std::string base64_profile; | 135 std::string base64_profile; |
| 134 if (capabilities->GetStringWithoutPathExpansion("chrome.profile", | 136 if (capabilities->GetStringWithoutPathExpansion("chrome.profile", |
| 135 &base64_profile)) { | 137 &base64_profile)) { |
| 136 if (!temp_profile_dir.CreateUniqueTempDir()) { | 138 if (!temp_profile_dir.CreateUniqueTempDir()) { |
| 137 response->SetError(new Error( | 139 response->SetError(new Error( |
| 138 kBadRequest, "Could not create temporary profile directory.")); | 140 kBadRequest, "Could not create temporary profile directory.")); |
| 139 return; | 141 return; |
| 140 } | 142 } |
| 141 FilePath temp_profile_zip( | 143 FilePath temp_profile_zip( |
| 142 temp_profile_dir.path().AppendASCII("profile.zip")); | 144 temp_profile_dir.path().AppendASCII("profile.zip")); |
| 143 std::string message; | 145 std::string message; |
| 144 if (!WriteBase64DataToFile(temp_profile_zip, base64_profile, &message)) { | 146 if (!WriteBase64DataToFile(temp_profile_zip, base64_profile, &message)) { |
| 145 response->SetError(new Error(kBadRequest, message)); | 147 response->SetError(new Error(kBadRequest, message)); |
| 146 return; | 148 return; |
| 147 } | 149 } |
| 148 | 150 |
| 149 browser_options.user_data_dir = | 151 temp_user_data_dir = temp_profile_dir.path().AppendASCII("user_data_dir"); |
| 150 temp_profile_dir.path().AppendASCII("user_data_dir"); | 152 if (!Unzip(temp_profile_zip, temp_user_data_dir)) { |
| 151 if (!Unzip(temp_profile_zip, browser_options.user_data_dir)) { | |
| 152 response->SetError(new Error( | 153 response->SetError(new Error( |
| 153 kBadRequest, "Could not unarchive provided user profile")); | 154 kBadRequest, "Could not unarchive provided user profile")); |
| 154 return; | 155 return; |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 | 158 |
| 158 const char* kExtensions = "chrome.extensions"; | 159 const char* kExtensions = "chrome.extensions"; |
| 159 ScopedTempDir extensions_dir; | 160 ScopedTempDir extensions_dir; |
| 160 ListValue* extensions_list = NULL; | 161 ListValue* extensions_list = NULL; |
| 161 std::vector<FilePath> extensions; | 162 std::vector<FilePath> extensions; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // difficult, and returning the hostname causes perf problems with the python | 226 // difficult, and returning the hostname causes perf problems with the python |
| 226 // bindings on Windows. | 227 // bindings on Windows. |
| 227 std::ostringstream stream; | 228 std::ostringstream stream; |
| 228 stream << SessionManager::GetInstance()->url_base() << "/session/" | 229 stream << SessionManager::GetInstance()->url_base() << "/session/" |
| 229 << session->id(); | 230 << session->id(); |
| 230 response->SetStatus(kSeeOther); | 231 response->SetStatus(kSeeOther); |
| 231 response->SetValue(Value::CreateStringValue(stream.str())); | 232 response->SetValue(Value::CreateStringValue(stream.str())); |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // namespace webdriver | 235 } // namespace webdriver |
| OLD | NEW |