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" | |
8 #include "base/file_util.h" | |
9 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
10 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
11 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/test/chromedriver/capabilities.h" |
12 #include "chrome/test/chromedriver/chrome/chrome.h" | 11 #include "chrome/test/chromedriver/chrome/chrome.h" |
13 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" | 12 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" |
14 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" | 13 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" |
15 #include "chrome/test/chromedriver/chrome/status.h" | 14 #include "chrome/test/chromedriver/chrome/status.h" |
16 #include "chrome/test/chromedriver/chrome/version.h" | 15 #include "chrome/test/chromedriver/chrome/version.h" |
17 #include "chrome/test/chromedriver/chrome/web_view.h" | 16 #include "chrome/test/chromedriver/chrome/web_view.h" |
18 #include "chrome/test/chromedriver/chrome_launcher.h" | 17 #include "chrome/test/chromedriver/chrome_launcher.h" |
19 #include "chrome/test/chromedriver/net/net_util.h" | 18 #include "chrome/test/chromedriver/net/net_util.h" |
20 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 19 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
21 #include "chrome/test/chromedriver/session.h" | 20 #include "chrome/test/chromedriver/session.h" |
(...skipping 29 matching lines...) Expand all Loading... |
51 scoped_ptr<base::Value>* out_value, | 50 scoped_ptr<base::Value>* out_value, |
52 std::string* out_session_id) { | 51 std::string* out_session_id) { |
53 int port; | 52 int port; |
54 if (!FindOpenPort(&port)) | 53 if (!FindOpenPort(&port)) |
55 return Status(kUnknownError, "failed to find an open port for Chrome"); | 54 return Status(kUnknownError, "failed to find an open port for Chrome"); |
56 | 55 |
57 const base::DictionaryValue* desired_caps; | 56 const base::DictionaryValue* desired_caps; |
58 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) | 57 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) |
59 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); | 58 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); |
60 | 59 |
| 60 Capabilities capabilities; |
| 61 Status status = capabilities.Parse(*desired_caps); |
| 62 if (status.IsError()) |
| 63 return status; |
| 64 |
61 scoped_ptr<Chrome> chrome; | 65 scoped_ptr<Chrome> chrome; |
62 std::string android_package; | 66 status = LaunchChrome(context_getter, port, socket_factory, |
63 if (desired_caps->GetString("chromeOptions.android_package", | 67 capabilities, &chrome); |
64 &android_package)) { | 68 if (status.IsError()) |
65 Status status = LaunchAndroidChrome( | 69 return status; |
66 context_getter, port, socket_factory, android_package, &chrome); | |
67 if (status.IsError()) | |
68 return status; | |
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()) | |
125 return status; | |
126 } | |
127 | 70 |
128 std::list<std::string> web_view_ids; | 71 std::list<std::string> web_view_ids; |
129 Status status = chrome->GetWebViewIds(&web_view_ids); | 72 status = chrome->GetWebViewIds(&web_view_ids); |
130 if (status.IsError() || web_view_ids.empty()) { | 73 if (status.IsError() || web_view_ids.empty()) { |
131 chrome->Quit(); | 74 chrome->Quit(); |
132 return status.IsError() ? status : | 75 return status.IsError() ? status : |
133 Status(kUnknownError, "unable to discover open window in chrome"); | 76 Status(kUnknownError, "unable to discover open window in chrome"); |
134 } | 77 } |
135 | 78 |
136 std::string new_id = session_id; | 79 std::string new_id = session_id; |
137 if (new_id.empty()) | 80 if (new_id.empty()) |
138 new_id = GenerateId(); | 81 new_id = GenerateId(); |
139 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); | 82 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); |
(...skipping 22 matching lines...) Expand all Loading... |
162 std::string* out_session_id) { | 105 std::string* out_session_id) { |
163 std::vector<std::string> session_ids; | 106 std::vector<std::string> session_ids; |
164 session_map->GetKeys(&session_ids); | 107 session_map->GetKeys(&session_ids); |
165 for (size_t i = 0; i < session_ids.size(); ++i) { | 108 for (size_t i = 0; i < session_ids.size(); ++i) { |
166 scoped_ptr<base::Value> unused_value; | 109 scoped_ptr<base::Value> unused_value; |
167 std::string unused_session_id; | 110 std::string unused_session_id; |
168 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); | 111 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); |
169 } | 112 } |
170 return Status(kOk); | 113 return Status(kOk); |
171 } | 114 } |
OLD | NEW |