| OLD | NEW |
| 1 // Copyright (c) 2011 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> |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 // Wait to make sure the browser process is actually stopped. | 165 // Wait to make sure the browser process is actually stopped. |
| 166 // It's necessary when running with valgrind. | 166 // It's necessary when running with valgrind. |
| 167 EXPECT_GE(HANDLE_EINTR(waitpid(pid, 0, WUNTRACED)), 0); | 167 EXPECT_GE(HANDLE_EINTR(waitpid(pid, 0, WUNTRACED)), 0); |
| 168 | 168 |
| 169 std::string url("about:blank"); | 169 std::string url("about:blank"); |
| 170 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, | 170 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, |
| 171 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms())); | 171 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms())); |
| 172 | 172 |
| 173 // 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. |
| 174 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); | 174 int exit_code = 0; |
| 175 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit( |
| 176 TestTimeouts::action_max_timeout_ms(), &exit_code)); |
| 177 EXPECT_EQ(-1, exit_code); // Expect unclean shutdown. |
| 175 } | 178 } |
| 176 | 179 |
| 177 // Test that we don't kill ourselves by accident if a lockfile with the same pid | 180 // Test that we don't kill ourselves by accident if a lockfile with the same pid |
| 178 // happens to exist. | 181 // happens to exist. |
| 179 // TODO(mattm): This doesn't really need to be a uitest. (We don't use the | 182 // TODO(mattm): This doesn't really need to be a uitest. (We don't use the |
| 180 // uitest created browser process, but we do use some uitest provided stuff like | 183 // uitest created browser process, but we do use some uitest provided stuff like |
| 181 // the user_data_dir and the NotifyOtherProcess function in this file, which | 184 // the user_data_dir and the NotifyOtherProcess function in this file, which |
| 182 // would have to be duplicated or shared if this test was moved into a | 185 // would have to be duplicated or shared if this test was moved into a |
| 183 // unittest.) | 186 // unittest.) |
| 184 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) { | 187 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // Test that we fail when lock says process is on another host and we can't | 221 // Test that we fail when lock says process is on another host and we can't |
| 219 // notify it over the socket. | 222 // notify it over the socket. |
| 220 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) { | 223 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) { |
| 221 base::ProcessId pid = browser_process_id(); | 224 base::ProcessId pid = browser_process_id(); |
| 222 | 225 |
| 223 ASSERT_GE(pid, 1); | 226 ASSERT_GE(pid, 1); |
| 224 | 227 |
| 225 // Kill the browser process, so that it does not respond on the socket. | 228 // Kill the browser process, so that it does not respond on the socket. |
| 226 kill(pid, SIGKILL); | 229 kill(pid, SIGKILL); |
| 227 // Wait for a while to make sure the browser process is actually killed. | 230 // Wait for a while to make sure the browser process is actually killed. |
| 228 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); | 231 int exit_code = 0; |
| 232 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit( |
| 233 TestTimeouts::action_max_timeout_ms(), &exit_code)); |
| 234 EXPECT_EQ(-1, exit_code); // Expect unclean shutdown. |
| 229 | 235 |
| 230 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 236 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
| 231 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 237 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
| 232 | 238 |
| 233 std::string url("about:blank"); | 239 std::string url("about:blank"); |
| 234 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 240 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
| 235 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms())); | 241 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms())); |
| 236 | 242 |
| 237 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); | 243 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); |
| 238 } | 244 } |
| 239 | 245 |
| 240 // Test that we fail when lock says process is on another host and we can't | 246 // Test that we fail when lock says process is on another host and we can't |
| 241 // notify it over the socket. | 247 // notify it over the socket. |
| 242 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) { | 248 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) { |
| 243 base::ProcessId pid = browser_process_id(); | 249 base::ProcessId pid = browser_process_id(); |
| 244 | 250 |
| 245 ASSERT_GE(pid, 1); | 251 ASSERT_GE(pid, 1); |
| 246 | 252 |
| 247 // Kill the browser process, so that it does not respond on the socket. | 253 // Kill the browser process, so that it does not respond on the socket. |
| 248 kill(pid, SIGKILL); | 254 kill(pid, SIGKILL); |
| 249 // Wait for a while to make sure the browser process is actually killed. | 255 // Wait for a while to make sure the browser process is actually killed. |
| 250 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); | 256 int exit_code = 0; |
| 257 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit( |
| 258 TestTimeouts::action_max_timeout_ms(), &exit_code)); |
| 259 EXPECT_EQ(-1, exit_code); // Expect unclean shutdown. |
| 251 | 260 |
| 252 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 261 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
| 253 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 262 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
| 254 | 263 |
| 255 std::string url("about:blank"); | 264 std::string url("about:blank"); |
| 256 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 265 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
| 257 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms())); | 266 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms())); |
| 258 | 267 |
| 259 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); | 268 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); |
| 260 } | 269 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 291 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str())); | 300 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str())); |
| 292 | 301 |
| 293 // Also change the hostname, so the remote does not retry. | 302 // Also change the hostname, so the remote does not retry. |
| 294 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 303 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
| 295 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 304 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
| 296 | 305 |
| 297 std::string url("about:blank"); | 306 std::string url("about:blank"); |
| 298 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 307 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
| 299 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms())); | 308 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms())); |
| 300 } | 309 } |
| OLD | NEW |