| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 } // namespace | 258 } // namespace |
| 259 | 259 |
| 260 TEST_F(ProcessSingletonTest, KillsHungBrowserWithNoWindows) { | 260 TEST_F(ProcessSingletonTest, KillsHungBrowserWithNoWindows) { |
| 261 ASSERT_NO_FATAL_FAILURE(PrepareTest(NO_WINDOW, false)); | 261 ASSERT_NO_FATAL_FAILURE(PrepareTest(NO_WINDOW, false)); |
| 262 | 262 |
| 263 // As the hung browser has no visible window, it'll be killed without | 263 // As the hung browser has no visible window, it'll be killed without |
| 264 // user interaction. | 264 // user interaction. |
| 265 ProcessSingleton::NotifyResult notify_result = | 265 ProcessSingleton::NotifyResult notify_result = |
| 266 test_singleton()->NotifyOtherProcessOrCreate(); | 266 test_singleton()->NotifyOtherProcessOrCreate(); |
| 267 ASSERT_EQ(ProcessSingleton::PROFILE_IN_USE, notify_result); | 267 |
| 268 // The hung process was killed and the notification is equivalent to |
| 269 // a non existent process. |
| 270 ASSERT_EQ(ProcessSingleton::PROCESS_NONE, notify_result); |
| 268 | 271 |
| 269 // The should-kill callback should not have been called, as the "browser" does | 272 // The should-kill callback should not have been called, as the "browser" does |
| 270 // not have visible window. | 273 // not have visible window. |
| 271 EXPECT_FALSE(should_kill_called()); | 274 EXPECT_FALSE(should_kill_called()); |
| 272 | 275 |
| 273 // Verify that the hung browser has beem terminated with the | 276 // Verify that the hung browser has been terminated with the |
| 274 // RESULT_CODE_HUNG exit code. | 277 // RESULT_CODE_HUNG exit code. |
| 275 int exit_code = 0; | 278 int exit_code = 0; |
| 276 EXPECT_TRUE( | 279 EXPECT_TRUE( |
| 277 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); | 280 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); |
| 278 EXPECT_EQ(content::RESULT_CODE_HUNG, exit_code); | 281 EXPECT_EQ(content::RESULT_CODE_HUNG, exit_code); |
| 279 } | 282 } |
| 280 | 283 |
| 281 TEST_F(ProcessSingletonTest, DoesntKillWithoutUserPermission) { | 284 TEST_F(ProcessSingletonTest, DoesntKillWithoutUserPermission) { |
| 282 ASSERT_NO_FATAL_FAILURE(PrepareTest(WITH_WINDOW, false)); | 285 ASSERT_NO_FATAL_FAILURE(PrepareTest(WITH_WINDOW, false)); |
| 283 | 286 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 297 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); | 300 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); |
| 298 } | 301 } |
| 299 | 302 |
| 300 TEST_F(ProcessSingletonTest, KillWithUserPermission) { | 303 TEST_F(ProcessSingletonTest, KillWithUserPermission) { |
| 301 ASSERT_NO_FATAL_FAILURE(PrepareTest(WITH_WINDOW, true)); | 304 ASSERT_NO_FATAL_FAILURE(PrepareTest(WITH_WINDOW, true)); |
| 302 | 305 |
| 303 // As the hung browser has a visible window, this should query the user | 306 // As the hung browser has a visible window, this should query the user |
| 304 // before killing the hung process. | 307 // before killing the hung process. |
| 305 ProcessSingleton::NotifyResult notify_result = | 308 ProcessSingleton::NotifyResult notify_result = |
| 306 test_singleton()->NotifyOtherProcessOrCreate(); | 309 test_singleton()->NotifyOtherProcessOrCreate(); |
| 307 ASSERT_EQ(ProcessSingleton::PROFILE_IN_USE, notify_result); | 310 |
| 311 // The hung process was killed and the notification is equivalent to |
| 312 // a non existent process. |
| 313 ASSERT_EQ(ProcessSingleton::PROCESS_NONE, notify_result); |
| 308 | 314 |
| 309 // The should-kill callback should have been called, as the "browser" has a | 315 // The should-kill callback should have been called, as the "browser" has a |
| 310 // visible window. | 316 // visible window. |
| 311 EXPECT_TRUE(should_kill_called()); | 317 EXPECT_TRUE(should_kill_called()); |
| 312 | 318 |
| 313 // Verify that the hung browser has beem terminated with the | 319 // Verify that the hung browser has been terminated with the |
| 314 // RESULT_CODE_HUNG exit code. | 320 // RESULT_CODE_HUNG exit code. |
| 315 int exit_code = 0; | 321 int exit_code = 0; |
| 316 EXPECT_TRUE( | 322 EXPECT_TRUE( |
| 317 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); | 323 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); |
| 318 EXPECT_EQ(content::RESULT_CODE_HUNG, exit_code); | 324 EXPECT_EQ(content::RESULT_CODE_HUNG, exit_code); |
| 319 } | 325 } |
| OLD | NEW |