| OLD | NEW |
| 1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2016 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 | 4 |
| 5 """Library handling DevTools websocket interaction. | 5 """Library handling DevTools websocket interaction. |
| 6 """ | 6 """ |
| 7 | 7 |
| 8 import datetime | 8 import datetime |
| 9 import httplib | 9 import httplib |
| 10 import json | 10 import json |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 281 |
| 282 def ExecuteJavaScript(self, expression): | 282 def ExecuteJavaScript(self, expression): |
| 283 """Run JavaScript expression. | 283 """Run JavaScript expression. |
| 284 | 284 |
| 285 Args: | 285 Args: |
| 286 expression: JavaScript expression to run. | 286 expression: JavaScript expression to run. |
| 287 | 287 |
| 288 Returns: | 288 Returns: |
| 289 The return value from the JavaScript expression. | 289 The return value from the JavaScript expression. |
| 290 """ | 290 """ |
| 291 # Note: Clients may be tempted to do naive string interpolation to inject |
| 292 # Python values into the JavaScript expression, which could lead to syntax |
| 293 # errors during evaluation (e.g. injecting strings with special characters). |
| 294 # If this becomes an issue, consider extending the interface of this method |
| 295 # as in: https://github.com/catapult-project/catapult/issues/3028 |
| 291 response = self.SyncRequest('Runtime.evaluate', { | 296 response = self.SyncRequest('Runtime.evaluate', { |
| 292 'expression': expression, | 297 'expression': expression, |
| 293 'returnByValue': True}) | 298 'returnByValue': True}) |
| 294 if 'error' in response: | 299 if 'error' in response: |
| 295 raise Exception(response['error']['message']) | 300 raise Exception(response['error']['message']) |
| 296 if 'wasThrown' in response['result'] and response['result']['wasThrown']: | 301 if 'wasThrown' in response['result'] and response['result']['wasThrown']: |
| 297 raise Exception(response['error']['result']['description']) | 302 raise Exception(response['error']['result']['description']) |
| 298 if response['result']['result']['type'] == 'undefined': | 303 if response['result']['result']['type'] == 'undefined': |
| 299 return None | 304 return None |
| 300 return response['result']['result']['value'] | 305 return response['result']['result']['value'] |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 json_data: (dict) Parsed from a JSON file using the json module. | 485 json_data: (dict) Parsed from a JSON file using the json module. |
| 481 | 486 |
| 482 Returns: | 487 Returns: |
| 483 a Track instance. | 488 a Track instance. |
| 484 """ | 489 """ |
| 485 # There is no sensible way to deserialize this abstract class, but | 490 # There is no sensible way to deserialize this abstract class, but |
| 486 # subclasses are not required to define a deserialization method. For | 491 # subclasses are not required to define a deserialization method. For |
| 487 # example, for testing we have a FakeRequestTrack which is never | 492 # example, for testing we have a FakeRequestTrack which is never |
| 488 # deserialized; instead fake instances are deserialized as RequestTracks. | 493 # deserialized; instead fake instances are deserialized as RequestTracks. |
| 489 assert False | 494 assert False |
| OLD | NEW |