| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/process_singleton.h" | 5 #include "chrome/browser/process_singleton.h" |
| 6 | 6 |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <sys/wait.h> | 8 #include <sys/wait.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 #include <vector> | 11 #include <vector> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/eintr_wrapper.h" | 14 #include "base/eintr_wrapper.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/test/test_timeouts.h" |
| 17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/test/chrome_process_util.h" | 24 #include "chrome/test/chrome_process_util.h" |
| 24 #include "chrome/test/ui/ui_test.h" | 25 #include "chrome/test/ui/ui_test.h" |
| 25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 164 |
| 164 // Wait to make sure the browser process is actually stopped. | 165 // Wait to make sure the browser process is actually stopped. |
| 165 // It's necessary when running with valgrind. | 166 // It's necessary when running with valgrind. |
| 166 EXPECT_GE(HANDLE_EINTR(waitpid(pid, 0, WUNTRACED)), 0); | 167 EXPECT_GE(HANDLE_EINTR(waitpid(pid, 0, WUNTRACED)), 0); |
| 167 | 168 |
| 168 std::string url("about:blank"); | 169 std::string url("about:blank"); |
| 169 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, | 170 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, |
| 170 NotifyOtherProcess(url, action_timeout_ms())); | 171 NotifyOtherProcess(url, action_timeout_ms())); |
| 171 | 172 |
| 172 // Wait for a while to make sure the browser process is actually killed. | 173 // Wait for a while to make sure the browser process is actually killed. |
| 173 EXPECT_FALSE(CrashAwareSleep(sleep_timeout_ms())); | 174 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); |
| 174 } | 175 } |
| 175 | 176 |
| 176 // Test that we don't kill ourselves by accident if a lockfile with the same pid | 177 // Test that we don't kill ourselves by accident if a lockfile with the same pid |
| 177 // happens to exist. | 178 // happens to exist. |
| 178 // TODO(mattm): This doesn't really need to be a uitest. (We don't use the | 179 // TODO(mattm): This doesn't really need to be a uitest. (We don't use the |
| 179 // uitest created browser process, but we do use some uitest provided stuff like | 180 // uitest created browser process, but we do use some uitest provided stuff like |
| 180 // the user_data_dir and the NotifyOtherProcess function in this file, which | 181 // the user_data_dir and the NotifyOtherProcess function in this file, which |
| 181 // would have to be duplicated or shared if this test was moved into a | 182 // would have to be duplicated or shared if this test was moved into a |
| 182 // unittest.) | 183 // unittest.) |
| 183 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) { | 184 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // Test that we fail when lock says process is on another host and we can't | 218 // Test that we fail when lock says process is on another host and we can't |
| 218 // notify it over the socket. | 219 // notify it over the socket. |
| 219 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) { | 220 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) { |
| 220 base::ProcessId pid = browser_process_id(); | 221 base::ProcessId pid = browser_process_id(); |
| 221 | 222 |
| 222 ASSERT_GE(pid, 1); | 223 ASSERT_GE(pid, 1); |
| 223 | 224 |
| 224 // Kill the browser process, so that it does not respond on the socket. | 225 // Kill the browser process, so that it does not respond on the socket. |
| 225 kill(pid, SIGKILL); | 226 kill(pid, SIGKILL); |
| 226 // Wait for a while to make sure the browser process is actually killed. | 227 // Wait for a while to make sure the browser process is actually killed. |
| 227 EXPECT_FALSE(CrashAwareSleep(sleep_timeout_ms())); | 228 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); |
| 228 | 229 |
| 229 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 230 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
| 230 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 231 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
| 231 | 232 |
| 232 std::string url("about:blank"); | 233 std::string url("about:blank"); |
| 233 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 234 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
| 234 NotifyOtherProcess(url, action_timeout_ms())); | 235 NotifyOtherProcess(url, action_timeout_ms())); |
| 235 | 236 |
| 236 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); | 237 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); |
| 237 } | 238 } |
| 238 | 239 |
| 239 // Test that we fail when lock says process is on another host and we can't | 240 // Test that we fail when lock says process is on another host and we can't |
| 240 // notify it over the socket. | 241 // notify it over the socket. |
| 241 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) { | 242 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) { |
| 242 base::ProcessId pid = browser_process_id(); | 243 base::ProcessId pid = browser_process_id(); |
| 243 | 244 |
| 244 ASSERT_GE(pid, 1); | 245 ASSERT_GE(pid, 1); |
| 245 | 246 |
| 246 // Kill the browser process, so that it does not respond on the socket. | 247 // Kill the browser process, so that it does not respond on the socket. |
| 247 kill(pid, SIGKILL); | 248 kill(pid, SIGKILL); |
| 248 // Wait for a while to make sure the browser process is actually killed. | 249 // Wait for a while to make sure the browser process is actually killed. |
| 249 EXPECT_FALSE(CrashAwareSleep(sleep_timeout_ms())); | 250 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); |
| 250 | 251 |
| 251 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 252 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
| 252 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 253 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
| 253 | 254 |
| 254 std::string url("about:blank"); | 255 std::string url("about:blank"); |
| 255 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 256 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
| 256 NotifyOtherProcessOrCreate(url, action_timeout_ms())); | 257 NotifyOtherProcessOrCreate(url, action_timeout_ms())); |
| 257 | 258 |
| 258 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); | 259 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); |
| 259 } | 260 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 290 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str())); | 291 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str())); |
| 291 | 292 |
| 292 // Also change the hostname, so the remote does not retry. | 293 // Also change the hostname, so the remote does not retry. |
| 293 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 294 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
| 294 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 295 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
| 295 | 296 |
| 296 std::string url("about:blank"); | 297 std::string url("about:blank"); |
| 297 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 298 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
| 298 NotifyOtherProcessOrCreate(url, action_timeout_ms())); | 299 NotifyOtherProcessOrCreate(url, action_timeout_ms())); |
| 299 } | 300 } |
| OLD | NEW |