コード例 #1
0
    def MeasureMemory(self, deterministic_mode=False):
        """Add a memory measurement to the trace being recorded.

    Behaves as a no-op if tracing is not enabled.

    TODO(perezju): Also behave as a no-op if tracing is enabled but
    memory-infra is not.

    Args:
      deterministic_mode: A boolean indicating whether to attempt or not to
          control the environment (force GCs, clear caches) before making the
          measurement in an attempt to obtain more deterministic results.

    Returns:
      GUID of the generated dump if one was triggered, None otherwise.
    """
        if not self.tab.browser.platform.tracing_controller.is_tracing_running:
            logging.warning(
                'Tracing is off. No memory dumps are being recorded.')
            return None
        if deterministic_mode:
            self.Wait(_MEMORY_DUMP_WAIT_TIME)
            self.ForceGarbageCollection()
        dump_id = self.tab.browser.DumpMemory()
        if not dump_id:
            raise exceptions.StoryActionError('Unable to obtain memory dump')
        return dump_id
コード例 #2
0
    def _Scroll(self, action_runner, distance, step_size):
        """ This function scrolls the webpage by the given scroll distance in
    multiple steps, where each step (except the last one) has the given size.

    If scrolling gets stuck, the functions retries scrolling MAX_SCROLL_RETRIES
    times waiting TIME_BEFORE_SCROLL_RETRY_IN_SECONDS seconds between retries.
    """
        remaining = distance - action_runner.EvaluateJavaScript(
            'window.scrollY')
        retry_count = 0
        # Scroll until the window.scrollY is within 1 pixel of the target distance.
        while remaining > 1:
            action_runner.ScrollPage(distance=min(remaining, step_size) + 1)
            new_remaining = (
                distance - action_runner.EvaluateJavaScript('window.scrollY'))
            if remaining <= new_remaining:
                # Scrolling is stuck. This can happen if the page is loading
                # resources. Give the page some time and retry scrolling.
                if retry_count == self.MAX_SCROLL_RETRIES:
                    raise exceptions.StoryActionError('Scrolling stuck at %d' %
                                                      remaining)
                retry_count += 1
                action_runner.Wait(self.TIME_BEFORE_SCROLL_RETRY_IN_SECONDS)
            else:
                retry_count = 0
                remaining = new_remaining
コード例 #3
0
 def __init__(self, inspector_socket, timeout):
     self._websocket = inspector_socket
     self._websocket.RegisterDomain('ServiceWorker', self._OnNotification)
     # ServiceWorker.enable RPC must be called before calling any other methods
     # in ServiceWorker domain.
     res = self._websocket.SyncRequest({'method': 'ServiceWorker.enable'},
                                       timeout)
     if 'error' in res:
         raise exceptions.StoryActionError(res['error']['message'])
コード例 #4
0
 def StopAllWorkers(self, timeout):
     res = self._websocket.SyncRequest(
         {'method': 'ServiceWorker.stopAllWorkers'}, timeout)
     if 'error' in res:
         code = res['error']['code']
         if code == inspector_websocket.InspectorWebsocket.METHOD_NOT_FOUND_CODE:
             raise NotImplementedError(
                 'DevTools method ServiceWorker.stopAllWorkers is not supported by '
                 'this browser.')
         raise exceptions.StoryActionError(res['error']['message'])
コード例 #5
0
 def ClearDataForOrigin(self, url, timeout):
     res = self._websocket.SyncRequest(
         {
             'method': 'Storage.clearDataForOrigin',
             'params': {
                 'origin': url,
                 'storageTypes': 'all',
             }
         }, timeout)
     if 'error' in res:
         raise exceptions.StoryActionError(res['error']['message'])
コード例 #6
0
ファイル: tab.py プロジェクト: zhaojunmin/catapult
    def ClearDataForOrigin(self, url, timeout=DEFAULT_TAB_TIMEOUT):
        """Clears storage data for the origin of url.

    With assigning 'all' to params.storageTypes, Storage.clearDataForOrigin
    clears all storage of app cache, cookies, file systems, indexed db,
    local storage, shader cache, web sql, service workers and cache storage.
    See StorageHandler::ClearDataForOrigin() for more details.

    Raises:
      exceptions.StoryActionError
    """
        res = self._inspector_backend._websocket.SyncRequest(
            {
                'method': 'Storage.clearDataForOrigin',
                'params': {
                    'origin': url,
                    'storageTypes': 'all'
                }
            }, timeout)
        if 'error' in res:
            raise exceptions.StoryActionError(res['error']['message'])
コード例 #7
0
 def ExitOverviewMode(self):
     if not self._tab.browser.supports_overview_mode:
         raise exceptions.StoryActionError('Overview mode is not supported')
     self._tab.browser.ExitOverviewMode()
コード例 #8
0
 def ExitOverviewMode(self, timeout):  # pylint: disable=unused-argument
     raise exceptions.StoryActionError('Overview mode is not supported')
コード例 #9
0
 def GetUIDevtoolsBackend(self, port):  # pylint: disable=unused-argument
     raise exceptions.StoryActionError('UI Devtools not supported')
コード例 #10
0
 def SetDownloadBehavior(self, behavior, downloadPath, timeout):  # pylint: disable=unused-argument
     raise exceptions.StoryActionError(
         'Set download behavior not supported')
コード例 #11
0
 def ExecuteBrowserCommand(self, command_id, timeout):  # pylint: disable=unused-argument
     raise exceptions.StoryActionError(
         'Execute browser command not supported')