test_launcher_utils.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 warning level logging so that we can see when bad stuff happens.
39  command_line->AppendSwitch(switches::kEnableLogging);
40  command_line->AppendSwitchASCII(switches::kLoggingLevel, "1");  // warning
41
42  // Disable safebrowsing autoupdate.
43  command_line->AppendSwitch(switches::kSbDisableAutoUpdate);
44
45  // Don't install default apps.
46  command_line->AppendSwitch(switches::kDisableDefaultApps);
47
48  // Don't collect GPU info, load GPU blacklist, or schedule a GPU blacklist
49  // auto-update.
50  command_line->AppendSwitch(switches::kSkipGpuDataLoading);
51
52#if defined(USE_AURA)
53  // Disable window animations under Ash as the animations effect the
54  // coordinates returned and result in flake.
55  command_line->AppendSwitch(
56      views::corewm::switches::kWindowAnimationsDisabled);
57#endif
58
59#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
60  // Don't use the native password stores on Linux since they may
61  // prompt for additional UI during tests and cause test failures or
62  // timeouts.  Win, Mac and ChromeOS don't look at the kPasswordStore
63  // switch.
64  if (!command_line->HasSwitch(switches::kPasswordStore))
65    command_line->AppendSwitchASCII(switches::kPasswordStore, "basic");
66#endif
67
68#if defined(OS_MACOSX)
69  // Use mock keychain on mac to prevent blocking permissions dialogs.
70  command_line->AppendSwitch(switches::kUseMockKeychain);
71#endif
72
73  command_line->AppendSwitch(switches::kDisableComponentUpdate);
74}
75
76bool OverrideUserDataDir(const base::FilePath& user_data_dir) {
77  bool success = true;
78
79  // PathService::Override() is the best way to change the user data directory.
80  // This matches what is done in ChromeMain().
81  success = PathService::Override(chrome::DIR_USER_DATA, user_data_dir);
82
83#if defined(OS_POSIX) && !defined(OS_MACOSX)
84  // Make sure the cache directory is inside our clear profile. Otherwise
85  // the cache may contain data from earlier tests that could break the
86  // current test.
87  //
88  // Note: we use an environment variable here, because we have to pass the
89  // value to the child process. This is the simplest way to do it.
90  scoped_ptr<base::Environment> env(base::Environment::Create());
91  success = success && env->SetVar("XDG_CACHE_HOME", user_data_dir.value());
92#endif
93
94  return success;
95}
96
97bool OverrideGLImplementation(CommandLine* command_line,
98                              const std::string& implementation_name) {
99  if (command_line->HasSwitch(switches::kUseGL))
100    return false;
101
102  command_line->AppendSwitchASCII(switches::kUseGL, implementation_name);
103
104  return true;
105}
106
107}  // namespace test_launcher_utils
108