summaryrefslogtreecommitdiffstats
path: root/chrome/browser/process_singleton_linux_uitest.cc
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-21 01:18:37 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-21 01:18:37 +0000
commit9f20a6d0e6153489efe035c860f249c7cbc28890 (patch)
tree27fc986ae9f9600d12268ea043156048400712d8 /chrome/browser/process_singleton_linux_uitest.cc
parent0a1f310d964e67756c8316330ffb090048c9ae82 (diff)
downloadchromium_src-9f20a6d0e6153489efe035c860f249c7cbc28890.zip
chromium_src-9f20a6d0e6153489efe035c860f249c7cbc28890.tar.gz
chromium_src-9f20a6d0e6153489efe035c860f249c7cbc28890.tar.bz2
Make ProcessSingletonLinux check the hostname to avoid multiple uses of a profile over NFS.
In order to avoid the singleton socket filename from exceeding the max socket name length, the socket is just named "SingletonSocket" and a new file "SingletonLock" is used for the hostname&pid. BUG=17549 TEST=see bug Review URL: http://codereview.chromium.org/174041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23930 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton_linux_uitest.cc')
-rw-r--r--chrome/browser/process_singleton_linux_uitest.cc88
1 files changed, 67 insertions, 21 deletions
diff --git a/chrome/browser/process_singleton_linux_uitest.cc b/chrome/browser/process_singleton_linux_uitest.cc
index 07220f6..7f2b90c 100644
--- a/chrome/browser/process_singleton_linux_uitest.cc
+++ b/chrome/browser/process_singleton_linux_uitest.cc
@@ -11,6 +11,7 @@
#include <vector>
#include <string>
+#include "base/eintr_wrapper.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/string_util.h"
@@ -24,18 +25,30 @@
#include "testing/gtest/include/gtest/gtest.h"
class ProcessSingletonLinuxTest : public UITest {
+ public:
+ virtual void SetUp() {
+ UITest::SetUp();
+ old_argv_ = CommandLine::ForCurrentProcess()->argv();
+ }
+
+ virtual void TearDown() {
+ if (!old_argv_.empty()) {
+ CommandLine::Reset();
+ CommandLine::Init(old_argv_);
+ }
+ UITest::TearDown();
+ }
+
protected:
// A helper method to call ProcessSingleton::NotifyOtherProcess().
// |url| will be added to CommandLine for current process, so that it can be
// sent to browser process by ProcessSingleton::NotifyOtherProcess().
- void NotifyOtherProcess(const std::string& url, bool expect_result) {
+ ProcessSingleton::NotifyResult NotifyOtherProcess(const std::string& url) {
FilePath user_data_dir;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- std::vector<std::string> old_argv =
- CommandLine::ForCurrentProcess()->argv();
std::vector<std::string> argv;
- argv.push_back(old_argv[0]);
+ argv.push_back(old_argv_[0]);
argv.push_back(url);
CommandLine::Reset();
@@ -43,11 +56,10 @@ class ProcessSingletonLinuxTest : public UITest {
ProcessSingleton process_singleton(user_data_dir);
- if (expect_result)
- EXPECT_TRUE(process_singleton.NotifyOtherProcess());
- else
- EXPECT_FALSE(process_singleton.NotifyOtherProcess());
+ return process_singleton.NotifyOtherProcess();
}
+
+ std::vector<std::string> old_argv_;
};
// Test if the socket file and symbol link created by ProcessSingletonLinux
@@ -55,21 +67,22 @@ class ProcessSingletonLinuxTest : public UITest {
// initiated by UITest. So we just test against this existing object.
TEST_F(ProcessSingletonLinuxTest, CheckSocketFile) {
FilePath user_data_dir;
- FilePath path;
+ FilePath socket_path;
+ FilePath lock_path;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- path = user_data_dir.Append(chrome::kSingletonSocketFilename);
+ socket_path = user_data_dir.Append(chrome::kSingletonSocketFilename);
+ lock_path = user_data_dir.Append(chrome::kSingletonLockFilename);
struct stat statbuf;
- ASSERT_EQ(0, lstat(path.value().c_str(), &statbuf));
+ ASSERT_EQ(0, lstat(lock_path.value().c_str(), &statbuf));
ASSERT_TRUE(S_ISLNK(statbuf.st_mode));
char buf[PATH_MAX + 1];
- ssize_t len = readlink(path.value().c_str(), buf, PATH_MAX);
+ ssize_t len = readlink(lock_path.value().c_str(), buf, PATH_MAX);
ASSERT_GT(len, 0);
buf[len] = '\0';
- path = user_data_dir.Append(buf);
- ASSERT_EQ(0, lstat(path.value().c_str(), &statbuf));
+ ASSERT_EQ(0, lstat(socket_path.value().c_str(), &statbuf));
ASSERT_TRUE(S_ISSOCK(statbuf.st_mode));
}
@@ -79,7 +92,7 @@ TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessSuccess) {
std::string url("about:blank");
int original_tab_count = GetTabCount();
- NotifyOtherProcess(url, true);
+ EXPECT_EQ(ProcessSingleton::PROCESS_NOTIFIED, NotifyOtherProcess(url));
EXPECT_EQ(original_tab_count + 1, GetTabCount());
EXPECT_EQ(url, GetActiveTabURL().spec());
}
@@ -88,21 +101,54 @@ TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessSuccess) {
TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessFailure) {
base::ProcessId pid = ChromeBrowserProcessId(user_data_dir());
- ASSERT_GT(pid, 1);
+ ASSERT_GE(pid, 1);
// Block the browser process, then it'll be killed by
// ProcessSingleton::NotifyOtherProcess().
kill(pid, SIGSTOP);
- // Wait for a while to make sure the browser process is actually stopped.
+ // Wait to make sure the browser process is actually stopped.
// It's necessary when running with valgrind.
- sleep(1);
+ HANDLE_EINTR(waitpid(pid, 0, WUNTRACED));
std::string url("about:blank");
- NotifyOtherProcess(url, false);
+ EXPECT_EQ(ProcessSingleton::PROCESS_NONE, NotifyOtherProcess(url));
// Wait for a while to make sure the browser process is actually killed.
- sleep(1);
+ EXPECT_FALSE(CrashAwareSleep(1000));
+}
- EXPECT_FALSE(IsBrowserRunning());
+// Test that we can still notify a process on the same host even after the
+// hostname changed.
+TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessHostChanged) {
+ FilePath lock_path = user_data_dir().Append(chrome::kSingletonLockFilename);
+ EXPECT_EQ(0, unlink(lock_path.value().c_str()));
+ EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path.value().c_str()));
+
+ int original_tab_count = GetTabCount();
+
+ std::string url("about:blank");
+ EXPECT_EQ(ProcessSingleton::PROCESS_NOTIFIED, NotifyOtherProcess(url));
+ EXPECT_EQ(original_tab_count + 1, GetTabCount());
+ EXPECT_EQ(url, GetActiveTabURL().spec());
+}
+
+// Test that we fail when lock says process is on another host and we can't
+// notify it over the socket.
+TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) {
+ base::ProcessId pid = ChromeBrowserProcessId(user_data_dir());
+
+ ASSERT_GE(pid, 1);
+
+ // Kill the browser process, so that it does not respond on the socket.
+ kill(pid, SIGKILL);
+ // Wait for a while to make sure the browser process is actually killed.
+ EXPECT_FALSE(CrashAwareSleep(1000));
+
+ FilePath lock_path = user_data_dir().Append(chrome::kSingletonLockFilename);
+ EXPECT_EQ(0, unlink(lock_path.value().c_str()));
+ EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path.value().c_str()));
+
+ std::string url("about:blank");
+ EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, NotifyOtherProcess(url));
}