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/chrome_launcher_impl.h" | 5 #include "chrome/test/chromedriver/chrome_launcher_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/process.h" | 11 #include "base/process.h" |
12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/string_number_conversions.h" |
13 #include "chrome/test/chromedriver/chrome.h" | 14 #include "chrome/test/chromedriver/chrome.h" |
14 #include "chrome/test/chromedriver/chrome_finder.h" | 15 #include "chrome/test/chromedriver/chrome_finder.h" |
15 #include "chrome/test/chromedriver/chrome_impl.h" | 16 #include "chrome/test/chromedriver/chrome_impl.h" |
| 17 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
16 #include "chrome/test/chromedriver/status.h" | 18 #include "chrome/test/chromedriver/status.h" |
17 | 19 |
18 ChromeLauncherImpl::ChromeLauncherImpl() {} | 20 ChromeLauncherImpl::ChromeLauncherImpl(URLRequestContextGetter* context_getter) |
| 21 : context_getter_(context_getter) {} |
19 | 22 |
20 ChromeLauncherImpl::~ChromeLauncherImpl() {} | 23 ChromeLauncherImpl::~ChromeLauncherImpl() {} |
21 | 24 |
22 Status ChromeLauncherImpl::Launch( | 25 Status ChromeLauncherImpl::Launch( |
23 const FilePath& chrome_exe, | 26 const FilePath& chrome_exe, |
24 scoped_ptr<Chrome>* chrome) { | 27 scoped_ptr<Chrome>* chrome) { |
25 FilePath program = chrome_exe; | 28 FilePath program = chrome_exe; |
26 if (program.empty()) { | 29 if (program.empty()) { |
27 if (!FindChrome(&program)) | 30 if (!FindChrome(&program)) |
28 return Status(kUnknownError, "cannot find Chrome binary"); | 31 return Status(kUnknownError, "cannot find Chrome binary"); |
29 } | 32 } |
30 | 33 |
| 34 int port = 33081; |
31 CommandLine command(program); | 35 CommandLine command(program); |
| 36 command.AppendSwitchASCII("remote-debugging-port", base::IntToString(port)); |
| 37 command.AppendSwitch("no-first-run"); |
32 command.AppendSwitch("enable-logging"); | 38 command.AppendSwitch("enable-logging"); |
33 command.AppendSwitchASCII("logging-level", "1"); | 39 command.AppendSwitchASCII("logging-level", "1"); |
34 base::ScopedTempDir user_data_dir; | 40 base::ScopedTempDir user_data_dir; |
35 if (!user_data_dir.CreateUniqueTempDir()) | 41 if (!user_data_dir.CreateUniqueTempDir()) |
36 return Status(kUnknownError, "cannot create temp dir for user data dir"); | 42 return Status(kUnknownError, "cannot create temp dir for user data dir"); |
37 command.AppendSwitchPath("user-data-dir", user_data_dir.path()); | 43 command.AppendSwitchPath("user-data-dir", user_data_dir.path()); |
38 command.AppendArg("about:blank"); | 44 command.AppendArg("about:blank"); |
39 | 45 |
40 base::LaunchOptions options; | 46 base::LaunchOptions options; |
41 base::ProcessHandle process; | 47 base::ProcessHandle process; |
42 if (!base::LaunchProcess(command, options, &process)) | 48 if (!base::LaunchProcess(command, options, &process)) |
43 return Status(kUnknownError, "chrome failed to start"); | 49 return Status(kUnknownError, "chrome failed to start"); |
44 chrome->reset(new ChromeImpl(process, &user_data_dir)); | 50 scoped_ptr<ChromeImpl> chrome_impl(new ChromeImpl( |
45 | 51 process, context_getter_, &user_data_dir, port)); |
| 52 Status status = chrome_impl->Init(); |
| 53 if (status.IsError()) |
| 54 return status; |
| 55 chrome->reset(chrome_impl.release()); |
46 return Status(kOk); | 56 return Status(kOk); |
47 } | 57 } |
OLD | NEW |