OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Start and stop Web Page Replay. | 6 """Start and stop Web Page Replay. |
7 | 7 |
8 Of the public module names, the following ones are key: | 8 Of the public module names, the following ones are key: |
9 CHROME_FLAGS: Chrome options to make it work with Web Page Replay. | 9 CHROME_FLAGS: Chrome options to make it work with Web Page Replay. |
10 ReplayServer: a class to start/stop Web Page Replay. | 10 ReplayServer: a class to start/stop Web Page Replay. |
11 """ | 11 """ |
12 | 12 |
13 import logging | 13 import logging |
14 import os | 14 import os |
15 import signal | 15 import signal |
16 import socket | |
16 import subprocess | 17 import subprocess |
17 import sys | 18 import sys |
18 import time | 19 import time |
19 import urllib | 20 import urllib |
20 | 21 |
22 def GetRandomOpenPort(): | |
bulach
2012/11/26 13:53:46
drive-by: can we re-use / improve this?
http://src
| |
23 tmp = socket.socket() | |
24 tmp.bind(('', 0)) | |
25 port = tmp.getsockname()[1] | |
26 tmp.close() | |
21 | 27 |
22 HTTP_PORT = 8080 | 28 return port |
23 HTTPS_PORT = 8413 | 29 |
30 HTTP_PORT = GetRandomOpenPort() | |
31 HTTPS_PORT = GetRandomOpenPort() | |
24 REPLAY_HOST='127.0.0.1' | 32 REPLAY_HOST='127.0.0.1' |
25 CHROME_FLAGS = [ | 33 CHROME_FLAGS = [ |
26 '--host-resolver-rules=MAP * %s,EXCLUDE localhost' % REPLAY_HOST, | 34 '--host-resolver-rules=MAP * %s,EXCLUDE localhost' % REPLAY_HOST, |
27 '--testing-fixed-http-port=%s' % HTTP_PORT, | 35 '--testing-fixed-http-port=%s' % HTTP_PORT, |
28 '--testing-fixed-https-port=%s' % HTTPS_PORT, | 36 '--testing-fixed-https-port=%s' % HTTPS_PORT, |
29 '--ignore-certificate-errors', | 37 '--ignore-certificate-errors', |
30 ] | 38 ] |
31 | 39 |
32 _CHROME_BASE_DIR = os.path.abspath(os.path.join( | 40 _CHROME_BASE_DIR = os.path.abspath(os.path.join( |
33 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) | 41 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 self.log_fh.close() | 180 self.log_fh.close() |
173 | 181 |
174 def __enter__(self): | 182 def __enter__(self): |
175 """Add support for with-statement.""" | 183 """Add support for with-statement.""" |
176 self.StartServer() | 184 self.StartServer() |
177 return self | 185 return self |
178 | 186 |
179 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): | 187 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): |
180 """Add support for with-statement.""" | 188 """Add support for with-statement.""" |
181 self.StopServer() | 189 self.StopServer() |
OLD | NEW |