Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: chrome/test/webdriver/automation.cc

Issue 7523060: Let pyauto create an attached webdriver instance to manipulate web pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address nirnimesh' latest comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return true; 112 return true;
114 } 113 }
115 } 114 }
116 return false; 115 return false;
117 } 116 }
118 117
119 } // namespace 118 } // namespace
120 119
121 namespace webdriver { 120 namespace webdriver {
122 121
122 Automation::InitOptions::InitOptions() : cmdline(CommandLine::NO_PROGRAM) {
123 }
124
125 Automation::InitOptions::~InitOptions() {
126 }
127
123 Automation::Automation() {} 128 Automation::Automation() {}
124 129
125 Automation::~Automation() {} 130 Automation::~Automation() {}
126 131
127 void Automation::Init(const CommandLine& options, 132 void Automation::Init(const InitOptions& options, Error** error) {
128 const FilePath& user_data_dir, 133 CommandLine cmdline = options.cmdline;
129 Error** error) { 134 if (cmdline.GetProgram().empty()) {
130 FilePath browser_exe; 135 FilePath browser_exe;
131 if (!GetDefaultChromeExe(&browser_exe)) { 136 if (!GetDefaultChromeExe(&browser_exe)) {
132 *error = new Error(kUnknownError, "Could not find default Chrome binary"); 137 *error = new Error(kUnknownError, "Could not find default Chrome binary");
133 return; 138 return;
139 }
140 cmdline.SetProgram(browser_exe);
134 } 141 }
135 142 if (!file_util::PathExists(cmdline.GetProgram())) {
136 InitWithBrowserPath(browser_exe, user_data_dir, options, error);
137 }
138
139 void Automation::InitWithBrowserPath(const FilePath& browser_exe,
140 const FilePath& user_data_dir,
141 const CommandLine& options,
142 Error** error) {
143 if (!file_util::PathExists(browser_exe)) {
144 std::string message = base::StringPrintf( 143 std::string message = base::StringPrintf(
145 "Could not find Chrome binary at: %" PRFilePath, 144 "Could not find Chrome binary at: %" PRFilePath,
146 browser_exe.value().c_str()); 145 cmdline.GetProgram().value().c_str());
147 *error = new Error(kUnknownError, message); 146 *error = new Error(kUnknownError, message);
148 return; 147 return;
149 } 148 }
149 std::string chrome_details = base::StringPrintf(
150 "Using Chrome binary at: %" PRFilePath,
151 cmdline.GetProgram().value().c_str());
152 LOG(INFO) << chrome_details;
150 153
151 CommandLine command(browser_exe); 154 cmdline.AppendSwitch(switches::kDisableHangMonitor);
152 command.AppendSwitch(switches::kDisableHangMonitor); 155 cmdline.AppendSwitch(switches::kDisablePromptOnRepost);
153 command.AppendSwitch(switches::kDisablePromptOnRepost); 156 cmdline.AppendSwitch(switches::kDomAutomationController);
154 command.AppendSwitch(switches::kDomAutomationController); 157 cmdline.AppendSwitch(switches::kFullMemoryCrashReport);
155 command.AppendSwitch(switches::kFullMemoryCrashReport); 158 cmdline.AppendSwitch(switches::kNoDefaultBrowserCheck);
156 command.AppendSwitch(switches::kNoDefaultBrowserCheck); 159 cmdline.AppendSwitch(switches::kNoFirstRun);
157 command.AppendSwitch(switches::kNoFirstRun);
158 command.AppendSwitchASCII(switches::kTestType, "webdriver");
159 160
160 if (user_data_dir.empty()) 161 if (options.user_data_dir.empty())
161 command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL); 162 cmdline.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
162 163
163 command.AppendArguments(options, false); 164 if (options.channel_id.empty()) {
165 launcher_.reset(new AnonymousProxyLauncher(false));
166 } else {
167 NamedProxyLauncher::InitParams params;
168 params.launch_browser = false;
169 params.disconnect_on_failure = false;
170 params.wait_for_server_channel = false;
171 launcher_.reset(new NamedProxyLauncher(options.channel_id, params));
172 }
164 173
165 launcher_.reset(new AnonymousProxyLauncher(false));
166 ProxyLauncher::LaunchState launch_props = { 174 ProxyLauncher::LaunchState launch_props = {
167 false, // clear_profile 175 false, // clear_profile
168 user_data_dir, // template_user_data 176 options.user_data_dir, // template_user_data
169 base::Closure(), 177 base::Closure(),
170 command, 178 cmdline,
171 true, // include_testing_id 179 true, // include_testing_id
172 true // show_window 180 true // show_window
173 }; 181 };
174 182 if (!launcher_->InitializeConnection(launch_props, true)) {
175 std::string chrome_details = base::StringPrintf( 183 LOG(ERROR) << "Failed to initialize connection";
176 "Using Chrome binary at: %" PRFilePath,
177 browser_exe.value().c_str());
178 LOG(INFO) << chrome_details;
179
180 if (!launcher_->LaunchBrowserAndServer(launch_props, true)) {
181 *error = new Error( 184 *error = new Error(
182 kUnknownError, 185 kUnknownError,
183 "Unable to either launch or connect to Chrome. Please check that " 186 "Unable to either launch or connect to Chrome. Please check that "
184 "ChromeDriver is up-to-date. " + chrome_details); 187 "ChromeDriver is up-to-date. " + chrome_details);
185 return; 188 return;
186 } 189 }
187 190
188 launcher_->automation()->set_action_timeout_ms(base::kNoTimeout); 191 launcher_->automation()->set_action_timeout_ms(base::kNoTimeout);
189 LOG(INFO) << "Chrome launched successfully. Version: " 192 LOG(INFO) << "Chrome launched successfully. Version: "
190 << automation()->server_version(); 193 << automation()->server_version();
191 194
192 bool has_automation_version = false; 195 chrome_details += ", version (" + automation()->server_version() + ")";
193 *error = CompareVersion(730, 0, &has_automation_version); 196 int version = 0;
194 if (*error) 197 std::string error_msg;
198 if (!SendGetChromeDriverAutomationVersion(
199 automation(), &version, &error_msg)) {
200 *error = new Error(kUnknownError, error_msg + " " + chrome_details);
195 return; 201 return;
196 202 }
197 chrome_details += ", version (" + automation()->server_version() + ")"; 203 if (version > automation::kChromeDriverAutomationVersion) {
198 if (has_automation_version) { 204 *error = new Error(
199 int version = 0; 205 kUnknownError,
200 std::string error_msg; 206 "ChromeDriver is not compatible with this version of Chrome. " +
201 if (!SendGetChromeDriverAutomationVersion( 207 chrome_details);
202 automation(), &version, &error_msg)) { 208 return;
203 *error = new Error(kUnknownError, error_msg + " " + chrome_details);
204 return;
205 }
206 if (version > automation::kChromeDriverAutomationVersion) {
207 *error = new Error(
208 kUnknownError,
209 "ChromeDriver is not compatible with this version of Chrome. " +
210 chrome_details);
211 return;
212 }
213 } 209 }
214 } 210 }
215 211
216 void Automation::Terminate() { 212 void Automation::Terminate() {
217 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { 213 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) {
218 launcher_->QuitBrowser(); 214 launcher_->QuitBrowser();
219 } 215 }
220 } 216 }
221 217
222 void Automation::ExecuteScript(int tab_id, 218 void Automation::ExecuteScript(int tab_id,
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 768, 0, "Alerts are not supported for this version of Chrome"); 628 768, 0, "Alerts are not supported for this version of Chrome");
633 } 629 }
634 630
635 Error* Automation::CheckAdvancedInteractionsSupported() { 631 Error* Automation::CheckAdvancedInteractionsSupported() {
636 const char* message = 632 const char* message =
637 "Advanced user interactions are not supported for this version of Chrome"; 633 "Advanced user interactions are not supported for this version of Chrome";
638 return CheckVersion(750, 0, message); 634 return CheckVersion(750, 0, message);
639 } 635 }
640 636
641 } // namespace webdriver 637 } // namespace webdriver
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698