Chromium Code Reviews| 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/image_decoder.h" | 5 #include "chrome/browser/image_decoder.h" |
| 6 | 6 |
| 7 #include "chrome/grit/generated_resources.h" | 7 #include "chrome/grit/generated_resources.h" |
| 8 #include "chrome/test/base/in_process_browser_test.h" | 8 #include "chrome/test/base/in_process_browser_test.h" |
| 9 #include "content/public/browser/browser_child_process_observer.h" | 9 #include "content/public/browser/browser_child_process_observer.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 base::ProcessHandle out_handle; | 101 base::ProcessHandle out_handle; |
| 102 if (!::DuplicateHandle(GetCurrentProcess(), handle, | 102 if (!::DuplicateHandle(GetCurrentProcess(), handle, |
| 103 GetCurrentProcess(), &out_handle, | 103 GetCurrentProcess(), &out_handle, |
| 104 0, FALSE, DUPLICATE_SAME_ACCESS)) { | 104 0, FALSE, DUPLICATE_SAME_ACCESS)) { |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 handle = out_handle; | 107 handle = out_handle; |
| 108 #endif | 108 #endif |
| 109 | 109 |
| 110 // Use a non-zero exit code so it counts as a crash. | 110 // Use a non-zero exit code so it counts as a crash. |
| 111 EXPECT_TRUE(base::Process(handle).Terminate(1, true)); | 111 // Don't wait for the process after sending the kill signal. According to |
|
Lei Zhang
2015/05/11 23:09:19
By 'kill signal', did you mean SIGTERM?
Anand Mistry (off Chromium)
2015/05/12 00:05:31
Yes.
| |
| 112 // POSIX, doing so causes the resulting zombie to be removed from the | |
| 113 // process table. However, Chromium treats an error on |waitpid| (in this | |
| 114 // case, ECHILD) as a "normal" termination and doesn't invoke the process | |
| 115 // host detegate's |OnProcessCrashed|. | |
|
Lei Zhang
2015/05/11 23:09:19
nit: typo
Anand Mistry (off Chromium)
2015/05/12 00:05:31
Done.
| |
| 116 EXPECT_TRUE(base::Process(handle).Terminate(1, false)); | |
|
Lei Zhang
2015/05/11 23:09:19
Maybe we should post this to the IO thread, so the
Anand Mistry (off Chromium)
2015/05/12 00:05:31
I don't think it's possible for the two to race. I
Lei Zhang
2015/05/12 02:23:24
I was thinking if we had left this as true, then t
| |
| 112 did_kill_ = true; | 117 did_kill_ = true; |
| 113 } | 118 } |
| 114 | 119 |
| 115 bool did_kill_; | 120 bool did_kill_; |
| 116 const base::string16 utility_process_name_; | 121 const base::string16 utility_process_name_; |
| 117 | 122 |
| 118 DISALLOW_COPY_AND_ASSIGN(KillProcessObserver); | 123 DISALLOW_COPY_AND_ASSIGN(KillProcessObserver); |
| 119 }; | 124 }; |
| 120 | 125 |
| 121 } // namespace | 126 } // namespace |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 150 test_request.reset(); | 155 test_request.reset(); |
| 151 runner->Run(); | 156 runner->Run(); |
| 152 } | 157 } |
| 153 | 158 |
| 154 // Killing the utility process counts as a crash. Thus the request fails. | 159 // Killing the utility process counts as a crash. Thus the request fails. |
| 155 // If ImageDecoder did not handle the crash properly, the request never finishes | 160 // If ImageDecoder did not handle the crash properly, the request never finishes |
| 156 // and this test would hang. | 161 // and this test would hang. |
| 157 // Note: This test is inherently racy because KillProcessObserver lives on the | 162 // Note: This test is inherently racy because KillProcessObserver lives on the |
| 158 // UI thread but ImageDecoder does its work mainly on the IO thread. So the test | 163 // UI thread but ImageDecoder does its work mainly on the IO thread. So the test |
| 159 // checks for both possible valid outcomes. | 164 // checks for both possible valid outcomes. |
| 160 // BUG(486194): Disabled due to flakyness. | 165 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, StartAndKillProcess) { |
| 161 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, DISABLED_StartAndKillProcess) { | |
| 162 KillProcessObserver observer; | 166 KillProcessObserver observer; |
| 163 scoped_refptr<content::MessageLoopRunner> runner = | 167 scoped_refptr<content::MessageLoopRunner> runner = |
| 164 new content::MessageLoopRunner; | 168 new content::MessageLoopRunner; |
| 165 TestImageRequest test_request(runner->QuitClosure()); | 169 TestImageRequest test_request(runner->QuitClosure()); |
| 166 ImageDecoder::Start(&test_request, GetValidPngString()); | 170 ImageDecoder::Start(&test_request, GetValidPngString()); |
| 167 runner->Run(); | 171 runner->Run(); |
| 168 if (!test_request.decode_succeeded()) { | 172 if (!test_request.decode_succeeded()) { |
| 169 // The UI thread won the race. Make sure the utility process did get killed. | 173 // The UI thread won the race. Make sure the utility process did get killed. |
| 170 EXPECT_TRUE(observer.did_kill()); | 174 EXPECT_TRUE(observer.did_kill()); |
| 171 } | 175 } |
| 172 // Else the IO thread won the race and the image got decoded. Oh well. | 176 // Else the IO thread won the race and the image got decoded. Oh well. |
| 173 } | 177 } |
| OLD | NEW |