OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/test_launcher_utils.h" | 5 #include "chrome/test/base/test_launcher_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "components/os_crypt/os_crypt_switches.h" | 18 #include "components/os_crypt/os_crypt_switches.h" |
19 #include "components/safe_browsing/common/safebrowsing_switches.h" | 19 #include "components/safe_browsing/common/safebrowsing_switches.h" |
20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
21 | 21 |
22 #if defined(USE_AURA) | 22 #if defined(USE_AURA) |
23 #include "ui/wm/core/wm_core_switches.h" | 23 #include "ui/wm/core/wm_core_switches.h" |
24 #endif | 24 #endif |
25 | 25 |
26 namespace test_launcher_utils { | 26 namespace test_launcher_utils { |
27 | 27 |
28 void PrepareBrowserCommandLineForTests(base::CommandLine* command_line) { | 28 void PrepareBrowserCommandLineForTests(base::CommandLine* command_line) { |
29 // Turn off preconnects because they break the brittle python webserver; | |
30 // see http://crbug.com/60035. | |
31 command_line->AppendSwitchASCII(switches::kDisableFeatures, | |
32 "NetworkPrediction"); | |
33 | |
34 // Don't show the first run ui. | 29 // Don't show the first run ui. |
35 command_line->AppendSwitch(switches::kNoFirstRun); | 30 command_line->AppendSwitch(switches::kNoFirstRun); |
36 | 31 |
37 // No default browser check, it would create an info-bar (if we are not the | 32 // No default browser check, it would create an info-bar (if we are not the |
38 // default browser) that could conflicts with some tests expectations. | 33 // default browser) that could conflicts with some tests expectations. |
39 command_line->AppendSwitch(switches::kNoDefaultBrowserCheck); | 34 command_line->AppendSwitch(switches::kNoDefaultBrowserCheck); |
40 | 35 |
41 // Enable info level logging to stderr by default so that we can see when | 36 // Enable info level logging to stderr by default so that we can see when |
42 // bad stuff happens, but honor the flags specified from the command line. | 37 // bad stuff happens, but honor the flags specified from the command line. |
43 if (!command_line->HasSwitch(switches::kEnableLogging)) | 38 if (!command_line->HasSwitch(switches::kEnableLogging)) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 const base::CommandLine::SwitchMap& switch_map = | 76 const base::CommandLine::SwitchMap& switch_map = |
82 in_command_line.GetSwitches(); | 77 in_command_line.GetSwitches(); |
83 for (base::CommandLine::SwitchMap::const_iterator i = switch_map.begin(); | 78 for (base::CommandLine::SwitchMap::const_iterator i = switch_map.begin(); |
84 i != switch_map.end(); ++i) { | 79 i != switch_map.end(); ++i) { |
85 const std::string& switch_name = i->first; | 80 const std::string& switch_name = i->first; |
86 if (switch_name == switch_to_remove) | 81 if (switch_name == switch_to_remove) |
87 continue; | 82 continue; |
88 | 83 |
89 out_command_line->AppendSwitchNative(switch_name, i->second); | 84 out_command_line->AppendSwitchNative(switch_name, i->second); |
90 } | 85 } |
91 } | 86 } |
Ilya Sherman
2017/06/09 20:19:28
^^^ looks like what you are trying to implement in
chaopeng
2017/06/13 04:16:32
Yes, we should remove this method after.
| |
92 | 87 |
93 bool OverrideUserDataDir(const base::FilePath& user_data_dir) { | 88 bool OverrideUserDataDir(const base::FilePath& user_data_dir) { |
94 bool success = true; | 89 bool success = true; |
95 | 90 |
96 // PathService::Override() is the best way to change the user data directory. | 91 // PathService::Override() is the best way to change the user data directory. |
97 // This matches what is done in ChromeMain(). | 92 // This matches what is done in ChromeMain(). |
98 success = PathService::Override(chrome::DIR_USER_DATA, user_data_dir); | 93 success = PathService::Override(chrome::DIR_USER_DATA, user_data_dir); |
99 | 94 |
100 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 95 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
101 // Make sure the cache directory is inside our clear profile. Otherwise | 96 // Make sure the cache directory is inside our clear profile. Otherwise |
102 // the cache may contain data from earlier tests that could break the | 97 // the cache may contain data from earlier tests that could break the |
103 // current test. | 98 // current test. |
104 // | 99 // |
105 // Note: we use an environment variable here, because we have to pass the | 100 // Note: we use an environment variable here, because we have to pass the |
106 // value to the child process. This is the simplest way to do it. | 101 // value to the child process. This is the simplest way to do it. |
107 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 102 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
108 success = success && env->SetVar("XDG_CACHE_HOME", user_data_dir.value()); | 103 success = success && env->SetVar("XDG_CACHE_HOME", user_data_dir.value()); |
109 | 104 |
110 // Also make sure that the machine policy directory is inside the clear | 105 // Also make sure that the machine policy directory is inside the clear |
111 // profile. Otherwise the machine's policies could affect tests. | 106 // profile. Otherwise the machine's policies could affect tests. |
112 base::FilePath policy_files = user_data_dir.AppendASCII("policies"); | 107 base::FilePath policy_files = user_data_dir.AppendASCII("policies"); |
113 success = | 108 success = |
114 success && PathService::Override(chrome::DIR_POLICY_FILES, policy_files); | 109 success && PathService::Override(chrome::DIR_POLICY_FILES, policy_files); |
115 #endif | 110 #endif |
116 | 111 |
117 return success; | 112 return success; |
118 } | 113 } |
119 | 114 |
120 } // namespace test_launcher_utils | 115 } // namespace test_launcher_utils |
OLD | NEW |