test_launcher_utils.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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/base/test_launcher_utils.h"
6
7#include "base/command_line.h"
8#include "base/environment.h"
9#include "base/logging.h"
10#include "base/memory/scoped_ptr.h"
11#include "base/path_service.h"
12#include "base/strings/string_number_conversions.h"
13#include "chrome/common/chrome_paths.h"
14#include "chrome/common/chrome_switches.h"
15#include "ui/gl/gl_switches.h"
16
17#if defined(USE_AURA)
18#include "ui/views/corewm/corewm_switches.h"
19#endif
20
21namespace test_launcher_utils {
22
23void PrepareBrowserCommandLineForTests(CommandLine* command_line) {
24  // Turn off tip loading for tests; see http://crbug.com/17725.
25  command_line->AppendSwitch(switches::kDisableWebResources);
26
27  // Turn off preconnects because they break the brittle python webserver;
28  // see http://crbug.com/60035.
29  command_line->AppendSwitch(switches::kDisablePreconnect);
30
31  // Don't show the first run ui.
32  command_line->AppendSwitch(switches::kNoFirstRun);
33
34  // No default browser check, it would create an info-bar (if we are not the
35  // default browser) that could conflicts with some tests expectations.
36  command_line->AppendSwitch(switches::kNoDefaultBrowserCheck);
37
38  // Enable info level logging to stderr by default so that we can see when
39  // bad stuff happens, but honor the flags specified from the command line.
40  if (!command_line->HasSwitch(switches::kEnableLogging))
41    command_line->AppendSwitchASCII(switches::kEnableLogging, "stderr");
42  if (!command_line->HasSwitch(switches::kLoggingLevel))
43    command_line->AppendSwitchASCII(switches::kLoggingLevel, "0");  // info
44
45  // Disable safebrowsing autoupdate.
46  command_line->AppendSwitch(switches::kSbDisableAutoUpdate);
47
48  // Don't install default apps.
49  command_line->AppendSwitch(switches::kDisableDefaultApps);
50
51  // Don't collect GPU info, load GPU blacklist, or schedule a GPU blacklist
52  // auto-update.
53  command_line->AppendSwitch(switches::kSkipGpuDataLoading);
54
55#if defined(USE_AURA)
56  // Disable window animations under Ash as the animations effect the
57  // coordinates returned and result in flake.
58  command_line->AppendSwitch(
59      views::corewm::switches::kWindowAnimationsDisabled);
60#endif
61
62#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
63  // Don't use the native password stores on Linux since they may
64  // prompt for additional UI during tests and cause test failures or
65  // timeouts.  Win, Mac and ChromeOS don't look at the kPasswordStore
66  // switch.
67  if (!command_line->HasSwitch(switches::kPasswordStore))
68    command_line->AppendSwitchASCII(switches::kPasswordStore, "basic");
69#endif
70
71#if defined(OS_MACOSX)
72  // Use mock keychain on mac to prevent blocking permissions dialogs.
73  command_line->AppendSwitch(switches::kUseMockKeychain);
74#endif
75
76  command_line->AppendSwitch(switches::kDisableComponentUpdate);
77}
78
79bool OverrideUserDataDir(const base::FilePath& user_data_dir) {
80  bool success = true;
81
82  // PathService::Override() is the best way to change the user data directory.
83  // This matches what is done in ChromeMain().
84  success = PathService::Override(chrome::DIR_USER_DATA, user_data_dir);
85
86#if defined(OS_POSIX) && !defined(OS_MACOSX)
87  // Make sure the cache directory is inside our clear profile. Otherwise
88  // the cache may contain data from earlier tests that could break the
89  // current test.
90  //
91  // Note: we use an environment variable here, because we have to pass the
92  // value to the child process. This is the simplest way to do it.
93  scoped_ptr<base::Environment> env(base::Environment::Create());
94  success = success && env->SetVar("XDG_CACHE_HOME", user_data_dir.value());
95#endif
96
97  return success;
98}
99
100bool OverrideGLImplementation(CommandLine* command_line,
101                              const std::string& implementation_name) {
102  if (command_line->HasSwitch(switches::kUseGL))
103    return false;
104
105  command_line->AppendSwitchASCII(switches::kUseGL, implementation_name);
106
107  return true;
108}
109
110}  // namespace test_launcher_utils
111