예제 #1
0
 def _StartConnection(self, connection):
     """This should be called after opening an appropriate connection."""
     if self._emulated_device:
         self._metadata.update(
             emulation.SetUpDeviceEmulationAndReturnMetadata(
                 connection, self._emulated_device))
     if self._emulated_network:
         emulation.SetUpNetworkEmulation(connection,
                                         **self._emulated_network)
         self._metadata.update(self._emulated_network)
     self._metadata.update(date=datetime.datetime.utcnow().isoformat(),
                           seconds_since_epoch=time.time())
예제 #2
0
 def _StartConnection(self, connection):
   """This should be called after opening an appropriate connection."""
   if self._emulated_device:
     self._metadata.update(emulation.SetUpDeviceEmulationAndReturnMetadata(
         connection, self._emulated_device))
   if self._network_name:
     network_condition = emulation.NETWORK_CONDITIONS[self._network_name]
     logging.info('Set up network emulation %s (latency=%dms, down=%d, up=%d)'
         % (self._network_name, network_condition['latency'],
             network_condition['download'], network_condition['upload']))
     emulation.SetUpNetworkEmulation(connection, **network_condition)
     self._metadata['network_emulation'] = copy.copy(network_condition)
     self._metadata['network_emulation']['name'] = self._network_name
   else:
     self._metadata['network_emulation'] = \
         {k: 'disabled' for k in ['name', 'download', 'upload', 'latency']}
   self._metadata.update(self.METADATA_GATHERER.GetMetadata())
   logging.info('Devtools connection success')
예제 #3
0
 def testSetUpDevice(self):
   registry = StringIO("""{
     "extensions": [
         {
             "type": "emulated-device",
             "device": {
                 "show-by-default": false,
                 "title": "mattPhone" ,
                 "screen": {
                     "horizontal": {
                         "width": 480,
                         "height": 320
                     },
                     "device-pixel-ratio": 2,
                     "vertical": {
                         "width": 320,
                         "height": 480
                     }
                 },
                 "capabilities": [
                     "touch",
                     "mobile"
                 ],
                 "user-agent": "James Bond"
             }
         } ]}""")
   devices = emulation.LoadEmulatedDevices(registry)
   connection = test_utils.MockConnection(self)
   connection.ExpectSyncRequest({'result': True}, 'Emulation.canEmulate')
   metadata = emulation.SetUpDeviceEmulationAndReturnMetadata(
       connection, devices['mattPhone'])
   self.assertEqual(320, metadata['width'])
   self.assertEqual('James Bond', metadata['userAgent'])
   self.assertTrue(connection.AllExpectationsUsed())
   self.assertEqual('Emulation.setDeviceMetricsOverride',
                    connection.no_response_requests_seen[0][0])