#include "chrome/browser/process_singleton.h"
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/test_timeouts.h"
#include "base/test/thread_test_helper.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_task_environment.h"
#include "net/base/network_interfaces.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class ProcessSingletonPosixTest : public testing::Test { … };
}
TEST_F(ProcessSingletonPosixTest, CheckSocketFile) { … }
TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessSuccess) { … }
TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessFailure) { … }
TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessNoSuicide) { … }
TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessHostChanged) { … }
TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessDifferingHost) { … }
TEST_F(ProcessSingletonPosixTest,
NotifyOtherProcessDifferingHost_UnlockedProfileBeforeKill) { … }
TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessOrCreate_DifferingHost) { … }
TEST_F(ProcessSingletonPosixTest, CreateFailsWithExistingBrowser) { … }
TEST_F(ProcessSingletonPosixTest, CreateChecksCompatibilitySocket) { … }
TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessOrCreate_BadCookie) { … }
TEST_F(ProcessSingletonPosixTest, IgnoreSocketSymlinkWithTooLongTarget) { … }
#if BUILDFLAG(IS_MAC)
TEST_F(ProcessSingletonPosixTest, CreateRespectsOldMacLock) {
std::unique_ptr<TestableProcessSingleton> process_singleton(
CreateProcessSingleton());
base::ScopedFD lock_fd(HANDLE_EINTR(
open(lock_path_.value().c_str(), O_RDWR | O_CREAT | O_EXLOCK, 0644)));
ASSERT_TRUE(lock_fd.is_valid());
EXPECT_FALSE(process_singleton->Create());
base::File::Info info;
EXPECT_TRUE(base::GetFileInfo(lock_path_, &info));
EXPECT_FALSE(info.is_directory);
EXPECT_FALSE(info.is_symbolic_link);
}
TEST_F(ProcessSingletonPosixTest, CreateReplacesOldMacLock) {
std::unique_ptr<TestableProcessSingleton> process_singleton(
CreateProcessSingleton());
EXPECT_TRUE(base::WriteFile(lock_path_, std::string_view()));
EXPECT_TRUE(process_singleton->Create());
VerifyFiles();
}
#endif