Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / base / test_launcher_utils.cc
blobbfc9d2bbf7d660374d68c0afed9d1140be3824bd
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.
5 #include "chrome/test/base/test_launcher_utils.h"
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 "components/os_crypt/os_crypt_switches.h"
17 #if defined(USE_AURA)
18 #include "ui/wm/core/wm_core_switches.h"
19 #endif
21 namespace test_launcher_utils {
23 void PrepareBrowserCommandLineForTests(base::CommandLine* command_line) {
24 // Turn off tip loading for tests; see http://crbug.com/17725.
25 command_line->AppendSwitch(switches::kDisableWebResources);
27 // Turn off preconnects because they break the brittle python webserver;
28 // see http://crbug.com/60035.
29 command_line->AppendSwitch(switches::kDisablePreconnect);
31 // Don't show the first run ui.
32 command_line->AppendSwitch(switches::kNoFirstRun);
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);
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
45 // Disable safebrowsing autoupdate.
46 command_line->AppendSwitch(switches::kSbDisableAutoUpdate);
48 // Don't install default apps.
49 command_line->AppendSwitch(switches::kDisableDefaultApps);
51 #if defined(USE_AURA)
52 // Disable window animations under Ash as the animations effect the
53 // coordinates returned and result in flake.
54 command_line->AppendSwitch(
55 wm::switches::kWindowAnimationsDisabled);
56 #endif
58 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
59 // Don't use the native password stores on Linux since they may
60 // prompt for additional UI during tests and cause test failures or
61 // timeouts. Win, Mac and ChromeOS don't look at the kPasswordStore
62 // switch.
63 if (!command_line->HasSwitch(switches::kPasswordStore))
64 command_line->AppendSwitchASCII(switches::kPasswordStore, "basic");
65 #endif
67 #if defined(OS_MACOSX)
68 // Use mock keychain on mac to prevent blocking permissions dialogs.
69 command_line->AppendSwitch(os_crypt::switches::kUseMockKeychain);
70 #endif
72 command_line->AppendSwitch(switches::kDisableComponentUpdate);
75 bool OverrideUserDataDir(const base::FilePath& user_data_dir) {
76 bool success = true;
78 // PathService::Override() is the best way to change the user data directory.
79 // This matches what is done in ChromeMain().
80 success = PathService::Override(chrome::DIR_USER_DATA, user_data_dir);
82 #if defined(OS_POSIX) && !defined(OS_MACOSX)
83 // Make sure the cache directory is inside our clear profile. Otherwise
84 // the cache may contain data from earlier tests that could break the
85 // current test.
87 // Note: we use an environment variable here, because we have to pass the
88 // value to the child process. This is the simplest way to do it.
89 scoped_ptr<base::Environment> env(base::Environment::Create());
90 success = success && env->SetVar("XDG_CACHE_HOME", user_data_dir.value());
91 #endif
93 return success;
96 } // namespace test_launcher_utils