Beispiel #1
0
 def _NavigateAndGetHTTPResponseEvents(self, page):
   network = inspector_network.InspectorNetwork(
       self._tab._inspector_backend._websocket)
   network.timeline_recorder.Start()
   self.Navigate(page)
   timeline_model = network.timeline_recorder.Stop()
   self.assertTrue(timeline_model)
   return timeline_model.GetAllEventsOfName('HTTPResponse')
    def _LogPageLoadInternal(self, url, clear_cache):
        """Returns the collection of requests made to load a given URL.

    Assumes that DevTools is available on http://localhost:DEVTOOLS_PORT.

    Args:
      url: URL to load.
      clear_cache: Whether to clear the HTTP cache.

    Returns:
      [inspector_network.InspectorNetworkResponseData, ...]
    """
        self._main_frame_id = None
        self._please_stop = False
        r = httplib.HTTPConnection(device_setup.DEVTOOLS_HOSTNAME,
                                   device_setup.DEVTOOLS_PORT)
        r.request('GET', '/json')
        response = r.getresponse()
        if response.status != 200:
            logging.error('Cannot connect to the remote target.')
            return None
        json_response = json.loads(response.read())
        r.close()
        websocket_url = json_response[0]['webSocketDebuggerUrl']
        ws = inspector_websocket.InspectorWebsocket()
        ws.Connect(websocket_url)
        inspector = inspector_network.InspectorNetwork(ws)
        if clear_cache:
            inspector.ClearCache()
        ws.SyncRequest({'method': 'Page.enable'})
        ws.RegisterDomain('Page', self._PageDataReceived)
        inspector.StartMonitoringNetwork()
        ws.SendAndIgnoreResponse({
            'method': 'Page.navigate',
            'params': {
                'url': url
            }
        })
        while not self._please_stop:
            try:
                ws.DispatchNotifications()
            except websocket.WebSocketTimeoutException as e:
                logging.warning('Exception: ' + str(e))
                break
        if not self._please_stop:
            logging.warning('Finished with timeout instead of page load')
        inspector.StopMonitoringNetwork()
        return inspector.GetResponseData()
Beispiel #3
0
  def testNetworkTiming(self):
    test = (
        'image_decoding.html', InspectorNetworkTabTest.TestCase(
            responses_count=2, subresources=['image.png'])
        )

    network = inspector_network.InspectorNetwork(
        self._tab._inspector_backend._websocket)
    network.StartMonitoringNetwork()
    self.Navigate(test[0])
    network.StopMonitoringNetwork()
    response_data = network.GetResponseData()
    path_to_response = {urlparse.urlparse(r.url).path: r
                        for r in response_data}
    self.assertTrue('/image_decoding.html' in path_to_response)
    self.assertTrue(
        path_to_response['/image_decoding.html'].timing['requestTime'] > 0)
    self.assertTrue(
        path_to_response['/image_decoding.html'].timing['loadingFinished'] > 0)
    self.assertTrue('/image.png' in path_to_response)
    self.assertTrue(
        path_to_response['/image.png'].timing['requestTime'] > 0)
    self.assertTrue(
        path_to_response['/image.png'].timing['loadingFinished'] > 0)
Beispiel #4
0
 def Start(self, page, tab):
   self._events = None
   network = inspector_network.InspectorNetwork(
       tab._inspector_backend._websocket)
   self._timeline_recorder = network.timeline_recorder
   self._timeline_recorder.Start()