from telemetry.core import wpr_modes
from telemetry.core import wpr_server
from telemetry.core.backends import browser_backend
-from telemetry.core.platform import tracing_category_filter
-from telemetry.core.platform import tracing_options
-from telemetry.core.platform.profiler import profiler_finder
class Browser(object):
with browser_to_create.Create() as browser:
... do all your operations on browser here
"""
- def __init__(self, backend, platform_backend):
+ def __init__(self, backend, platform_backend, archive_path,
+ append_to_existing_wpr, make_javascript_deterministic,
+ credentials_path):
assert platform_backend.platform != None
self._browser_backend = backend
self._platform_backend = platform_backend
self._wpr_server = None
- self._active_profilers = []
- self._profilers_states = {}
self._local_server_controller = local_server.LocalServerController(backend)
self._tabs = tab_list.TabList(backend.tab_list_backend)
self.credentials = browser_credentials.BrowserCredentials()
-
+ self.credentials.credentials_path = credentials_path
self._platform_backend.DidCreateBrowser(self, self._browser_backend)
+ self.SetReplayArchivePath(archive_path,
+ append_to_existing_wpr,
+ make_javascript_deterministic)
+
+ browser_options = self._browser_backend.browser_options
+ self.platform.FlushDnsCache()
+ if browser_options.clear_sytem_cache_for_browser_and_profile_on_start:
+ if self.platform.CanFlushIndividualFilesFromSystemCache():
+ self.platform.FlushSystemCacheForDirectory(
+ self._browser_backend.profile_directory)
+ self.platform.FlushSystemCacheForDirectory(
+ self._browser_backend.browser_directory)
+ else:
+ self.platform.FlushEntireSystemCache()
+
+ self._browser_backend.SetBrowser(self)
+ self._browser_backend.Start()
+ self._platform_backend.DidStartBrowser(self, self._browser_backend)
+
def __enter__(self):
- self.Start()
return self
def __exit__(self, *args):
'Extensions not supported')
return extension_dict.ExtensionDict(self._browser_backend.extension_backend)
- @property
- def supports_tracing(self):
- return self.platform.tracing_controller.IsChromeTracingSupported(self)
-
- def is_profiler_active(self, profiler_name):
- return profiler_name in [profiler.name() for
- profiler in self._active_profilers]
-
def _GetStatsCommon(self, pid_stats_function):
browser_pid = self._browser_backend.pid
result = {
del result['ProcessCount']
return result
- def StartProfiling(self, profiler_name, base_output_file):
- """Starts profiling using |profiler_name|. Results are saved to
- |base_output_file|.<process_name>."""
- assert not self._active_profilers, 'Already profiling. Must stop first.'
-
- profiler_class = profiler_finder.FindProfiler(profiler_name)
-
- if not profiler_class.is_supported(self._browser_backend.browser_type):
- raise Exception('The %s profiler is not '
- 'supported on this platform.' % profiler_name)
-
- if not profiler_class in self._profilers_states:
- self._profilers_states[profiler_class] = {}
-
- self._active_profilers.append(
- profiler_class(self._browser_backend, self._platform_backend,
- base_output_file, self._profilers_states[profiler_class]))
-
- def StopProfiling(self):
- """Stops all active profilers and saves their results.
-
- Returns:
- A list of filenames produced by the profiler.
- """
- output_files = []
- for profiler in self._active_profilers:
- output_files.extend(profiler.CollectProfile())
- self._active_profilers = []
- return output_files
-
-
- def StartTracing(self, custom_categories=None, timeout=10):
- """Note: this function is deprecated. Prefer platform.tracing_controller."""
- if not isinstance(custom_categories,
- tracing_category_filter.TracingCategoryFilter):
- category_filter = tracing_category_filter.TracingCategoryFilter(
- filter_string=custom_categories)
- else:
- category_filter = custom_categories
- options = tracing_options.TracingOptions()
- options.enable_chrome_trace = True
- return self.platform.tracing_controller.Start(
- options, category_filter, timeout)
-
- @property
- def is_tracing_running(self):
- """Note: this function is deprecated. Prefer platform.tracing_controller."""
- return self.platform.tracing_controller.is_tracing_running
-
- def StopTracing(self):
- """Note: this function is deprecated. Prefer platform.tracing_controller."""
- return self.platform.tracing_controller.Stop()
-
- def Start(self):
- browser_options = self._browser_backend.browser_options
- self.platform.FlushDnsCache()
- if browser_options.clear_sytem_cache_for_browser_and_profile_on_start:
- if self.platform.CanFlushIndividualFilesFromSystemCache():
- self.platform.FlushSystemCacheForDirectory(
- self._browser_backend.profile_directory)
- self.platform.FlushSystemCacheForDirectory(
- self._browser_backend.browser_directory)
- else:
- self.platform.FlushEntireSystemCache()
-
- self._browser_backend.SetBrowser(self)
- self._browser_backend.Start()
- self._platform_backend.DidStartBrowser(self, self._browser_backend)
-
def Close(self):
"""Closes this browser."""
- for profiler_class in self._profilers_states:
- profiler_class.WillCloseBrowser(self._browser_backend,
- self._platform_backend)
-
if self._browser_backend.IsBrowserRunning():
self._platform_backend.WillCloseBrowser(self, self._browser_backend)
See the documentation of the SystemInfo class for more details."""
return self._browser_backend.GetSystemInfo()
+
+ # TODO: Remove after call to Start() has been removed from
+ # related authotest files.
+ def Start(self):
+ pass