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): | 19 def __init__(self, options, executable, is_content_shell, use_login): |
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 |
29 self._executable = executable | 31 self._executable = executable |
30 if not self._executable: | 32 if not self._executable: |
31 raise Exception('Cannot create browser, no executable found!') | 33 raise Exception('Cannot create browser, no executable found!') |
32 | 34 |
33 if len(options.extensions_to_load) > 0 and is_content_shell: | 35 if len(options.extensions_to_load) > 0 and is_content_shell: |
34 raise browser_backend.ExtensionsNotSupportedException( | 36 raise browser_backend.ExtensionsNotSupportedException( |
35 'Content shell does not support extensions.') | 37 'Content shell does not support extensions.') |
36 | 38 |
37 self._port = util.GetAvailableLocalPort() | 39 self._port = util.GetAvailableLocalPort() |
38 self._supports_net_benchmarking = True | 40 self._supports_net_benchmarking = True |
39 self._LaunchBrowser(options) | 41 self._LaunchBrowser(options) |
40 | 42 |
41 # For old chrome versions, might have to relaunch to have the | 43 # For old chrome versions, might have to relaunch to have the |
42 # correct benchmarking switch. | 44 # correct benchmarking switch. |
43 if self._chrome_branch_number < 1418: | 45 if self._chrome_branch_number < 1418: |
44 self.Close() | 46 self.Close() |
45 self._supports_net_benchmarking = False | 47 self._supports_net_benchmarking = False |
46 self._LaunchBrowser(options) | 48 self._LaunchBrowser(options) |
47 | 49 |
48 if self.options.cros_desktop: | 50 if self._use_login: |
49 cros_util.NavigateLogin(self) | 51 cros_util.NavigateLogin(self) |
50 | 52 |
51 def _LaunchBrowser(self, options): | 53 def _LaunchBrowser(self, options): |
52 args = [self._executable] | 54 args = [self._executable] |
53 args.extend(self.GetBrowserStartupArgs()) | 55 args.extend(self.GetBrowserStartupArgs()) |
54 if not options.show_stdout: | 56 if not options.show_stdout: |
55 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) | 57 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) |
56 self._proc = subprocess.Popen( | 58 self._proc = subprocess.Popen( |
57 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) | 59 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) |
58 else: | 60 else: |
(...skipping 17 matching lines...) Expand all Loading... |
76 args.append('--enable-benchmarking') | 78 args.append('--enable-benchmarking') |
77 if not self.options.dont_override_profile: | 79 if not self.options.dont_override_profile: |
78 self._tmpdir = tempfile.mkdtemp() | 80 self._tmpdir = tempfile.mkdtemp() |
79 if self.options.profile_dir: | 81 if self.options.profile_dir: |
80 if self.is_content_shell: | 82 if self.is_content_shell: |
81 logging.critical('Profiles cannot be used with content shell') | 83 logging.critical('Profiles cannot be used with content shell') |
82 sys.exit(1) | 84 sys.exit(1) |
83 shutil.rmtree(self._tmpdir) | 85 shutil.rmtree(self._tmpdir) |
84 shutil.copytree(self.options.profile_dir, self._tmpdir) | 86 shutil.copytree(self.options.profile_dir, self._tmpdir) |
85 args.append('--user-data-dir=%s' % self._tmpdir) | 87 args.append('--user-data-dir=%s' % self._tmpdir) |
86 if self.options.cros_desktop: | 88 if self._use_login: |
87 ext_path = os.path.join(os.path.dirname(__file__), 'chromeos_login_ext') | 89 ext_path = os.path.join(os.path.dirname(__file__), 'chromeos_login_ext') |
88 args.extend(['--login-manager', '--login-profile=user', | 90 args.extend(['--login-manager', '--login-profile=user', |
89 '--stub-cros', '--login-screen=login', | 91 '--stub-cros', '--login-screen=login', |
90 '--auth-ext-path=%s' % ext_path]) | 92 '--auth-ext-path=%s' % ext_path]) |
91 return args | 93 return args |
92 | 94 |
93 @property | 95 @property |
94 def pid(self): | 96 def pid(self): |
95 if self._proc: | 97 if self._proc: |
96 return self._proc.pid | 98 return self._proc.pid |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if self._tmpdir and os.path.exists(self._tmpdir): | 144 if self._tmpdir and os.path.exists(self._tmpdir): |
143 shutil.rmtree(self._tmpdir, ignore_errors=True) | 145 shutil.rmtree(self._tmpdir, ignore_errors=True) |
144 self._tmpdir = None | 146 self._tmpdir = None |
145 | 147 |
146 if self._tmp_output_file: | 148 if self._tmp_output_file: |
147 self._tmp_output_file.close() | 149 self._tmp_output_file.close() |
148 self._tmp_output_file = None | 150 self._tmp_output_file = None |
149 | 151 |
150 def CreateForwarder(self, *port_pairs): | 152 def CreateForwarder(self, *port_pairs): |
151 return browser_backend.DoNothingForwarder(*port_pairs) | 153 return browser_backend.DoNothingForwarder(*port_pairs) |
OLD | NEW |