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