OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import os |
| 7 import psutil |
| 8 import signal |
| 9 import time |
| 10 import unittest |
| 11 |
| 12 import pyauto_functional |
| 13 import pyauto |
| 14 |
| 15 |
| 16 class WaitForChildrenBeforeExitingTest(pyauto.PyUITest): |
| 17 |
| 18 def ExtraChromeFlags(self): |
| 19 """Ensures Chrome is launched with custom flags. |
| 20 |
| 21 Returns: |
| 22 A list of extra flags to pass to Chrome when it is launched. |
| 23 """ |
| 24 extra_flags = ['--no-sandbox', '--child-clean-exit', |
| 25 '--wait-for-children-before-exiting'] |
| 26 return pyauto.PyUITest.ExtraChromeFlags(self) + extra_flags |
| 27 |
| 28 |
| 29 def _IsProcessAlive(self, pid): |
| 30 """Checks whether a process is alive or not. |
| 31 |
| 32 Args: |
| 33 pid: The process id on which to perform this check. |
| 34 |
| 35 Returns: |
| 36 True if a process is alive and not a zombie. |
| 37 """ |
| 38 try: |
| 39 process = psutil.Process(pid) |
| 40 except psutil.error.NoSuchProcess: |
| 41 return False |
| 42 |
| 43 if process.status == psutil.STATUS_ZOMBIE: |
| 44 return False |
| 45 |
| 46 return True |
| 47 |
| 48 def testWaitForChildrenBeforeExiting(self): |
| 49 """Ensures the browser process waits for all children before exiting.""" |
| 50 url = self.GetHttpURLForDataPath('title2.html') |
| 51 self.NavigateToURL(url) |
| 52 |
| 53 browser_pid = self.GetBrowserInfo()['browser_pid'] |
| 54 renderer_pid = ( |
| 55 self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']) |
| 56 |
| 57 os.kill(renderer_pid, signal.SIGSTOP) |
| 58 os.kill(browser_pid, signal.SIGINT) |
| 59 |
| 60 time.sleep(20) |
| 61 |
| 62 # The browser should still be alive, waiting for the renderer to die. |
| 63 self.assertTrue(self._IsProcessAlive(browser_pid)) |
| 64 self.assertTrue(self._IsProcessAlive(renderer_pid)) |
| 65 |
| 66 # Resume the renderer. |
| 67 os.kill(renderer_pid, signal.SIGCONT) |
| 68 |
| 69 time.sleep(20) |
| 70 |
| 71 self.assertFalse(self._IsProcessAlive(renderer_pid)) |
| 72 self.assertFalse(self._IsProcessAlive(browser_pid)) |
| 73 |
| 74 |
| 75 if __name__ == '__main__': |
| 76 pyauto_functional.Main() |
OLD | NEW |