OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chrome_test_suite.h" | 5 #include "chrome/test/base/chrome_test_suite.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/metrics/stats_table.h" | 10 #include "base/metrics/stats_table.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chrome_content_browser_client.h" | 16 #include "chrome/browser/chrome_content_browser_client.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_content_client.h" | 18 #include "chrome/common/chrome_content_client.h" |
19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
22 #include "content/public/common/content_paths.h" | 22 #include "content/public/common/content_paths.h" |
23 #include "net/base/mock_host_resolver.h" | 23 #include "net/base/mock_host_resolver.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/base/ui_base_paths.h" | 28 #include "ui/base/ui_base_paths.h" |
29 #include "ui/gfx/test/gfx_test_utils.h" | |
30 | 29 |
31 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
32 #include "base/mac/mac_util.h" | 31 #include "base/mac/mac_util.h" |
33 #include "base/mac/scoped_nsautorelease_pool.h" | 32 #include "base/mac/scoped_nsautorelease_pool.h" |
34 #include "chrome/browser/chrome_browser_application_mac.h" | 33 #include "chrome/browser/chrome_browser_application_mac.h" |
35 #endif | 34 #endif |
36 | 35 |
37 #if defined(OS_POSIX) | 36 #if defined(OS_POSIX) |
38 #include "base/shared_memory.h" | 37 #include "base/shared_memory.h" |
39 #endif | 38 #endif |
40 | 39 |
| 40 #if defined(USE_WEBKIT_COMPOSITOR) |
| 41 #include "ui/gfx/compositor/compositor_setup.h" |
| 42 #else |
| 43 #include "ui/gfx/test/gfx_test_utils.h" |
| 44 #endif |
| 45 |
41 namespace { | 46 namespace { |
42 | 47 |
43 void RemoveSharedMemoryFile(const std::string& filename) { | 48 void RemoveSharedMemoryFile(const std::string& filename) { |
44 // Stats uses SharedMemory under the hood. On posix, this results in a file | 49 // Stats uses SharedMemory under the hood. On posix, this results in a file |
45 // on disk. | 50 // on disk. |
46 #if defined(OS_POSIX) | 51 #if defined(OS_POSIX) |
47 base::SharedMemory memory; | 52 base::SharedMemory memory; |
48 memory.Delete(filename); | 53 memory.Delete(filename); |
49 #endif | 54 #endif |
50 } | 55 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // Force unittests to run using en-US so if we test against string | 191 // Force unittests to run using en-US so if we test against string |
187 // output, it'll pass regardless of the system language. | 192 // output, it'll pass regardless of the system language. |
188 ResourceBundle::InitSharedInstance("en-US"); | 193 ResourceBundle::InitSharedInstance("en-US"); |
189 FilePath resources_pack_path; | 194 FilePath resources_pack_path; |
190 PathService::Get(base::DIR_MODULE, &resources_pack_path); | 195 PathService::Get(base::DIR_MODULE, &resources_pack_path); |
191 resources_pack_path = | 196 resources_pack_path = |
192 resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); | 197 resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); |
193 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); | 198 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); |
194 | 199 |
195 // Mock out the compositor on platforms that use it. | 200 // Mock out the compositor on platforms that use it. |
| 201 #if defined(USE_WEBKIT_COMPOSITOR) |
| 202 ui::SetupTestCompositor(); |
| 203 #else |
196 ui::gfx_test_utils::SetupTestCompositor(); | 204 ui::gfx_test_utils::SetupTestCompositor(); |
| 205 #endif |
197 | 206 |
198 stats_filename_ = base::StringPrintf("unit_tests-%d", | 207 stats_filename_ = base::StringPrintf("unit_tests-%d", |
199 base::GetCurrentProcId()); | 208 base::GetCurrentProcId()); |
200 RemoveSharedMemoryFile(stats_filename_); | 209 RemoveSharedMemoryFile(stats_filename_); |
201 stats_table_.reset(new base::StatsTable(stats_filename_, 20, 200)); | 210 stats_table_.reset(new base::StatsTable(stats_filename_, 20, 200)); |
202 base::StatsTable::set_current(stats_table_.get()); | 211 base::StatsTable::set_current(stats_table_.get()); |
203 | 212 |
204 testing::TestEventListeners& listeners = | 213 testing::TestEventListeners& listeners = |
205 testing::UnitTest::GetInstance()->listeners(); | 214 testing::UnitTest::GetInstance()->listeners(); |
206 listeners.Append(new ChromeTestSuiteInitializer); | 215 listeners.Append(new ChromeTestSuiteInitializer); |
207 } | 216 } |
208 | 217 |
209 void ChromeTestSuite::Shutdown() { | 218 void ChromeTestSuite::Shutdown() { |
210 ResourceBundle::CleanupSharedInstance(); | 219 ResourceBundle::CleanupSharedInstance(); |
211 | 220 |
212 #if defined(OS_MACOSX) | 221 #if defined(OS_MACOSX) |
213 base::mac::SetOverrideAppBundle(NULL); | 222 base::mac::SetOverrideAppBundle(NULL); |
214 #endif | 223 #endif |
215 | 224 |
216 base::StatsTable::set_current(NULL); | 225 base::StatsTable::set_current(NULL); |
217 stats_table_.reset(); | 226 stats_table_.reset(); |
218 RemoveSharedMemoryFile(stats_filename_); | 227 RemoveSharedMemoryFile(stats_filename_); |
219 | 228 |
220 base::TestSuite::Shutdown(); | 229 base::TestSuite::Shutdown(); |
221 } | 230 } |
OLD | NEW |