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 int exit_code = 0; | 174 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); |
175 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit( | |
176 TestTimeouts::action_max_timeout_ms(), &exit_code)); | |
177 EXPECT_EQ(-1, exit_code); // Expect unclean shutdown. | |
178 } | 175 } |
179 | 176 |
180 // 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 |
181 // happens to exist. | 178 // happens to exist. |
182 // 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 |
183 // 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 |
184 // 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 |
185 // 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 |
186 // unittest.) | 183 // unittest.) |
187 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) { | 184 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessNoSuicide) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // 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 |
222 // notify it over the socket. | 219 // notify it over the socket. |
223 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) { | 220 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessDifferingHost) { |
224 base::ProcessId pid = browser_process_id(); | 221 base::ProcessId pid = browser_process_id(); |
225 | 222 |
226 ASSERT_GE(pid, 1); | 223 ASSERT_GE(pid, 1); |
227 | 224 |
228 // 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. |
229 kill(pid, SIGKILL); | 226 kill(pid, SIGKILL); |
230 // 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. |
231 int exit_code = 0; | 228 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); |
232 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit( | |
233 TestTimeouts::action_max_timeout_ms(), &exit_code)); | |
234 EXPECT_EQ(-1, exit_code); // Expect unclean shutdown. | |
235 | 229 |
236 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 230 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
237 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 231 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
238 | 232 |
239 std::string url("about:blank"); | 233 std::string url("about:blank"); |
240 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 234 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
241 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms())); | 235 NotifyOtherProcess(url, TestTimeouts::action_timeout_ms())); |
242 | 236 |
243 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); | 237 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); |
244 } | 238 } |
245 | 239 |
246 // 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 |
247 // notify it over the socket. | 241 // notify it over the socket. |
248 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) { | 242 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessOrCreate_DifferingHost) { |
249 base::ProcessId pid = browser_process_id(); | 243 base::ProcessId pid = browser_process_id(); |
250 | 244 |
251 ASSERT_GE(pid, 1); | 245 ASSERT_GE(pid, 1); |
252 | 246 |
253 // 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. |
254 kill(pid, SIGKILL); | 248 kill(pid, SIGKILL); |
255 // 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. |
256 int exit_code = 0; | 250 EXPECT_FALSE(CrashAwareSleep(TestTimeouts::action_timeout_ms())); |
257 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit( | |
258 TestTimeouts::action_max_timeout_ms(), &exit_code)); | |
259 EXPECT_EQ(-1, exit_code); // Expect unclean shutdown. | |
260 | 251 |
261 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 252 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
262 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 253 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
263 | 254 |
264 std::string url("about:blank"); | 255 std::string url("about:blank"); |
265 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 256 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
266 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms())); | 257 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms())); |
267 | 258 |
268 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); | 259 ASSERT_EQ(0, unlink(lock_path_.value().c_str())); |
269 } | 260 } |
(...skipping 30 matching lines...) Expand all Loading... |
300 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str())); | 291 EXPECT_EQ(0, symlink("INCORRECTCOOKIE", cookie_path_.value().c_str())); |
301 | 292 |
302 // Also change the hostname, so the remote does not retry. | 293 // Also change the hostname, so the remote does not retry. |
303 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); | 294 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); |
304 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); | 295 EXPECT_EQ(0, symlink("FAKEFOOHOST-1234", lock_path_.value().c_str())); |
305 | 296 |
306 std::string url("about:blank"); | 297 std::string url("about:blank"); |
307 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, | 298 EXPECT_EQ(ProcessSingleton::PROFILE_IN_USE, |
308 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms())); | 299 NotifyOtherProcessOrCreate(url, TestTimeouts::action_timeout_ms())); |
309 } | 300 } |
OLD | NEW |