| Index: chrome/test/webdriver/commands/create_session.cc
|
| diff --git a/chrome/test/webdriver/commands/create_session.cc b/chrome/test/webdriver/commands/create_session.cc
|
| index d6bab1c2c3aeee179f54d6009da0f96d0b2d6761..a4eb304b54416b56f1e97ed62f8dee161e99d00a 100644
|
| --- a/chrome/test/webdriver/commands/create_session.cc
|
| +++ b/chrome/test/webdriver/commands/create_session.cc
|
| @@ -29,58 +29,71 @@ CreateSession::~CreateSession() {}
|
| bool CreateSession::DoesPost() { return true; }
|
|
|
| void CreateSession::ExecutePost(Response* const response) {
|
| - DictionaryValue *added_options = NULL, *desiredCapabilities = NULL;
|
| - CommandLine options(CommandLine::NO_PROGRAM);
|
| - FilePath user_browser_exe;
|
| -
|
| - if (!GetDictionaryParameter("desiredCapabilities", &desiredCapabilities)) {
|
| - desiredCapabilities = NULL;
|
| + DictionaryValue *capabilities = NULL;
|
| + if (!GetDictionaryParameter("desiredCapabilities", &capabilities)) {
|
| + response->SetError(new Error(
|
| + kBadRequest, "Missing or invalid 'desiredCapabilities'"));
|
| + return;
|
| }
|
|
|
| - if ((desiredCapabilities != NULL) &&
|
| - desiredCapabilities->GetDictionary("chrome.customSwitches",
|
| - &added_options)) {
|
| - DictionaryValue::key_iterator i = added_options->begin_keys();
|
| - while (i != added_options->end_keys()) {
|
| - FilePath::StringType value;
|
| - if (!added_options->GetString(*i, &value)) {
|
| + CommandLine command_line_options(CommandLine::NO_PROGRAM);
|
| + ListValue* switches = NULL;
|
| + const char* kCustomSwitchesKey = "chrome.switches";
|
| + if (capabilities->GetListWithoutPathExpansion(kCustomSwitchesKey,
|
| + &switches)) {
|
| + for (size_t i = 0; i < switches->GetSize(); ++i) {
|
| + std::string switch_string;
|
| + if (!switches->GetString(i, &switch_string)) {
|
| response->SetError(new Error(
|
| - kBadRequest, "Invalid format for added options to browser"));
|
| + kBadRequest, "Custom switch is not a string"));
|
| return;
|
| - } else {
|
| - if (!value.empty()) {
|
| - options.AppendSwitchNative(*i, value);
|
| - } else {
|
| - options.AppendSwitch(*i);
|
| + }
|
| + size_t separator_index = switch_string.find("=");
|
| + if (separator_index != std::string::npos) {
|
| + CommandLine::StringType switch_string_native;
|
| + if (!switches->GetString(i, &switch_string_native)) {
|
| + response->SetError(new Error(
|
| + kBadRequest, "Custom switch is not a string"));
|
| + return;
|
| }
|
| + command_line_options.AppendSwitchNative(
|
| + switch_string.substr(0, separator_index),
|
| + switch_string_native.substr(separator_index + 1));
|
| + } else {
|
| + command_line_options.AppendSwitch(switch_string);
|
| }
|
| - ++i;
|
| }
|
| - FilePath::StringType path;
|
| - desiredCapabilities->GetString("chrome.binary", &path);
|
| - user_browser_exe = FilePath(path);
|
| + } else if (capabilities->HasKey(kCustomSwitchesKey)) {
|
| + response->SetError(new Error(
|
| + kBadRequest, "Custom switches must be a list"));
|
| + return;
|
| }
|
|
|
| + FilePath browser_exe;
|
| + FilePath::StringType path;
|
| + if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path))
|
| + browser_exe = FilePath(path);
|
| +
|
| // Session manages its own liftime, so do not call delete.
|
| Session* session = new Session();
|
| - Error* error = session->Init(user_browser_exe, options);
|
| + Error* error = session->Init(browser_exe, command_line_options);
|
| if (error) {
|
| response->SetError(error);
|
| return;
|
| }
|
|
|
| - if (desiredCapabilities != NULL) {
|
| - bool native_events_required = false;
|
| - if (desiredCapabilities->GetBoolean("chrome.nativeEvents",
|
| - &native_events_required)) {
|
| + bool native_events_required = false;
|
| + Value* native_events_value = NULL;
|
| + if (capabilities->GetWithoutPathExpansion(
|
| + "chrome.nativeEvents", &native_events_value)) {
|
| + if (native_events_value->GetAsBoolean(&native_events_required)) {
|
| session->set_use_native_events(native_events_required);
|
| }
|
| -
|
| - bool screenshot_on_error = false;
|
| - if (desiredCapabilities->GetBoolean("takeScreenshotOnError",
|
| - &screenshot_on_error)) {
|
| - session->set_screenshot_on_error(screenshot_on_error);
|
| - }
|
| + }
|
| + bool screenshot_on_error = false;
|
| + if (capabilities->GetBoolean(
|
| + "takeScreenshotOnError", &screenshot_on_error)) {
|
| + session->set_screenshot_on_error(screenshot_on_error);
|
| }
|
|
|
| VLOG(1) << "Created session " << session->id();
|
|
|