diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-28 22:22:44 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-28 22:22:44 +0000 |
commit | 4a44bc32d152f0583bb196339c2568351573e304 (patch) | |
tree | fc2513a618e59b3b620fd1f001acbce24e87611b /chrome/browser/process_singleton_linux_uitest.cc | |
parent | c8b59f972e2c4b6fa92dab4101e9ccf0a15c20b4 (diff) | |
download | chromium_src-4a44bc32d152f0583bb196339c2568351573e304.zip chromium_src-4a44bc32d152f0583bb196339c2568351573e304.tar.gz chromium_src-4a44bc32d152f0583bb196339c2568351573e304.tar.bz2 |
ProcessSingleton(all): create the lock immediately after failing to connect to an existing process.
ProcessSingletonLinux: if creating the lock fails, try to notify again.
BUG=44417
TEST=manual
Review URL: http://codereview.chromium.org/2066014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48533 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton_linux_uitest.cc')
-rw-r--r-- | chrome/browser/process_singleton_linux_uitest.cc | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/chrome/browser/process_singleton_linux_uitest.cc b/chrome/browser/process_singleton_linux_uitest.cc index ef42966..3f7ddd8 100644 --- a/chrome/browser/process_singleton_linux_uitest.cc +++ b/chrome/browser/process_singleton_linux_uitest.cc @@ -30,14 +30,14 @@ namespace { typedef UITest ProcessSingletonLinuxTest; -// 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(). -ProcessSingleton::NotifyResult NotifyOtherProcess(const std::string& url, - int timeout_ms) { +ProcessSingleton* CreateProcessSingleton() { FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); + return new ProcessSingleton(user_data_dir); +} + +CommandLine CommandLineForUrl(const std::string& url) { // Hack: mutate the current process's command line so we don't show a dialog. // Note that this only works if we have no loose values on the command line, // but that's fine for unit tests. In a UI test we disable error dialogs @@ -48,11 +48,28 @@ ProcessSingleton::NotifyResult NotifyOtherProcess(const std::string& url, CommandLine new_cmd_line(*cmd_line); new_cmd_line.AppendLooseValue(ASCIIToWide(url)); + return new_cmd_line; +} - ProcessSingleton process_singleton(user_data_dir); +// 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(). +ProcessSingleton::NotifyResult NotifyOtherProcess(const std::string& url, + int timeout_ms) { + scoped_ptr<ProcessSingleton> process_singleton(CreateProcessSingleton()); + return process_singleton->NotifyOtherProcessWithTimeout( + CommandLineForUrl(url), timeout_ms / 1000, true); +} - return process_singleton.NotifyOtherProcessWithTimeout( - new_cmd_line, timeout_ms / 1000); +// A helper method to call ProcessSingleton::NotifyOtherProcessOrCreate(). +// |url| will be added to CommandLine for current process, so that it can be +// sent to browser process by ProcessSingleton::NotifyOtherProcessOrCreate(). +ProcessSingleton::NotifyResult NotifyOtherProcessOrCreate( + const std::string& url, + int timeout_ms) { + scoped_ptr<ProcessSingleton> process_singleton(CreateProcessSingleton()); + return process_singleton->NotifyOtherProcessWithTimeoutOrCreate( + CommandLineForUrl(url), timeout_ms / 1000); } } // namespace @@ -188,3 +205,30 @@ TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) { EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, NotifyOtherProcess(url, action_timeout_ms())); } + +// Test that we fail when lock says process is on another host and we can't +// notify it over the socket. +TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) { + base::ProcessId pid = browser_process_id(); + + 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(sleep_timeout_ms())); + + 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, + NotifyOtherProcessOrCreate(url, action_timeout_ms())); +} + +// Test that Create fails when another browser is using the profile directory. +TEST_F(ProcessSingletonLinuxTest, CreateFailsWithExistingBrowser) { + scoped_ptr<ProcessSingleton> process_singleton(CreateProcessSingleton()); + EXPECT_FALSE(process_singleton->Create()); +} |