diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 20:27:04 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 20:27:04 +0000 |
commit | 146354945e1fb1a915ecb009c6732e0e28db9adc (patch) | |
tree | 248ec50922622796c7df09720b30c3f4ad6d2fa6 /chrome/common/service_process_util_unittest.cc | |
parent | 6da080717a2ef41e6292090427386d9079e73a59 (diff) | |
download | chromium_src-146354945e1fb1a915ecb009c6732e0e28db9adc.zip chromium_src-146354945e1fb1a915ecb009c6732e0e28db9adc.tar.gz chromium_src-146354945e1fb1a915ecb009c6732e0e28db9adc.tar.bz2 |
Spilt code in service_process_utils.cc into separate files for Windows and Posix. Added unit-tests for this file. Also created a ServiceProcessState class that manages global state for the service process.
BUG=None
TEST=Unit-tests, cloud print proxy.
Review URL: http://codereview.chromium.org/3745001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62448 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 | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/chrome/common/service_process_util_unittest.cc b/chrome/common/service_process_util_unittest.cc new file mode 100644 index 0000000..6000b5c --- /dev/null +++ b/chrome/common/service_process_util_unittest.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/process_util.h" +#include "base/string_util.h" +#include "chrome/common/chrome_version_info.h" +#include "chrome/common/service_process_util.h" +#include "testing/gtest/include/gtest/gtest.h" + + +TEST(ServiceProcessUtilTest, ScopedVersionedName) { + std::string test_str = "test"; + std::string scoped_name = GetServiceProcessScopedVersionedName(test_str); + chrome::VersionInfo version_info; + DCHECK(version_info.is_valid()); + EXPECT_TRUE(EndsWith(scoped_name, test_str, true)); + EXPECT_NE(std::string::npos, scoped_name.find(version_info.Version())); +} + +#if defined(OS_WIN) +// Singleton-ness is only implemented on Windows. +TEST(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) { +#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 + // CheckServiceProcessReady to lie. On Windows, we use a named event so we + // don't have this issue. Until we have a more stable signalling mechanism on + // Posix, this check will only execute on Windows. + EXPECT_FALSE(CheckServiceProcessReady()); +#endif // defined(OS_WIN) + ServiceProcessState state; + EXPECT_TRUE(state.Initialize()); + state.SignalReady(NULL); + EXPECT_TRUE(CheckServiceProcessReady()); + state.SignalStopped(); + EXPECT_FALSE(CheckServiceProcessReady()); +} + +TEST(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 + // GetServiceProcessPid to lie. On Windows, we use a named event so we + // don't have this issue. Until we have a more stable shared memory + // implementation on Posix, this check will only execute on Windows. + EXPECT_EQ(0, GetServiceProcessPid()); +#endif // defined(OS_WIN) + ServiceProcessState state; + EXPECT_TRUE(state.Initialize()); + EXPECT_EQ(base::GetCurrentProcId(), GetServiceProcessPid()); +} + |