| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromedriver/commands.h" | 5 #include "chrome/test/chromedriver/commands.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/test/chromedriver/capabilities_parser.h" |
| 12 #include "chrome/test/chromedriver/chrome/chrome.h" | 13 #include "chrome/test/chromedriver/chrome/chrome.h" |
| 13 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" | 14 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" |
| 14 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" | 15 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" |
| 15 #include "chrome/test/chromedriver/chrome/status.h" | 16 #include "chrome/test/chromedriver/chrome/status.h" |
| 16 #include "chrome/test/chromedriver/chrome/version.h" | 17 #include "chrome/test/chromedriver/chrome/version.h" |
| 17 #include "chrome/test/chromedriver/chrome/web_view.h" | 18 #include "chrome/test/chromedriver/chrome/web_view.h" |
| 18 #include "chrome/test/chromedriver/chrome_launcher.h" | 19 #include "chrome/test/chromedriver/chrome_launcher.h" |
| 19 #include "chrome/test/chromedriver/net/net_util.h" | 20 #include "chrome/test/chromedriver/net/net_util.h" |
| 20 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 21 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
| 21 #include "chrome/test/chromedriver/session.h" | 22 #include "chrome/test/chromedriver/session.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 51 scoped_ptr<base::Value>* out_value, | 52 scoped_ptr<base::Value>* out_value, |
| 52 std::string* out_session_id) { | 53 std::string* out_session_id) { |
| 53 int port; | 54 int port; |
| 54 if (!FindOpenPort(&port)) | 55 if (!FindOpenPort(&port)) |
| 55 return Status(kUnknownError, "failed to find an open port for Chrome"); | 56 return Status(kUnknownError, "failed to find an open port for Chrome"); |
| 56 | 57 |
| 57 const base::DictionaryValue* desired_caps; | 58 const base::DictionaryValue* desired_caps; |
| 58 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) | 59 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) |
| 59 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); | 60 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); |
| 60 | 61 |
| 61 scoped_ptr<Chrome> chrome; | 62 Capabilities capabilities; |
| 62 std::string android_package; | 63 const base::Value* chrome_options = NULL; |
| 63 if (desired_caps->GetString("chromeOptions.android_package", | 64 if (desired_caps->Get("chromeOptions", &chrome_options)) { |
| 64 &android_package)) { | 65 const base::DictionaryValue* chrome_options_dict = NULL; |
| 65 Status status = LaunchAndroidChrome( | 66 if (!chrome_options->GetAsDictionary(&chrome_options_dict)) |
| 66 context_getter, port, socket_factory, android_package, &chrome); | 67 return Status(kUnknownError, "'chromeOptions' must be a dictionary"); |
| 67 if (status.IsError()) | 68 Status status = capabilities.Parse(*chrome_options_dict, |
| 68 return status; | 69 base::Bind(&file_util::PathExists)); |
| 69 } else { | |
| 70 base::FilePath::StringType path_str; | |
| 71 base::FilePath chrome_exe; | |
| 72 if (desired_caps->GetString("chromeOptions.binary", &path_str)) { | |
| 73 chrome_exe = base::FilePath(path_str); | |
| 74 if (!file_util::PathExists(chrome_exe)) { | |
| 75 std::string message = base::StringPrintf( | |
| 76 "no chrome binary at %" PRFilePath, | |
| 77 path_str.c_str()); | |
| 78 return Status(kUnknownError, message); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 const base::Value* args = NULL; | |
| 83 const base::ListValue* args_list = NULL; | |
| 84 if (desired_caps->Get("chromeOptions.args", &args) && | |
| 85 !args->GetAsList(&args_list)) { | |
| 86 return Status(kUnknownError, | |
| 87 "command line arguments for chrome must be a list"); | |
| 88 } | |
| 89 | |
| 90 const base::Value* prefs = NULL; | |
| 91 const base::DictionaryValue* prefs_dict = NULL; | |
| 92 if (desired_caps->Get("chromeOptions.prefs", &prefs) && | |
| 93 !prefs->GetAsDictionary(&prefs_dict)) { | |
| 94 return Status(kUnknownError, "'prefs' must be a dictionary"); | |
| 95 } | |
| 96 | |
| 97 const base::Value* local_state = NULL; | |
| 98 const base::DictionaryValue* local_state_dict = NULL; | |
| 99 if (desired_caps->Get("chromeOptions.localState", &local_state) && | |
| 100 !prefs->GetAsDictionary(&prefs_dict)) { | |
| 101 return Status(kUnknownError, "'localState' must be a dictionary"); | |
| 102 } | |
| 103 | |
| 104 const base::Value* extensions = NULL; | |
| 105 const base::ListValue* extensions_list = NULL; | |
| 106 if (desired_caps->Get("chromeOptions.extensions", &extensions) | |
| 107 && !extensions->GetAsList(&extensions_list)) { | |
| 108 return Status(kUnknownError, | |
| 109 "chrome extensions must be a list"); | |
| 110 } | |
| 111 | |
| 112 const base::Value* log_path = NULL; | |
| 113 std::string chrome_log_path; | |
| 114 if (desired_caps->Get("chromeOptions.logPath", &log_path) && | |
| 115 !log_path->GetAsString(&chrome_log_path)) { | |
| 116 return Status(kUnknownError, | |
| 117 "chrome log path must be a string"); | |
| 118 } | |
| 119 | |
| 120 Status status = LaunchDesktopChrome( | |
| 121 context_getter, port, socket_factory, | |
| 122 chrome_exe, args_list, extensions_list, | |
| 123 prefs_dict, local_state_dict, chrome_log_path, &chrome); | |
| 124 if (status.IsError()) | 70 if (status.IsError()) |
| 125 return status; | 71 return status; |
| 126 } | 72 } |
| 127 | 73 |
| 74 scoped_ptr<Chrome> chrome; |
| 75 Status status = LaunchChrome(context_getter, port, socket_factory, |
| 76 capabilities, &chrome); |
| 77 if (status.IsError()) |
| 78 return status; |
| 79 |
| 128 std::list<std::string> web_view_ids; | 80 std::list<std::string> web_view_ids; |
| 129 Status status = chrome->GetWebViewIds(&web_view_ids); | 81 status = chrome->GetWebViewIds(&web_view_ids); |
| 130 if (status.IsError() || web_view_ids.empty()) { | 82 if (status.IsError() || web_view_ids.empty()) { |
| 131 chrome->Quit(); | 83 chrome->Quit(); |
| 132 return status.IsError() ? status : | 84 return status.IsError() ? status : |
| 133 Status(kUnknownError, "unable to discover open window in chrome"); | 85 Status(kUnknownError, "unable to discover open window in chrome"); |
| 134 } | 86 } |
| 135 | 87 |
| 136 std::string new_id = session_id; | 88 std::string new_id = session_id; |
| 137 if (new_id.empty()) | 89 if (new_id.empty()) |
| 138 new_id = GenerateId(); | 90 new_id = GenerateId(); |
| 139 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); | 91 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 162 std::string* out_session_id) { | 114 std::string* out_session_id) { |
| 163 std::vector<std::string> session_ids; | 115 std::vector<std::string> session_ids; |
| 164 session_map->GetKeys(&session_ids); | 116 session_map->GetKeys(&session_ids); |
| 165 for (size_t i = 0; i < session_ids.size(); ++i) { | 117 for (size_t i = 0; i < session_ids.size(); ++i) { |
| 166 scoped_ptr<base::Value> unused_value; | 118 scoped_ptr<base::Value> unused_value; |
| 167 std::string unused_session_id; | 119 std::string unused_session_id; |
| 168 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); | 120 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); |
| 169 } | 121 } |
| 170 return Status(kOk); | 122 return Status(kOk); |
| 171 } | 123 } |
| OLD | NEW |