Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: tools/telemetry/telemetry/desktop_browser_backend.py

Issue 11882033: Telemetry support for extensions. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: wait for document ready state Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class DesktopBrowserBackend(browser_backend.BrowserBackend): 12 class DesktopBrowserBackend(browser_backend.BrowserBackend):
13 """The backend for controlling a locally-executed browser instance, on Linux, 13 """The backend for controlling a locally-executed browser instance, on Linux,
14 Mac or Windows. 14 Mac or Windows.
15 """ 15 """
16 def __init__(self, options, executable, is_content_shell): 16 def __init__(self, options, executable, is_content_shell):
17 super(DesktopBrowserBackend, self).__init__(is_content_shell, options) 17 super(DesktopBrowserBackend, self).__init__(is_content_shell, options)
18 18
19 # Initialize fields so that an explosion during init doesn't break in Close. 19 # Initialize fields so that an explosion during init doesn't break in Close.
20 self._proc = None 20 self._proc = None
21 self._tmpdir = None 21 self._tmpdir = None
22 self._tmp_output_file = None 22 self._tmp_output_file = None
23 23
24 self._executable = executable 24 self._executable = executable
25 if not self._executable: 25 if not self._executable:
26 raise Exception('Cannot create browser, no executable found!') 26 raise Exception('Cannot create browser, no executable found!')
27 27
28 if len(options.extensions_to_load) > 0 and is_content_shell:
29 raise Exception('Cannot load extensions for content shell!')
30
28 self._port = util.GetAvailableLocalPort() 31 self._port = util.GetAvailableLocalPort()
29 32
30 args = [self._executable] 33 args = [self._executable]
31 args.extend(self.GetBrowserStartupArgs()) 34 args.extend(self.GetBrowserStartupArgs())
32 if not options.show_stdout: 35 if not options.show_stdout:
33 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0) 36 self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0)
34 self._proc = subprocess.Popen( 37 self._proc = subprocess.Popen(
35 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT) 38 args, stdout=self._tmp_output_file, stderr=subprocess.STDOUT)
36 else: 39 else:
37 self._proc = subprocess.Popen(args) 40 self._proc = subprocess.Popen(args)
38 41
39 try: 42 try:
40 self._WaitForBrowserToComeUp() 43 self._WaitForBrowserToComeUp()
41 self._PostBrowserStartupInitialization() 44 self._PostBrowserStartupInitialization()
42 except: 45 except:
43 self.Close() 46 self.Close()
44 raise 47 raise
45 48
46 def GetBrowserStartupArgs(self): 49 def GetBrowserStartupArgs(self):
47 args = super(DesktopBrowserBackend, self).GetBrowserStartupArgs() 50 args = super(DesktopBrowserBackend, self).GetBrowserStartupArgs()
48 args.append('--remote-debugging-port=%i' % self._port) 51 args.append('--remote-debugging-port=%i' % self._port)
49 args.append('--window-size=1280,1024') 52 args.append('--window-size=1280,1024')
50 args.append('--enable-benchmarking') 53 args.append('--enable-benchmarking')
51 if not self.options.dont_override_profile: 54 if not self.options.dont_override_profile:
52 self._tmpdir = tempfile.mkdtemp() 55 self._tmpdir = tempfile.mkdtemp()
53 args.append('--user-data-dir=%s' % self._tmpdir) 56 args.append('--user-data-dir=%s' % self._tmpdir)
57 extensions = ','.join(
58 [extension.path for extension in self.options.extensions_to_load
59 if not extension.is_component])
60 component_extensions = ','.join(
61 [extension.path for extension in self.options.extensions_to_load
62 if extension.is_component])
63 if len(extensions) > 0:
64 args.append('--load-extension=%s' % extensions)
65 if len(component_extensions) > 0:
66 args.append('--load-component-extension=%s' % component_extensions)
67
54 return args 68 return args
55 69
56 def IsBrowserRunning(self): 70 def IsBrowserRunning(self):
57 return self._proc.poll() == None 71 return self._proc.poll() == None
58 72
59 def GetStandardOutput(self): 73 def GetStandardOutput(self):
60 assert self._tmp_output_file, "Can't get standard output with show_stdout" 74 assert self._tmp_output_file, "Can't get standard output with show_stdout"
61 self._tmp_output_file.flush() 75 self._tmp_output_file.flush()
62 try: 76 try:
63 with open(self._tmp_output_file.name) as f: 77 with open(self._tmp_output_file.name) as f:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 def __init__(self, *port_pairs): 125 def __init__(self, *port_pairs):
112 self._host_port = port_pairs[0].local_port 126 self._host_port = port_pairs[0].local_port
113 127
114 @property 128 @property
115 def url(self): 129 def url(self):
116 assert self._host_port 130 assert self._host_port
117 return 'http://localhost:%i' % self._host_port 131 return 'http://localhost:%i' % self._host_port
118 132
119 def Close(self): 133 def Close(self):
120 self._host_port = None 134 self._host_port = None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698