| Index: chrome/test/chromedriver/chrome_launcher.cc
|
| diff --git a/chrome/test/chromedriver/chrome_launcher.cc b/chrome/test/chromedriver/chrome_launcher.cc
|
| index 36e2a1c345f646b7ae04c4a5e659b3ae25af9811..9cfbc3b558f2e0e350cd1c3879f4aa7aaeabd293 100644
|
| --- a/chrome/test/chromedriver/chrome_launcher.cc
|
| +++ b/chrome/test/chromedriver/chrome_launcher.cc
|
| @@ -43,9 +43,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;
|
| @@ -67,62 +64,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");
|
| @@ -141,11 +120,12 @@ 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->AppendToCommandLine(&command);
|
| *prepared_command = command;
|
| return Status(kOk);
|
| }
|
| @@ -206,6 +186,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);
|
| @@ -214,6 +195,7 @@ Status LaunchDesktopChrome(
|
| std::vector<std::string> extension_bg_pages;
|
| Status status = PrepareCommandLine(port,
|
| capabilities,
|
| + switches,
|
| &command,
|
| &user_data_dir,
|
| &extension_dir,
|
| @@ -311,6 +293,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) {
|
| @@ -325,15 +308,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;
|
| @@ -369,14 +349,23 @@ Status LaunchChrome(
|
| return LaunchExistingChromeSession(
|
| context_getter, capabilities.existing_browser_port, socket_factory,
|
| log, capabilities, devtools_event_listeners, chrome);
|
| - } else if (capabilities.IsAndroid()) {
|
| + }
|
| +
|
| +
|
| + Switches switches = capabilities.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);
|
| }
|
| }
|
|
|
| @@ -493,10 +482,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;
|
| @@ -520,9 +519,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());
|
| }
|
| @@ -531,7 +530,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);
|
|
|