Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/test/base/chrome_unit_test_suite.cc

Issue 224713017: Remove IPC dependency from base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit tests Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_unit_test_suite.h" 5 #include "chrome/test/base/chrome_unit_test_suite.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/process/process_handle.h" 8 #include "base/process/process_handle.h"
9 #include "base/metrics/stats_table.h" 9 #include "base/metrics/stats_table.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 18 matching lines...) Expand all
29 #include "extensions/common/extension_paths.h" 29 #include "extensions/common/extension_paths.h"
30 #include "ui/gl/gl_surface.h" 30 #include "ui/gl/gl_surface.h"
31 #endif 31 #endif
32 32
33 #if defined(OS_POSIX) 33 #if defined(OS_POSIX)
34 #include "base/memory/shared_memory.h" 34 #include "base/memory/shared_memory.h"
35 #endif 35 #endif
36 36
37 namespace { 37 namespace {
38 38
39 void RemoveSharedMemoryFile(const std::string& filename) {
40 // Stats uses SharedMemory under the hood. On posix, this results in a file
41 // on disk.
42 #if defined(OS_POSIX)
43 base::SharedMemory memory;
44 memory.Delete(filename);
45 #endif
46 }
47
48 // Creates a TestingBrowserProcess for each test. 39 // Creates a TestingBrowserProcess for each test.
49 class ChromeUnitTestSuiteInitializer : public testing::EmptyTestEventListener { 40 class ChromeUnitTestSuiteInitializer : public testing::EmptyTestEventListener {
50 public: 41 public:
51 ChromeUnitTestSuiteInitializer() {} 42 ChromeUnitTestSuiteInitializer() {}
52 virtual ~ChromeUnitTestSuiteInitializer() {} 43 virtual ~ChromeUnitTestSuiteInitializer() {}
53 44
54 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { 45 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
55 content_client_.reset(new ChromeContentClient); 46 content_client_.reset(new ChromeContentClient);
56 content::SetContentClient(content_client_.get()); 47 content::SetContentClient(content_client_.get());
57 // TODO(ios): Bring this back once ChromeContentBrowserClient is building. 48 // TODO(ios): Bring this back once ChromeContentBrowserClient is building.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // Add an additional listener to do the extra initialization for unit tests. 91 // Add an additional listener to do the extra initialization for unit tests.
101 // It will be started before the base class listeners and ended after the 92 // It will be started before the base class listeners and ended after the
102 // base class listeners. 93 // base class listeners.
103 testing::TestEventListeners& listeners = 94 testing::TestEventListeners& listeners =
104 testing::UnitTest::GetInstance()->listeners(); 95 testing::UnitTest::GetInstance()->listeners();
105 listeners.Append(new ChromeUnitTestSuiteInitializer); 96 listeners.Append(new ChromeUnitTestSuiteInitializer);
106 97
107 InitializeProviders(); 98 InitializeProviders();
108 RegisterInProcessThreads(); 99 RegisterInProcessThreads();
109 100
110 stats_filename_ = base::StringPrintf("unit_tests-%d", 101 // Create an anonymous stats table since we don't need to share between
111 base::GetCurrentProcId()); 102 // processes.
112 RemoveSharedMemoryFile(stats_filename_); 103 stats_table_.reset(
113 stats_table_.reset(new base::StatsTable(stats_filename_, 20, 200)); 104 new base::StatsTable(base::StatsTable::TableIdentifier(), 20, 200));
114 base::StatsTable::set_current(stats_table_.get()); 105 base::StatsTable::set_current(stats_table_.get());
115 106
116 ChromeTestSuite::Initialize(); 107 ChromeTestSuite::Initialize();
117 108
118 // This needs to run after ChromeTestSuite::Initialize which calls content's 109 // This needs to run after ChromeTestSuite::Initialize which calls content's
119 // intialization which calls base's which initializes ICU. 110 // intialization which calls base's which initializes ICU.
120 InitializeResourceBundle(); 111 InitializeResourceBundle();
121 } 112 }
122 113
123 void ChromeUnitTestSuite::Shutdown() { 114 void ChromeUnitTestSuite::Shutdown() {
124 ResourceBundle::CleanupSharedInstance(); 115 ResourceBundle::CleanupSharedInstance();
125 116
126 base::StatsTable::set_current(NULL); 117 base::StatsTable::set_current(NULL);
127 stats_table_.reset(); 118 stats_table_.reset();
128 RemoveSharedMemoryFile(stats_filename_);
129 119
130 ChromeTestSuite::Shutdown(); 120 ChromeTestSuite::Shutdown();
131 } 121 }
132 122
133 void ChromeUnitTestSuite::InitializeProviders() { 123 void ChromeUnitTestSuite::InitializeProviders() {
134 { 124 {
135 ChromeContentClient content_client; 125 ChromeContentClient content_client;
136 RegisterContentSchemes(&content_client); 126 RegisterContentSchemes(&content_client);
137 } 127 }
138 128
(...skipping 26 matching lines...) Expand all
165 #if defined(OS_MACOSX) && !defined(OS_IOS) 155 #if defined(OS_MACOSX) && !defined(OS_IOS)
166 PathService::Get(base::DIR_MODULE, &resources_pack_path); 156 PathService::Get(base::DIR_MODULE, &resources_pack_path);
167 resources_pack_path = 157 resources_pack_path =
168 resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); 158 resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak"));
169 #else 159 #else
170 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); 160 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
171 #endif 161 #endif
172 ResourceBundle::GetSharedInstance().AddDataPackFromPath( 162 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
173 resources_pack_path, ui::SCALE_FACTOR_NONE); 163 resources_pack_path, ui::SCALE_FACTOR_NONE);
174 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698