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/automation.h" | 5 #include "chrome/test/webdriver/automation.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/command_line.h" | |
14 #include "base/environment.h" | 13 #include "base/environment.h" |
15 #include "base/file_path.h" | 14 #include "base/file_path.h" |
16 #include "base/file_util.h" | 15 #include "base/file_util.h" |
17 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
18 #include "base/logging.h" | 17 #include "base/logging.h" |
19 #include "base/path_service.h" | 18 #include "base/path_service.h" |
20 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
21 #include "base/string_split.h" | 20 #include "base/string_split.h" |
22 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
23 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return true; | 111 return true; |
113 } | 112 } |
114 } | 113 } |
115 return false; | 114 return false; |
116 } | 115 } |
117 | 116 |
118 } // namespace | 117 } // namespace |
119 | 118 |
120 namespace webdriver { | 119 namespace webdriver { |
121 | 120 |
| 121 Automation::InitOptions::InitOptions() : cmdline(CommandLine::NO_PROGRAM) { |
| 122 } |
| 123 |
| 124 Automation::InitOptions::~InitOptions() { |
| 125 } |
| 126 |
122 Automation::Automation() {} | 127 Automation::Automation() {} |
123 | 128 |
124 Automation::~Automation() {} | 129 Automation::~Automation() {} |
125 | 130 |
126 void Automation::Init(const CommandLine& options, | 131 void Automation::Init(const InitOptions& options, Error** error) { |
127 const FilePath& user_data_dir, | 132 CommandLine cmdline = options.cmdline; |
128 Error** error) { | 133 if (cmdline.GetProgram().empty()) { |
129 FilePath browser_exe; | 134 FilePath browser_exe; |
130 if (!GetDefaultChromeExe(&browser_exe)) { | 135 if (!GetDefaultChromeExe(&browser_exe)) { |
131 *error = new Error(kUnknownError, "Could not find default Chrome binary"); | 136 *error = new Error(kUnknownError, "Could not find default Chrome binary"); |
132 return; | 137 return; |
| 138 } |
| 139 cmdline.SetProgram(browser_exe); |
133 } | 140 } |
134 | 141 if (!file_util::PathExists(cmdline.GetProgram())) { |
135 InitWithBrowserPath(browser_exe, user_data_dir, options, error); | |
136 } | |
137 | |
138 void Automation::InitWithBrowserPath(const FilePath& browser_exe, | |
139 const FilePath& user_data_dir, | |
140 const CommandLine& options, | |
141 Error** error) { | |
142 if (!file_util::PathExists(browser_exe)) { | |
143 std::string message = base::StringPrintf( | 142 std::string message = base::StringPrintf( |
144 "Could not find Chrome binary at: %" PRFilePath, | 143 "Could not find Chrome binary at: %" PRFilePath, |
145 browser_exe.value().c_str()); | 144 cmdline.GetProgram().value().c_str()); |
146 *error = new Error(kUnknownError, message); | 145 *error = new Error(kUnknownError, message); |
147 return; | 146 return; |
148 } | 147 } |
| 148 std::string chrome_details = base::StringPrintf( |
| 149 "Using Chrome binary at: %" PRFilePath, |
| 150 cmdline.GetProgram().value().c_str()); |
| 151 LOG(INFO) << chrome_details; |
149 | 152 |
150 CommandLine command(browser_exe); | 153 cmdline.AppendSwitch(switches::kDisableHangMonitor); |
151 command.AppendSwitch(switches::kDisableHangMonitor); | 154 cmdline.AppendSwitch(switches::kDisablePromptOnRepost); |
152 command.AppendSwitch(switches::kDisablePromptOnRepost); | 155 cmdline.AppendSwitch(switches::kDomAutomationController); |
153 command.AppendSwitch(switches::kDomAutomationController); | 156 cmdline.AppendSwitch(switches::kFullMemoryCrashReport); |
154 command.AppendSwitch(switches::kFullMemoryCrashReport); | 157 cmdline.AppendSwitch(switches::kNoDefaultBrowserCheck); |
155 command.AppendSwitch(switches::kNoDefaultBrowserCheck); | 158 cmdline.AppendSwitch(switches::kNoFirstRun); |
156 command.AppendSwitch(switches::kNoFirstRun); | |
157 command.AppendSwitchASCII(switches::kTestType, "webdriver"); | |
158 | 159 |
159 if (user_data_dir.empty()) | 160 if (options.user_data_dir.empty()) |
160 command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL); | 161 cmdline.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL); |
161 | 162 |
162 command.AppendArguments(options, false); | 163 if (options.channel_id.empty()) { |
| 164 launcher_.reset(new AnonymousProxyLauncher(false)); |
| 165 } else { |
| 166 NamedProxyLauncher::InitParams params; |
| 167 params.launch_browser = false; |
| 168 params.disconnect_on_failure = false; |
| 169 params.wait_for_server_channel = false; |
| 170 launcher_.reset(new NamedProxyLauncher(options.channel_id, params)); |
| 171 } |
163 | 172 |
164 launcher_.reset(new AnonymousProxyLauncher(false)); | |
165 ProxyLauncher::LaunchState launch_props = { | 173 ProxyLauncher::LaunchState launch_props = { |
166 false, // clear_profile | 174 false, // clear_profile |
167 user_data_dir, // template_user_data | 175 options.user_data_dir, // template_user_data |
168 base::Closure(), | 176 base::Closure(), |
169 command, | 177 cmdline, |
170 true, // include_testing_id | 178 true, // include_testing_id |
171 true // show_window | 179 true // show_window |
172 }; | 180 }; |
173 | 181 if (!launcher_->InitializeConnection(launch_props, true)) { |
174 std::string chrome_details = base::StringPrintf( | 182 LOG(ERROR) << "Failed to initialize connection"; |
175 "Using Chrome binary at: %" PRFilePath, | |
176 browser_exe.value().c_str()); | |
177 LOG(INFO) << chrome_details; | |
178 | |
179 if (!launcher_->LaunchBrowserAndServer(launch_props, true)) { | |
180 *error = new Error( | 183 *error = new Error( |
181 kUnknownError, | 184 kUnknownError, |
182 "Unable to either launch or connect to Chrome. Please check that " | 185 "Unable to either launch or connect to Chrome. Please check that " |
183 "ChromeDriver is up-to-date. " + chrome_details); | 186 "ChromeDriver is up-to-date. " + chrome_details); |
184 return; | 187 return; |
185 } | 188 } |
186 | 189 |
187 launcher_->automation()->set_action_timeout_ms(base::kNoTimeout); | 190 launcher_->automation()->set_action_timeout_ms(base::kNoTimeout); |
188 LOG(INFO) << "Chrome launched successfully. Version: " | 191 LOG(INFO) << "Chrome launched successfully. Version: " |
189 << automation()->server_version(); | 192 << automation()->server_version(); |
190 | 193 |
191 bool has_automation_version = false; | 194 chrome_details += ", version (" + automation()->server_version() + ")"; |
192 *error = CompareVersion(730, 0, &has_automation_version); | 195 int version = 0; |
193 if (*error) | 196 std::string error_msg; |
| 197 if (!SendGetChromeDriverAutomationVersion( |
| 198 automation(), &version, &error_msg)) { |
| 199 *error = new Error(kUnknownError, error_msg + " " + chrome_details); |
194 return; | 200 return; |
195 | 201 } |
196 chrome_details += ", version (" + automation()->server_version() + ")"; | 202 if (version > automation::kChromeDriverAutomationVersion) { |
197 if (has_automation_version) { | 203 *error = new Error( |
198 int version = 0; | 204 kUnknownError, |
199 std::string error_msg; | 205 "ChromeDriver is not compatible with this version of Chrome. " + |
200 if (!SendGetChromeDriverAutomationVersion( | 206 chrome_details); |
201 automation(), &version, &error_msg)) { | 207 return; |
202 *error = new Error(kUnknownError, error_msg + " " + chrome_details); | |
203 return; | |
204 } | |
205 if (version > automation::kChromeDriverAutomationVersion) { | |
206 *error = new Error( | |
207 kUnknownError, | |
208 "ChromeDriver is not compatible with this version of Chrome. " + | |
209 chrome_details); | |
210 return; | |
211 } | |
212 } | 208 } |
213 } | 209 } |
214 | 210 |
215 void Automation::Terminate() { | 211 void Automation::Terminate() { |
216 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { | 212 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { |
217 launcher_->QuitBrowser(); | 213 launcher_->QuitBrowser(); |
218 } | 214 } |
219 } | 215 } |
220 | 216 |
221 void Automation::ExecuteScript(int tab_id, | 217 void Automation::ExecuteScript(int tab_id, |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 768, 0, "Alerts are not supported for this version of Chrome"); | 622 768, 0, "Alerts are not supported for this version of Chrome"); |
627 } | 623 } |
628 | 624 |
629 Error* Automation::CheckAdvancedInteractionsSupported() { | 625 Error* Automation::CheckAdvancedInteractionsSupported() { |
630 const char* message = | 626 const char* message = |
631 "Advanced user interactions are not supported for this version of Chrome"; | 627 "Advanced user interactions are not supported for this version of Chrome"; |
632 return CheckVersion(750, 0, message); | 628 return CheckVersion(750, 0, message); |
633 } | 629 } |
634 | 630 |
635 } // namespace webdriver | 631 } // namespace webdriver |
OLD | NEW |