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 logging | 4 import logging |
5 import os | 5 import os |
6 import subprocess as subprocess | 6 import subprocess as subprocess |
7 import shutil | 7 import shutil |
8 import sys | 8 import sys |
9 import tempfile | 9 import tempfile |
10 | 10 |
11 from telemetry.core import util | 11 from telemetry.core import util |
12 from telemetry.core.chrome import browser_backend | 12 from telemetry.core.chrome import browser_backend |
13 from telemetry.core.chrome import cros_util | 13 from telemetry.core.chrome import cros_util |
14 | 14 |
15 class DesktopBrowserBackend(browser_backend.BrowserBackend): | 15 class DesktopBrowserBackend(browser_backend.BrowserBackend): |
16 """The backend for controlling a locally-executed browser instance, on Linux, | 16 """The backend for controlling a locally-executed browser instance, on Linux, |
17 Mac or Windows. | 17 Mac or Windows. |
18 """ | 18 """ |
19 def __init__(self, options, executable, is_content_shell, use_login): | 19 def __init__(self, options, executable, is_content_shell): |
20 super(DesktopBrowserBackend, self).__init__( | 20 super(DesktopBrowserBackend, self).__init__( |
21 is_content_shell=is_content_shell, | 21 is_content_shell=is_content_shell, |
22 supports_extensions=not is_content_shell, options=options) | 22 supports_extensions=not is_content_shell, options=options) |
23 | 23 |
24 # Initialize fields so that an explosion during init doesn't break in Close. | 24 # Initialize fields so that an explosion during init doesn't break in Close. |
25 self._proc = None | 25 self._proc = None |
26 self._tmpdir = None | 26 self._tmpdir = None |
27 self._tmp_output_file = None | 27 self._tmp_output_file = None |
28 | 28 |
29 self._use_login = use_login | |
30 | |
31 self._executable = executable | 29 self._executable = executable |
32 if not self._executable: | 30 if not self._executable: |
33 raise Exception('Cannot create browser, no executable found!') | 31 raise Exception('Cannot create browser, no executable found!') |
34 | 32 |
35 if len(options.extensions_to_load) > 0 and is_content_shell: | 33 if len(options.extensions_to_load) > 0 and is_content_shell: |
36 raise browser_backend.ExtensionsNotSupportedException( | 34 raise browser_backend.ExtensionsNotSupportedException( |
37 'Content shell does not support extensions.') | 35 'Content shell does not support extensions.') |
38 | 36 |
39 self._port = util.GetAvailableLocalPort() | 37 self._port = util.GetAvailableLocalPort() |
40 self._supports_net_benchmarking = True | 38 self._supports_net_benchmarking = True |
41 self._LaunchBrowser(options) | 39 self._LaunchBrowser(options) |
42 | 40 |
43 # For old chrome versions, might have to relaunch to have the | 41 # For old chrome versions, might have to relaunch to have the |
44 # correct benchmarking switch. | 42 # correct benchmarking switch. |
45 if self._chrome_branch_number < 1418: | 43 if self._chrome_branch_number < 1418: |
46 self.Close() | 44 self.Close() |
47 self._supports_net_benchmarking = False | 45 self._supports_net_benchmarking = False |
48 self._LaunchBrowser(options) | 46 self._LaunchBrowser(options) |
49 | 47 |
50 if self._use_login: | 48 if self.options.cros_desktop: |
51 cros_util.NavigateLogin(self) | 49 cros_util.NavigateLogin(self) |
52 | 50 |
53 def _LaunchBrowser(self, options): | 51 def _LaunchBrowser(self, options): |
54 args = [self._executable] | 52 args = [self._executable] |
55 args.extend(self.GetBrowserStartupArgs()) | 53 args.extend(self.GetBrowserStartupArgs()) |
56 if not options.show_stdout: | 54 if not options.show_stdout: |
57 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) | 55 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) |
58 self._proc = subprocess.Popen( | 56 self._proc = subprocess.Popen( |
59 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) | 57 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) |
60 else: | 58 else: |
(...skipping 17 matching lines...) Expand all Loading... |
78 args.append('--enable-benchmarking') | 76 args.append('--enable-benchmarking') |
79 if not self.options.dont_override_profile: | 77 if not self.options.dont_override_profile: |
80 self._tmpdir = tempfile.mkdtemp() | 78 self._tmpdir = tempfile.mkdtemp() |
81 if self.options.profile_dir: | 79 if self.options.profile_dir: |
82 if self.is_content_shell: | 80 if self.is_content_shell: |
83 logging.critical('Profiles cannot be used with content shell') | 81 logging.critical('Profiles cannot be used with content shell') |
84 sys.exit(1) | 82 sys.exit(1) |
85 shutil.rmtree(self._tmpdir) | 83 shutil.rmtree(self._tmpdir) |
86 shutil.copytree(self.options.profile_dir, self._tmpdir) | 84 shutil.copytree(self.options.profile_dir, self._tmpdir) |
87 args.append('--user-data-dir=%s' % self._tmpdir) | 85 args.append('--user-data-dir=%s' % self._tmpdir) |
88 if self._use_login: | 86 if self.options.cros_desktop: |
89 ext_path = os.path.join(os.path.dirname(__file__), 'chromeos_login_ext') | 87 ext_path = os.path.join(os.path.dirname(__file__), 'chromeos_login_ext') |
90 args.extend(['--login-manager', '--login-profile=user', | 88 args.extend(['--login-manager', '--login-profile=user', |
91 '--stub-cros', '--login-screen=login', | 89 '--stub-cros', '--login-screen=login', |
92 '--auth-ext-path=%s' % ext_path]) | 90 '--auth-ext-path=%s' % ext_path]) |
93 return args | 91 return args |
94 | 92 |
95 @property | 93 @property |
96 def pid(self): | 94 def pid(self): |
97 if self._proc: | 95 if self._proc: |
98 return self._proc.pid | 96 return self._proc.pid |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 if self._tmpdir and os.path.exists(self._tmpdir): | 142 if self._tmpdir and os.path.exists(self._tmpdir): |
145 shutil.rmtree(self._tmpdir, ignore_errors=True) | 143 shutil.rmtree(self._tmpdir, ignore_errors=True) |
146 self._tmpdir = None | 144 self._tmpdir = None |
147 | 145 |
148 if self._tmp_output_file: | 146 if self._tmp_output_file: |
149 self._tmp_output_file.close() | 147 self._tmp_output_file.close() |
150 self._tmp_output_file = None | 148 self._tmp_output_file = None |
151 | 149 |
152 def CreateForwarder(self, *port_pairs): | 150 def CreateForwarder(self, *port_pairs): |
153 return browser_backend.DoNothingForwarder(*port_pairs) | 151 return browser_backend.DoNothingForwarder(*port_pairs) |
OLD | NEW |