OLD | NEW |
1 # Copyright (c) 2011 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 | 4 |
5 """A "Test Server Spawner" that handles killing/stopping per-test test servers. | 5 """A "Test Server Spawner" that handles killing/stopping per-test test servers. |
6 | 6 |
7 It's used to accept requests from the device to spawn and kill instances of the | 7 It's used to accept requests from the device to spawn and kill instances of the |
8 chrome test server on the host. | 8 chrome test server on the host. |
9 """ | 9 """ |
10 | 10 |
11 import BaseHTTPServer | 11 import BaseHTTPServer |
12 import logging | 12 import logging |
13 import os | 13 import os |
14 import sys | 14 import sys |
15 import threading | 15 import threading |
16 import time | 16 import time |
17 import urlparse | 17 import urlparse |
18 | 18 |
19 # Path that are needed to import testserver | 19 # Path that are needed to import testserver |
20 cr_src = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', '..') | 20 cr_src = os.path.join(os.path.abspath(os.path.dirname(__file__)), |
| 21 '..', '..', '..') |
21 sys.path.append(os.path.join(cr_src, 'third_party')) | 22 sys.path.append(os.path.join(cr_src, 'third_party')) |
22 sys.path.append(os.path.join(cr_src, 'third_party', 'tlslite')) | 23 sys.path.append(os.path.join(cr_src, 'third_party', 'tlslite')) |
23 sys.path.append(os.path.join(cr_src, 'third_party', 'pyftpdlib', 'src')) | 24 sys.path.append(os.path.join(cr_src, 'third_party', 'pyftpdlib', 'src')) |
24 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', | 25 sys.path.append(os.path.join(cr_src, 'net', 'tools', 'testserver')) |
25 '..', 'net', 'tools', 'testserver')) | |
26 import testserver | 26 import testserver |
27 | 27 |
28 _test_servers = [] | 28 _test_servers = [] |
29 | 29 |
30 class SpawningServerRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): | 30 class SpawningServerRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
31 """A handler used to process http GET request. | 31 """A handler used to process http GET request. |
32 """ | 32 """ |
33 | 33 |
34 def GetServerType(self, server_type): | 34 def GetServerType(self, server_type): |
35 """Returns the server type to use when starting the test server. | 35 """Returns the server type to use when starting the test server. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 self.server.serve_forever() | 105 self.server.serve_forever() |
106 | 106 |
107 def Start(self): | 107 def Start(self): |
108 listener_thread = threading.Thread(target=self.Listen) | 108 listener_thread = threading.Thread(target=self.Listen) |
109 listener_thread.setDaemon(True) | 109 listener_thread.setDaemon(True) |
110 listener_thread.start() | 110 listener_thread.start() |
111 time.sleep(1) | 111 time.sleep(1) |
112 | 112 |
113 def Stop(self): | 113 def Stop(self): |
114 self.server.Stop() | 114 self.server.Stop() |
OLD | NEW |