OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/unit/chrome_test_suite.h" | 5 #include "chrome/test/unit/chrome_test_suite.h" |
6 | 6 |
7 #include "app/app_paths.h" | 7 #include "app/app_paths.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
11 #include "base/metrics/stats_table.h" | 11 #include "base/metrics/stats_table.h" |
12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.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 "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "chrome/test/testing_browser_process.h" | 19 #include "chrome/test/testing_browser_process.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 | 21 |
22 #if defined(OS_MACOSX) | 22 #if defined(OS_MACOSX) |
23 #include "base/mac_util.h" | 23 #include "base/mac/mac_util.h" |
24 #endif | 24 #endif |
25 | 25 |
26 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
27 #include "base/shared_memory.h" | 27 #include "base/shared_memory.h" |
28 #endif | 28 #endif |
29 | 29 |
30 static void RemoveSharedMemoryFile(const std::string& filename) { | 30 static void RemoveSharedMemoryFile(const std::string& filename) { |
31 // Stats uses SharedMemory under the hood. On posix, this results in a file | 31 // Stats uses SharedMemory under the hood. On posix, this results in a file |
32 // on disk. | 32 // on disk. |
33 #if defined(OS_POSIX) | 33 #if defined(OS_POSIX) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 if (!browser_dir_.empty()) { | 100 if (!browser_dir_.empty()) { |
101 PathService::Override(base::DIR_EXE, browser_dir_); | 101 PathService::Override(base::DIR_EXE, browser_dir_); |
102 PathService::Override(base::DIR_MODULE, browser_dir_); | 102 PathService::Override(base::DIR_MODULE, browser_dir_); |
103 } | 103 } |
104 | 104 |
105 #if defined(OS_MACOSX) | 105 #if defined(OS_MACOSX) |
106 // Look in the framework bundle for resources. | 106 // Look in the framework bundle for resources. |
107 FilePath path; | 107 FilePath path; |
108 PathService::Get(base::DIR_EXE, &path); | 108 PathService::Get(base::DIR_EXE, &path); |
109 path = path.Append(chrome::kFrameworkName); | 109 path = path.Append(chrome::kFrameworkName); |
110 mac_util::SetOverrideAppBundlePath(path); | 110 base::mac::SetOverrideAppBundlePath(path); |
111 #endif | 111 #endif |
112 | 112 |
113 // Force unittests to run using en-US so if we test against string | 113 // Force unittests to run using en-US so if we test against string |
114 // output, it'll pass regardless of the system language. | 114 // output, it'll pass regardless of the system language. |
115 ResourceBundle::InitSharedInstance("en-US"); | 115 ResourceBundle::InitSharedInstance("en-US"); |
116 | 116 |
117 // initialize the global StatsTable for unit_tests (make sure the file | 117 // initialize the global StatsTable for unit_tests (make sure the file |
118 // doesn't exist before opening it so the test gets a clean slate) | 118 // doesn't exist before opening it so the test gets a clean slate) |
119 stats_filename_ = "unit_tests"; | 119 stats_filename_ = "unit_tests"; |
120 std::string pid_string = StringPrintf("-%d", base::GetCurrentProcId()); | 120 std::string pid_string = StringPrintf("-%d", base::GetCurrentProcId()); |
121 stats_filename_ += pid_string; | 121 stats_filename_ += pid_string; |
122 RemoveSharedMemoryFile(stats_filename_); | 122 RemoveSharedMemoryFile(stats_filename_); |
123 stats_table_ = new base::StatsTable(stats_filename_, 20, 200); | 123 stats_table_ = new base::StatsTable(stats_filename_, 20, 200); |
124 base::StatsTable::set_current(stats_table_); | 124 base::StatsTable::set_current(stats_table_); |
125 } | 125 } |
126 | 126 |
127 void ChromeTestSuite::Shutdown() { | 127 void ChromeTestSuite::Shutdown() { |
128 ResourceBundle::CleanupSharedInstance(); | 128 ResourceBundle::CleanupSharedInstance(); |
129 | 129 |
130 #if defined(OS_MACOSX) | 130 #if defined(OS_MACOSX) |
131 mac_util::SetOverrideAppBundle(NULL); | 131 base::mac::SetOverrideAppBundle(NULL); |
132 #endif | 132 #endif |
133 | 133 |
134 delete g_browser_process; | 134 delete g_browser_process; |
135 g_browser_process = NULL; | 135 g_browser_process = NULL; |
136 | 136 |
137 // Tear down shared StatsTable; prevents unit_tests from leaking it. | 137 // Tear down shared StatsTable; prevents unit_tests from leaking it. |
138 base::StatsTable::set_current(NULL); | 138 base::StatsTable::set_current(NULL); |
139 delete stats_table_; | 139 delete stats_table_; |
140 RemoveSharedMemoryFile(stats_filename_); | 140 RemoveSharedMemoryFile(stats_filename_); |
141 | 141 |
142 base::TestSuite::Shutdown(); | 142 base::TestSuite::Shutdown(); |
143 } | 143 } |
OLD | NEW |