Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import os as os | 4 import os as os |
| 5 import re | |
| 5 import subprocess as subprocess | 6 import subprocess as subprocess |
| 6 import shutil | 7 import shutil |
| 7 import tempfile | 8 import tempfile |
| 8 | 9 |
| 9 from telemetry import browser_backend | 10 from telemetry import browser_backend |
| 10 from telemetry import util | 11 from telemetry import util |
| 11 | 12 |
| 12 class DesktopBrowserBackend(browser_backend.BrowserBackend): | 13 class DesktopBrowserBackend(browser_backend.BrowserBackend): |
| 13 """The backend for controlling a locally-executed browser instance, on Linux, | 14 """The backend for controlling a locally-executed browser instance, on Linux, |
| 14 Mac or Windows. | 15 Mac or Windows. |
| 15 """ | 16 """ |
| 16 def __init__(self, options, executable, is_content_shell): | 17 def __init__(self, options, executable, is_content_shell): |
| 17 super(DesktopBrowserBackend, self).__init__(is_content_shell, options) | 18 super(DesktopBrowserBackend, self).__init__(is_content_shell, options) |
| 18 | 19 |
| 19 # Initialize fields so that an explosion during init doesn't break in Close. | 20 # Initialize fields so that an explosion during init doesn't break in Close. |
| 20 self._proc = None | 21 self._proc = None |
| 21 self._tmpdir = None | 22 self._tmpdir = None |
| 22 self._tmp_output_file = None | 23 self._tmp_output_file = None |
| 23 | 24 |
| 24 self._executable = executable | 25 self._executable = executable |
| 25 if not self._executable: | 26 if not self._executable: |
| 26 raise Exception('Cannot create browser, no executable found!') | 27 raise Exception('Cannot create browser, no executable found!') |
| 27 | 28 |
| 28 self._port = util.GetAvailableLocalPort() | 29 self._port = util.GetAvailableLocalPort() |
| 30 self._chrome_branch_number = self._GetChromeBranchNumber() | |
| 29 | 31 |
| 30 args = [self._executable] | 32 args = [self._executable] |
| 31 args.extend(self.GetBrowserStartupArgs()) | 33 args.extend(self.GetBrowserStartupArgs()) |
| 32 if not options.show_stdout: | 34 if not options.show_stdout: |
| 33 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) | 35 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) |
| 34 self._proc = subprocess.Popen( | 36 self._proc = subprocess.Popen( |
| 35 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) | 37 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) |
| 36 else: | 38 else: |
| 37 self._proc = subprocess.Popen(args) | 39 self._proc = subprocess.Popen(args) |
| 38 | 40 |
| 39 try: | 41 try: |
| 40 self._WaitForBrowserToComeUp() | 42 self._WaitForBrowserToComeUp() |
| 41 self._PostBrowserStartupInitialization() | 43 self._PostBrowserStartupInitialization() |
| 42 except: | 44 except: |
| 43 self.Close() | 45 self.Close() |
| 44 raise | 46 raise |
| 45 | 47 |
| 46 def GetBrowserStartupArgs(self): | 48 def GetBrowserStartupArgs(self): |
| 47 args = super(DesktopBrowserBackend, self).GetBrowserStartupArgs() | 49 args = super(DesktopBrowserBackend, self).GetBrowserStartupArgs() |
| 48 args.append('--remote-debugging-port=%i' % self._port) | 50 args.append('--remote-debugging-port=%i' % self._port) |
| 49 args.append('--window-size=1280,1024') | 51 args.append('--window-size=1280,1024') |
| 50 args.append('--enable-benchmarking') | 52 if self._chrome_branch_number >= 1404: |
|
nduca
2013/02/12 01:28:49
should this be conditional on content shell, since
Danh Nguyen
2013/02/12 15:57:26
Done. Made all chrome switches conditional on not
| |
| 53 args.append('--enable-net-benchmarking') | |
| 54 else: | |
| 55 args.append('--enable-benchmarking') | |
| 51 if not self.options.dont_override_profile: | 56 if not self.options.dont_override_profile: |
| 52 self._tmpdir = tempfile.mkdtemp() | 57 self._tmpdir = tempfile.mkdtemp() |
| 53 args.append('--user-data-dir=%s' % self._tmpdir) | 58 args.append('--user-data-dir=%s' % self._tmpdir) |
| 54 return args | 59 return args |
| 55 | 60 |
| 56 def IsBrowserRunning(self): | 61 def IsBrowserRunning(self): |
| 57 return self._proc.poll() == None | 62 return self._proc.poll() == None |
| 58 | 63 |
| 59 def GetStandardOutput(self): | 64 def GetStandardOutput(self): |
| 60 assert self._tmp_output_file, "Can't get standard output with show_stdout" | 65 assert self._tmp_output_file, "Can't get standard output with show_stdout" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 shutil.rmtree(self._tmpdir, ignore_errors=True) | 105 shutil.rmtree(self._tmpdir, ignore_errors=True) |
| 101 self._tmpdir = None | 106 self._tmpdir = None |
| 102 | 107 |
| 103 if self._tmp_output_file: | 108 if self._tmp_output_file: |
| 104 self._tmp_output_file.close() | 109 self._tmp_output_file.close() |
| 105 self._tmp_output_file = None | 110 self._tmp_output_file = None |
| 106 | 111 |
| 107 def CreateForwarder(self, *port_pairs): | 112 def CreateForwarder(self, *port_pairs): |
| 108 return DoNothingForwarder(*port_pairs) | 113 return DoNothingForwarder(*port_pairs) |
| 109 | 114 |
| 115 def _GetChromeBranchNumber(self): | |
| 116 version = subprocess.check_output([self._executable, '--version']) | |
| 117 match = re.match('[^\d]+\s+\d+\.\d+\.(\d+)\.\d+.*', version) | |
| 118 assert match | |
| 119 return int(match.group(1)) | |
| 120 | |
| 110 class DoNothingForwarder(object): | 121 class DoNothingForwarder(object): |
| 111 def __init__(self, *port_pairs): | 122 def __init__(self, *port_pairs): |
| 112 self._host_port = port_pairs[0].local_port | 123 self._host_port = port_pairs[0].local_port |
| 113 | 124 |
| 114 @property | 125 @property |
| 115 def url(self): | 126 def url(self): |
| 116 assert self._host_port | 127 assert self._host_port |
| 117 return 'http://localhost:%i' % self._host_port | 128 return 'http://localhost:%i' % self._host_port |
| 118 | 129 |
| 119 def Close(self): | 130 def Close(self): |
| 120 self._host_port = None | 131 self._host_port = None |
| OLD | NEW |