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