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

Unified Diff: chrome/browser/process_singleton_mac_unittest.cc

Issue 218883008: Use process_singleton_linux on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CreateUniqueTempDir is fine. DCHECK socket path length. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/process_singleton_mac_unittest.cc
diff --git a/chrome/browser/process_singleton_mac_unittest.cc b/chrome/browser/process_singleton_mac_unittest.cc
deleted file mode 100644
index b6a5b7b49bf3e55bcd87c130f28fd92eec2aa1d2..0000000000000000000000000000000000000000
--- a/chrome/browser/process_singleton_mac_unittest.cc
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright (c) 2012 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 <errno.h>
-#include <fcntl.h>
-#include <sys/file.h>
-
-#include "chrome/browser/process_singleton.h"
-
-#include "base/file_util.h"
-#include "base/files/scoped_file.h"
-#include "base/path_service.h"
-#include "base/posix/eintr_wrapper.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/test/base/testing_profile.h"
-#include "testing/platform_test.h"
-
-namespace {
-
-class ProcessSingletonMacTest : public PlatformTest {
- public:
- virtual void SetUp() {
- PlatformTest::SetUp();
-
- // Put the lock in a temporary directory. Doesn't need to be a
- // full profile to test this code.
- ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- lock_path_ = temp_dir_.path().Append(chrome::kSingletonLockFilename);
- }
-
- virtual void TearDown() {
- PlatformTest::TearDown();
-
- // Verify that the lock was released.
- EXPECT_FALSE(IsLocked());
- }
-
- // Return |true| if the file exists and is locked. Forces a failure
- // in the containing test in case of error condition.
- bool IsLocked() {
- base::ScopedFD fd(HANDLE_EINTR(open(lock_path_.value().c_str(), O_RDONLY)));
- if (!fd.is_valid()) {
- EXPECT_EQ(ENOENT, errno) << "Unexpected error opening lockfile.";
- return false;
- }
-
- int rc = HANDLE_EINTR(flock(fd.get(), LOCK_EX|LOCK_NB));
-
- // Got the lock, so it wasn't already locked. Close releases.
- if (rc != -1)
- return false;
-
- // Someone else has the lock.
- if (errno == EWOULDBLOCK)
- return true;
-
- EXPECT_EQ(EWOULDBLOCK, errno) << "Unexpected error acquiring lock.";
- return false;
- }
-
- base::ScopedTempDir temp_dir_;
- base::FilePath lock_path_;
-};
-
-// Test that the base case doesn't blow up.
-TEST_F(ProcessSingletonMacTest, Basic) {
- ProcessSingleton ps(temp_dir_.path(),
- ProcessSingleton::NotificationCallback());
- EXPECT_FALSE(IsLocked());
- EXPECT_TRUE(ps.Create());
- EXPECT_TRUE(IsLocked());
- ps.Cleanup();
- EXPECT_FALSE(IsLocked());
-}
-
-// The destructor should release the lock.
-TEST_F(ProcessSingletonMacTest, DestructorReleases) {
- EXPECT_FALSE(IsLocked());
- {
- ProcessSingleton ps(temp_dir_.path(),
- ProcessSingleton::NotificationCallback());
- EXPECT_TRUE(ps.Create());
- EXPECT_TRUE(IsLocked());
- }
- EXPECT_FALSE(IsLocked());
-}
-
-// Multiple singletons should interlock appropriately.
-TEST_F(ProcessSingletonMacTest, Interlock) {
- ProcessSingleton ps1(temp_dir_.path(),
- ProcessSingleton::NotificationCallback());
- ProcessSingleton ps2(temp_dir_.path(),
- ProcessSingleton::NotificationCallback());
-
- // Windows and Linux use a command-line flag to suppress this, but
- // it is on a sub-process so the scope is contained. Rather than
- // add additional API to process_singleton.h in an #ifdef, just tell
- // the reader what to expect and move on.
- LOG(ERROR) << "Expect two failures to obtain the lock.";
-
- // When |ps1| has the lock, |ps2| cannot get it.
- EXPECT_FALSE(IsLocked());
- EXPECT_TRUE(ps1.Create());
- EXPECT_TRUE(IsLocked());
- EXPECT_FALSE(ps2.Create());
- ps1.Cleanup();
-
- // And when |ps2| has the lock, |ps1| cannot get it.
- EXPECT_FALSE(IsLocked());
- EXPECT_TRUE(ps2.Create());
- EXPECT_TRUE(IsLocked());
- EXPECT_FALSE(ps1.Create());
- ps2.Cleanup();
- EXPECT_FALSE(IsLocked());
-}
-
-// Like |Interlock| test, but via |NotifyOtherProcessOrCreate()|.
-TEST_F(ProcessSingletonMacTest, NotifyOtherProcessOrCreate) {
- ProcessSingleton ps1(temp_dir_.path(),
- ProcessSingleton::NotificationCallback());
- ProcessSingleton ps2(temp_dir_.path(),
- ProcessSingleton::NotificationCallback());
-
- // Windows and Linux use a command-line flag to suppress this, but
- // it is on a sub-process so the scope is contained. Rather than
- // add additional API to process_singleton.h in an #ifdef, just tell
- // the reader what to expect and move on.
- LOG(ERROR) << "Expect two failures to obtain the lock.";
-
- // When |ps1| has the lock, |ps2| cannot get it.
- EXPECT_FALSE(IsLocked());
- EXPECT_EQ(
- ProcessSingleton::PROCESS_NONE,
- ps1.NotifyOtherProcessOrCreate());
- EXPECT_TRUE(IsLocked());
- EXPECT_EQ(
- ProcessSingleton::PROFILE_IN_USE,
- ps2.NotifyOtherProcessOrCreate());
- ps1.Cleanup();
-
- // And when |ps2| has the lock, |ps1| cannot get it.
- EXPECT_FALSE(IsLocked());
- EXPECT_EQ(
- ProcessSingleton::PROCESS_NONE,
- ps2.NotifyOtherProcessOrCreate());
- EXPECT_TRUE(IsLocked());
- EXPECT_EQ(
- ProcessSingleton::PROFILE_IN_USE,
- ps1.NotifyOtherProcessOrCreate());
- ps2.Cleanup();
- EXPECT_FALSE(IsLocked());
-}
-
-// TODO(shess): Test that the lock is released when the process dies.
-// DEATH_TEST? I don't know. If the code to communicate between
-// browser processes is ever written, this all would need to be tested
-// more like the other platforms, in which case it would be easy.
-
-} // namespace

Powered by Google App Engine
This is Rietveld 408576698