diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 08:14:10 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 08:14:10 +0000 |
commit | ee16679f293ca27ce3d822a97efad7d3fa8a049e (patch) | |
tree | 4d531d3ecd47038f476a405372acfbdd20c493f3 /chrome/common/service_process_util_unittest.cc | |
parent | dce3a57799f52dc3edc0bee78c5e74fed362c365 (diff) | |
download | chromium_src-ee16679f293ca27ce3d822a97efad7d3fa8a049e.zip chromium_src-ee16679f293ca27ce3d822a97efad7d3fa8a049e.tar.gz chromium_src-ee16679f293ca27ce3d822a97efad7d3fa8a049e.tar.bz2 |
Add a new GetInstance() method for singleton classes under chrome/service and /net.
This is a small step towards making all singleton classes use the Singleton<T> pattern within their code and not expect the callers to know about it.
This CL includes files under chrome/service and /net with related files elsewhere.
Suggested files to focus for reviewers:
- @sanjeevr for chrome/common and chrome/service
- @ukai for net/websockets
- @agl for rest of net
BUG=65298
TEST=all existing tests should continue to pass.
Review URL: http://codereview.chromium.org/5634005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/service_process_util_unittest.cc')
-rw-r--r-- | chrome/common/service_process_util_unittest.cc | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/chrome/common/service_process_util_unittest.cc b/chrome/common/service_process_util_unittest.cc index 6000b5c..58b68e1 100644 --- a/chrome/common/service_process_util_unittest.cc +++ b/chrome/common/service_process_util_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/at_exit.h" #include "base/process_util.h" #include "base/string_util.h" #include "chrome/common/chrome_version_info.h" @@ -18,18 +19,28 @@ TEST(ServiceProcessUtilTest, ScopedVersionedName) { EXPECT_NE(std::string::npos, scoped_name.find(version_info.Version())); } +class ServiceProcessStateTest : public testing::Test { + private: + // This is used to release the ServiceProcessState singleton after each test. + base::ShadowingAtExitManager at_exit_manager_; +}; + #if defined(OS_WIN) // Singleton-ness is only implemented on Windows. -TEST(ServiceProcessStateTest, Singleton) { +// TODO(sanjeev): Rewrite this test to spawn a new process and test using the +// ServiceProcessState singleton across processes. +/* +TEST_F(ServiceProcessStateTest, Singleton) { ServiceProcessState state; EXPECT_TRUE(state.Initialize()); // The second instance should fail to Initialize. ServiceProcessState another_state; EXPECT_FALSE(another_state.Initialize()); } +*/ #endif // defined(OS_WIN) -TEST(ServiceProcessStateTest, ReadyState) { +TEST_F(ServiceProcessStateTest, ReadyState) { #if defined(OS_WIN) // On Posix, we use a lock file on disk to signal readiness. This lock file // could be lying around from previous crashes which could cause @@ -38,15 +49,15 @@ TEST(ServiceProcessStateTest, ReadyState) { // Posix, this check will only execute on Windows. EXPECT_FALSE(CheckServiceProcessReady()); #endif // defined(OS_WIN) - ServiceProcessState state; - EXPECT_TRUE(state.Initialize()); - state.SignalReady(NULL); + ServiceProcessState* state = ServiceProcessState::GetInstance(); + EXPECT_TRUE(state->Initialize()); + state->SignalReady(NULL); EXPECT_TRUE(CheckServiceProcessReady()); - state.SignalStopped(); + state->SignalStopped(); EXPECT_FALSE(CheckServiceProcessReady()); } -TEST(ServiceProcessStateTest, SharedMem) { +TEST_F(ServiceProcessStateTest, SharedMem) { #if defined(OS_WIN) // On Posix, named shared memory uses a file on disk. This file // could be lying around from previous crashes which could cause @@ -55,8 +66,8 @@ TEST(ServiceProcessStateTest, SharedMem) { // implementation on Posix, this check will only execute on Windows. EXPECT_EQ(0, GetServiceProcessPid()); #endif // defined(OS_WIN) - ServiceProcessState state; - EXPECT_TRUE(state.Initialize()); + ServiceProcessState* state = ServiceProcessState::GetInstance(); + EXPECT_TRUE(state->Initialize()); EXPECT_EQ(base::GetCurrentProcId(), GetServiceProcessPid()); } |