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

Unified Diff: chrome/test/chromedriver/chrome_launcher.cc

Issue 23643005: [chromedriver] Load the automation extension as a component extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/chromedriver/chrome_launcher.h ('k') | chrome/test/chromedriver/chrome_launcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/chrome_launcher.cc
diff --git a/chrome/test/chromedriver/chrome_launcher.cc b/chrome/test/chromedriver/chrome_launcher.cc
index c9b0e4905498fa990e784c7fac4fc5c350f153d0..64f21c9345ea2fa4bdc5fb4a00075419466a2bd2 100644
--- a/chrome/test/chromedriver/chrome_launcher.cc
+++ b/chrome/test/chromedriver/chrome_launcher.cc
@@ -44,9 +44,6 @@
namespace {
-const char* kCommonSwitches[] = {
- "ignore-certificate-errors", "metrics-recording-only"};
-
Status UnpackAutomationExtension(const base::FilePath& temp_dir,
base::FilePath* automation_extension) {
std::string decoded_extension;
@@ -68,62 +65,44 @@ Status UnpackAutomationExtension(const base::FilePath& temp_dir,
return Status(kOk);
}
-void AddSwitches(CommandLine* command,
- const char* switches[],
- size_t switch_count,
- const std::set<std::string>& exclude_switches) {
- for (size_t i = 0; i < switch_count; ++i) {
- if (exclude_switches.find(switches[i]) == exclude_switches.end())
- command->AppendSwitch(switches[i]);
- }
-}
-
Status PrepareCommandLine(int port,
const Capabilities& capabilities,
+ Switches* switches,
CommandLine* prepared_command,
base::ScopedTempDir* user_data_dir,
base::ScopedTempDir* extension_dir,
std::vector<std::string>* extension_bg_pages) {
- CommandLine command = capabilities.command;
- base::FilePath program = command.GetProgram();
+ base::FilePath program = capabilities.binary;
if (program.empty()) {
if (!FindChrome(&program))
return Status(kUnknownError, "cannot find Chrome binary");
- command.SetProgram(program);
} else if (!base::PathExists(program)) {
return Status(kUnknownError,
base::StringPrintf("no chrome binary at %" PRFilePath,
program.value().c_str()));
}
-
- const char* excludable_switches[] = {
- "disable-hang-monitor",
- "disable-prompt-on-repost",
- "full-memory-crash-report",
- "no-first-run",
- "disable-background-networking",
- // TODO(chrisgao): Add "disable-sync" when chrome 30- is not supported.
- // For chrome 30-, it leads to crash when opening chrome://settings.
- "disable-web-resources",
- "safebrowsing-disable-auto-update",
- "safebrowsing-disable-download-protection",
- "disable-client-side-phishing-detection",
- "disable-component-update",
- "disable-default-apps",
- };
-
- AddSwitches(&command, excludable_switches, arraysize(excludable_switches),
- capabilities.exclude_switches);
- AddSwitches(&command, kCommonSwitches, arraysize(kCommonSwitches),
- capabilities.exclude_switches);
-
- command.AppendSwitch("enable-logging");
- command.AppendSwitchASCII("logging-level", "1");
- command.AppendSwitchASCII("password-store", "basic");
- command.AppendSwitch("use-mock-keychain");
- command.AppendSwitchASCII("remote-debugging-port", base::IntToString(port));
-
- if (!command.HasSwitch("user-data-dir")) {
+ CommandLine command(program);
+
+ // TODO(chrisgao): Add "disable-sync" when chrome 30- is not supported.
+ // For chrome 30-, it leads to crash when opening chrome://settings.
+ switches->SetSwitch("disable-hang-monitor");
+ switches->SetSwitch("disable-prompt-on-repost");
+ switches->SetSwitch("full-memory-crash-report");
+ switches->SetSwitch("no-first-run");
+ switches->SetSwitch("disable-background-networking");
+ switches->SetSwitch("disable-web-resources");
+ switches->SetSwitch("safebrowsing-disable-auto-update");
+ switches->SetSwitch("safebrowsing-disable-download-protection");
+ switches->SetSwitch("disable-client-side-phishing-detection");
+ switches->SetSwitch("disable-component-update");
+ switches->SetSwitch("disable-default-apps");
+ switches->SetSwitch("enable-logging");
+ switches->SetSwitch("logging-level", "1");
+ switches->SetSwitch("password-store", "basic");
+ switches->SetSwitch("use-mock-keychain");
+ switches->SetSwitch("remote-debugging-port", base::IntToString(port));
+
+ if (!switches->HasSwitch("user-data-dir")) {
command.AppendArg("about:blank");
if (!user_data_dir->CreateUniqueTempDir())
return Status(kUnknownError, "cannot create temp dir for user data dir");
@@ -142,11 +121,13 @@ Status PrepareCommandLine(int port,
Status status = internal::ProcessExtensions(capabilities.extensions,
extension_dir->path(),
true,
- &command,
+ switches,
extension_bg_pages);
if (status.IsError())
return status;
+ switches->SetFromSwitches(capabilities.switches);
chrisgao (Use stgao instead) 2013/08/30 02:12:55 including excludeSwitches, automation-extension mi
+ switches->AppendToCommandLine(&command);
*prepared_command = command;
return Status(kOk);
}
@@ -190,11 +171,11 @@ Status LaunchExistingChromeSession(
Status status(kOk);
scoped_ptr<DevToolsHttpClient> devtools_client;
status = WaitForDevToolsAndCheckVersion(
- capabilities.use_existing_browser, context_getter, socket_factory, log,
+ capabilities.debugger_address, context_getter, socket_factory, log,
&devtools_client);
if (status.IsError()) {
return Status(kUnknownError, "cannot connect to chrome at " +
- capabilities.use_existing_browser.ToString(),
+ capabilities.debugger_address.ToString(),
status);
}
chrome->reset(new ChromeExistingImpl(devtools_client.Pass(),
@@ -209,6 +190,7 @@ Status LaunchDesktopChrome(
const SyncWebSocketFactory& socket_factory,
Log* log,
const Capabilities& capabilities,
+ Switches* switches,
ScopedVector<DevToolsEventListener>& devtools_event_listeners,
scoped_ptr<Chrome>* chrome) {
CommandLine command(CommandLine::NO_PROGRAM);
@@ -217,6 +199,7 @@ Status LaunchDesktopChrome(
std::vector<std::string> extension_bg_pages;
Status status = PrepareCommandLine(port,
capabilities,
+ switches,
&command,
&user_data_dir,
&extension_dir,
@@ -314,6 +297,7 @@ Status LaunchAndroidChrome(
const SyncWebSocketFactory& socket_factory,
Log* log,
const Capabilities& capabilities,
+ Switches* switches,
ScopedVector<DevToolsEventListener>& devtools_event_listeners,
DeviceManager* device_manager,
scoped_ptr<Chrome>* chrome) {
@@ -328,15 +312,12 @@ Status LaunchAndroidChrome(
if (!status.IsOk())
return status;
- std::string args(capabilities.android_args);
- for (size_t i = 0; i < arraysize(kCommonSwitches); i++)
- args += "--" + std::string(kCommonSwitches[i]) + " ";
- args += "--disable-fre --enable-remote-debugging";
-
+ switches->SetSwitch("disable-fre");
+ switches->SetSwitch("enable-remote-debugging");
status = device->StartApp(capabilities.android_package,
capabilities.android_activity,
capabilities.android_process,
- args, port);
+ switches->ToString(), port);
if (!status.IsOk()) {
device->StopApp();
return status;
@@ -376,14 +357,20 @@ Status LaunchChrome(
if (!FindOpenPort(&port))
return Status(kUnknownError, "failed to find an open port for Chrome");
+ Switches switches;
+ const char* kCommonSwitches[] = {
+ "ignore-certificate-errors", "metrics-recording-only"};
+ for (size_t i = 0; i < arraysize(kCommonSwitches); i++)
+ switches.SetSwitch(kCommonSwitches[i]);
+
if (capabilities.IsAndroid()) {
return LaunchAndroidChrome(
context_getter, port, socket_factory, log, capabilities,
- devtools_event_listeners, device_manager, chrome);
+ &switches, devtools_event_listeners, device_manager, chrome);
} else {
return LaunchDesktopChrome(
context_getter, port, socket_factory, log, capabilities,
- devtools_event_listeners, chrome);
+ &switches, devtools_event_listeners, chrome);
}
}
@@ -500,10 +487,20 @@ Status ProcessExtension(const std::string& extension,
return Status(kOk);
}
+void UpdateExtensionSwitch(Switches* switches,
+ const char name[],
+ const base::FilePath::StringType& extension) {
+ base::FilePath::StringType value = switches->GetSwitchValueNative(name);
+ if (value.length())
+ value += FILE_PATH_LITERAL(",");
+ value += extension;
+ switches->SetSwitch(name, value);
+}
+
Status ProcessExtensions(const std::vector<std::string>& extensions,
const base::FilePath& temp_dir,
bool include_automation_extension,
- CommandLine* command,
+ Switches* switches,
std::vector<std::string>* bg_pages) {
std::vector<std::string> bg_pages_tmp;
std::vector<base::FilePath::StringType> extension_paths;
@@ -527,9 +524,9 @@ Status ProcessExtensions(const std::vector<std::string>& extensions,
Status status = UnpackAutomationExtension(temp_dir, &automation_extension);
if (status.IsError())
return status;
- if (command->HasSwitch("disable-extensions")) {
- command->AppendSwitchNative("load-component-extension",
- automation_extension.value());
+ if (switches->HasSwitch("disable-extensions")) {
+ UpdateExtensionSwitch(switches, "load-component-extension",
+ automation_extension.value());
} else {
extension_paths.push_back(automation_extension.value());
}
@@ -538,7 +535,7 @@ Status ProcessExtensions(const std::vector<std::string>& extensions,
if (extension_paths.size()) {
base::FilePath::StringType extension_paths_value = JoinString(
extension_paths, FILE_PATH_LITERAL(','));
- command->AppendSwitchNative("load-extension", extension_paths_value);
+ UpdateExtensionSwitch(switches, "load-extension", extension_paths_value);
}
bg_pages->swap(bg_pages_tmp);
return Status(kOk);
« no previous file with comments | « chrome/test/chromedriver/chrome_launcher.h ('k') | chrome/test/chromedriver/chrome_launcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698