OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import inspect | 4 import inspect |
5 import os | 5 import os |
6 import socket | 6 import socket |
7 import time | 7 import time |
8 | 8 |
9 class TimeoutException(Exception): | 9 class TimeoutException(Exception): |
10 pass | 10 pass |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 var _element = _findElement(document, \"""" + text + """\"); | 63 var _element = _findElement(document, \"""" + text + """\"); |
64 return callback_function(_element); | 64 return callback_function(_element); |
65 })();""" | 65 })();""" |
66 return tab.EvaluateJavaScript(code) | 66 return tab.EvaluateJavaScript(code) |
67 | 67 |
68 class PortPair(object): | 68 class PortPair(object): |
69 def __init__(self, local_port, remote_port): | 69 def __init__(self, local_port, remote_port): |
70 self.local_port = local_port | 70 self.local_port = local_port |
71 self.remote_port = remote_port | 71 self.remote_port = remote_port |
72 | 72 |
| 73 class DoNothingForwarder(object): |
| 74 def __init__(self, *port_pairs): |
| 75 self._host_port = port_pairs[0].local_port |
| 76 |
| 77 @property |
| 78 def url(self): |
| 79 assert self._host_port |
| 80 return 'http://127.0.0.1:%i' % self._host_port |
| 81 |
| 82 def Close(self): |
| 83 self._host_port = None |
| 84 |
73 def GetAvailableLocalPort(): | 85 def GetAvailableLocalPort(): |
74 tmp = socket.socket() | 86 tmp = socket.socket() |
75 tmp.bind(('', 0)) | 87 tmp.bind(('', 0)) |
76 port = tmp.getsockname()[1] | 88 port = tmp.getsockname()[1] |
77 tmp.close() | 89 tmp.close() |
78 | 90 |
79 return port | 91 return port |
80 | 92 |
81 def CloseConnections(tab): | 93 def CloseConnections(tab): |
82 """Closes all TCP sockets held open by the browser.""" | 94 """Closes all TCP sockets held open by the browser.""" |
83 try: | 95 try: |
84 tab.ExecuteJavaScript("""window.chrome && chrome.benchmarking && | 96 tab.ExecuteJavaScript("""window.chrome && chrome.benchmarking && |
85 chrome.benchmarking.closeConnections()""") | 97 chrome.benchmarking.closeConnections()""") |
86 except Exception: | 98 except Exception: |
87 pass | 99 pass |
OLD | NEW |