| 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 subprocess as subprocess | 5 import subprocess as subprocess |
| 6 import shutil | 6 import shutil |
| 7 import tempfile | 7 import tempfile |
| 8 | 8 |
| 9 from telemetry import browser_backend | 9 from telemetry import browser_backend |
| 10 from telemetry import util | 10 from telemetry import util |
| 11 | 11 |
| 12 DEFAULT_PORT = 9273 | 12 DEFAULT_PORT = 9273 |
| 13 | 13 |
| 14 class DesktopBrowserBackend(browser_backend.BrowserBackend): | 14 class DesktopBrowserBackend(browser_backend.BrowserBackend): |
| 15 """The backend for controlling a locally-executed browser instance, on Linux, | 15 """The backend for controlling a locally-executed browser instance, on Linux, |
| 16 Mac or Windows. | 16 Mac or Windows. |
| 17 """ | 17 """ |
| 18 def __init__(self, options, executable, is_content_shell): | 18 def __init__(self, options, executable, is_content_shell): |
| 19 super(DesktopBrowserBackend, self).__init__(is_content_shell, options) | 19 super(DesktopBrowserBackend, self).__init__(is_content_shell, options) |
| 20 | 20 |
| 21 # Initialize fields so that an explosion during init doesn't break in Close. | 21 # Initialize fields so that an explosion during init doesn't break in Close. |
| 22 self._proc = None | 22 self._proc = None |
| 23 self._tmpdir = None | 23 self._tmpdir = None |
| 24 self._tmp_output_file = None | 24 self._tmp_output_file = None |
| 25 | 25 |
| 26 self._executable = executable | 26 self._executable = executable |
| 27 if not self._executable: | 27 if not self._executable: |
| 28 raise Exception('Cannot create browser, no executable found!') | 28 raise Exception('Cannot create browser, no executable found!') |
| 29 | 29 |
| 30 if len(options.extensions_to_load) > 0 and is_content_shell: |
| 31 raise Exception('Cannot load extensions for content shell!') |
| 32 |
| 30 self._port = DEFAULT_PORT | 33 self._port = DEFAULT_PORT |
| 31 args = [self._executable] | 34 args = [self._executable] |
| 32 args.extend(self.GetBrowserStartupArgs()) | 35 args.extend(self.GetBrowserStartupArgs()) |
| 33 if not options.show_stdout: | 36 if not options.show_stdout: |
| 34 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) | 37 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) |
| 35 self._proc = subprocess.Popen( | 38 self._proc = subprocess.Popen( |
| 36 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) | 39 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) |
| 37 else: | 40 else: |
| 38 self._proc = subprocess.Popen(args) | 41 self._proc = subprocess.Popen(args) |
| 39 | 42 |
| 40 try: | 43 try: |
| 41 self._WaitForBrowserToComeUp() | 44 self._WaitForBrowserToComeUp() |
| 42 self._PostBrowserStartupInitialization() | 45 self._PostBrowserStartupInitialization() |
| 43 except: | 46 except: |
| 44 self.Close() | 47 self.Close() |
| 45 raise | 48 raise |
| 46 | 49 |
| 47 def GetBrowserStartupArgs(self): | 50 def GetBrowserStartupArgs(self): |
| 48 args = super(DesktopBrowserBackend, self).GetBrowserStartupArgs() | 51 args = super(DesktopBrowserBackend, self).GetBrowserStartupArgs() |
| 49 args.append('--remote-debugging-port=%i' % self._port) | 52 args.append('--remote-debugging-port=%i' % self._port) |
| 50 args.append('--window-size=1280,1024') | 53 args.append('--window-size=1280,1024') |
| 51 args.append('--enable-benchmarking') | 54 args.append('--enable-benchmarking') |
| 52 if not self.options.dont_override_profile: | 55 if not self.options.dont_override_profile: |
| 53 self._tmpdir = tempfile.mkdtemp() | 56 self._tmpdir = tempfile.mkdtemp() |
| 54 args.append('--user-data-dir=%s' % self._tmpdir) | 57 args.append('--user-data-dir=%s' % self._tmpdir) |
| 58 extensions = ','.join( |
| 59 [extension.path for extension in self.options.extensions_to_load |
| 60 if not extension.is_component]) |
| 61 component_extensions = ','.join( |
| 62 [extension.path for extension in self.options.extensions_to_load |
| 63 if extension.is_component]) |
| 64 if len(extensions) > 0: |
| 65 args.append('--load-extension=%s' % extensions) |
| 66 if len(component_extensions) > 0: |
| 67 args.append('--load-component-extension=%s' % component_extensions) |
| 68 |
| 55 return args | 69 return args |
| 56 | 70 |
| 57 def IsBrowserRunning(self): | 71 def IsBrowserRunning(self): |
| 58 return self._proc.poll() == None | 72 return self._proc.poll() == None |
| 59 | 73 |
| 60 def GetStandardOutput(self): | 74 def GetStandardOutput(self): |
| 61 assert self._tmp_output_file, "Can't get standard output with show_stdout" | 75 assert self._tmp_output_file, "Can't get standard output with show_stdout" |
| 62 self._tmp_output_file.flush() | 76 self._tmp_output_file.flush() |
| 63 try: | 77 try: |
| 64 with open(self._tmp_output_file.name) as f: | 78 with open(self._tmp_output_file.name) as f: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 def __init__(self, *port_pairs): | 126 def __init__(self, *port_pairs): |
| 113 self._host_port = port_pairs[0].local_port | 127 self._host_port = port_pairs[0].local_port |
| 114 | 128 |
| 115 @property | 129 @property |
| 116 def url(self): | 130 def url(self): |
| 117 assert self._host_port | 131 assert self._host_port |
| 118 return 'http://localhost:%i' % self._host_port | 132 return 'http://localhost:%i' % self._host_port |
| 119 | 133 |
| 120 def Close(self): | 134 def Close(self): |
| 121 self._host_port = None | 135 self._host_port = None |
| OLD | NEW |