| Index: tools/browser_tester/browsertester/browserlauncher.py
|
| ===================================================================
|
| --- tools/browser_tester/browsertester/browserlauncher.py (revision 6635)
|
| +++ tools/browser_tester/browsertester/browserlauncher.py (working copy)
|
| @@ -6,40 +6,23 @@
|
| import os.path
|
| import re
|
| import shutil
|
| +import subprocess
|
| import sys
|
| import tempfile
|
| import time
|
|
|
| -import browserprocess
|
| +# mozrunner is needed as long as we are supporting versions of Python
|
| +# before 2.6.
|
| +import mozrunner
|
|
|
| -class LaunchFailure(Exception):
|
| - pass
|
|
|
| -
|
| -def GetPlatform():
|
| - if sys.platform == 'darwin':
|
| - platform = 'mac'
|
| - elif sys.platform.startswith('linux'):
|
| - platform = 'linux'
|
| - elif sys.platform in ('cygwin', 'win32'):
|
| - platform = 'windows'
|
| - else:
|
| - raise LaunchFailure('Unknown platform: %s' % sys.platform)
|
| - return platform
|
| -
|
| -
|
| -PLATFORM = GetPlatform()
|
| -
|
| -
|
| def SelectRunCommand():
|
| # The subprocess module added support for .kill in Python 2.6
|
| if sys.version_info[0] < 2 or (sys.version_info[0] == 2 and
|
| sys.version_info[1] < 6):
|
| - return browserprocess.RunCommandWithMozrunner
|
| - elif PLATFORM == 'linux':
|
| - return browserprocess.RunCommandInProcessGroup
|
| + return mozrunner.run_command
|
| else:
|
| - return browserprocess.RunCommandWithSubprocess
|
| + return subprocess.Popen
|
|
|
|
|
| RunCommand = SelectRunCommand()
|
| @@ -64,7 +47,25 @@
|
| break
|
|
|
|
|
| +class LaunchFailure(Exception):
|
| + pass
|
|
|
| +
|
| +def GetPlatform():
|
| + if sys.platform == 'darwin':
|
| + platform = 'mac'
|
| + elif sys.platform.startswith('linux'):
|
| + platform = 'linux'
|
| + elif sys.platform in ('cygwin', 'win32'):
|
| + platform = 'windows'
|
| + else:
|
| + raise LaunchFailure('Unknown platform: %s' % sys.platform)
|
| + return platform
|
| +
|
| +
|
| +PLATFORM = GetPlatform()
|
| +
|
| +
|
| # In Windows, subprocess seems to have an issue with file names that
|
| # contain spaces.
|
| def EscapeSpaces(path):
|
| @@ -125,11 +126,26 @@
|
| raise LaunchFailure('Cannot find the browser binary')
|
| return binary
|
|
|
| + # subprocess.wait() doesn't have a timeout, unfortunately.
|
| def WaitForProcessDeath(self):
|
| - self.browser_process.Wait(self.WAIT_STEPS, self.SLEEP_TIME)
|
| + i = 0
|
| + while self.handle.poll() is None and i < self.WAIT_STEPS:
|
| + time.sleep(self.SLEEP_TIME)
|
| + i += 1
|
|
|
| def Cleanup(self):
|
| - self.browser_process.Kill()
|
| + if self.handle.poll() is None:
|
| + print 'KILLING the browser'
|
| + try:
|
| + self.handle.kill()
|
| + # If it doesn't die, we hang. Oh well.
|
| + self.handle.wait()
|
| + except Exception:
|
| + # If it is already dead, then it's ok.
|
| + # This may happen if the browser dies after the first poll, but before
|
| + # the kill.
|
| + if self.handle.poll() is None:
|
| + raise
|
|
|
| RemoveDirectory(self.profile)
|
| if self.tool_log_dir is not None:
|
| @@ -157,13 +173,14 @@
|
| print 'ENV:', ' '.join(['='.join(pair) for pair in env.iteritems()])
|
| print 'LAUNCHING: %s' % ' '.join(cmd)
|
| sys.stdout.flush()
|
| - self.browser_process = RunCommand(cmd, env=env)
|
| + self.handle = RunCommand(cmd, env=env)
|
| + print 'PID', self.handle.pid
|
|
|
| def IsRunning(self):
|
| - return self.browser_process.IsRunning()
|
| + return self.handle.poll() is None
|
|
|
| def GetReturnCode(self):
|
| - return self.browser_process.GetReturnCode()
|
| + return self.handle.returncode
|
|
|
| def Run(self, url, port):
|
| self.binary = EscapeSpaces(self.FindBinary())
|
|
|