OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import httplib | 5 import httplib |
6 import json | 6 import json |
7 | 7 |
8 | 8 |
9 class _Method(object): | 9 class _Method(object): |
10 GET = 'GET' | 10 GET = 'GET' |
11 POST = 'POST' | 11 POST = 'POST' |
12 DELETE = 'DELETE' | 12 DELETE = 'DELETE' |
13 | 13 |
14 | 14 |
15 class Command(object): | 15 class Command(object): |
16 NEW_SESSION = (_Method.POST, '/session') | 16 NEW_SESSION = (_Method.POST, '/session') |
17 GET_SESSION_CAPABILITIES = (_Method.GET, '/session/:sessionId') | 17 GET_SESSION_CAPABILITIES = (_Method.GET, '/session/:sessionId') |
18 QUIT = (_Method.DELETE, '/session/:sessionId') | 18 QUIT = (_Method.DELETE, '/session/:sessionId') |
19 GET_CURRENT_WINDOW_HANDLE = (_Method.GET, '/session/:sessionId/window_handle') | 19 GET_CURRENT_WINDOW_HANDLE = (_Method.GET, '/session/:sessionId/window_handle') |
20 GET_WINDOW_HANDLES = (_Method.GET, '/session/:sessionId/window_handles') | 20 GET_WINDOW_HANDLES = (_Method.GET, '/session/:sessionId/window_handles') |
21 GET = (_Method.POST, '/session/:sessionId/url') | 21 GET = (_Method.POST, '/session/:sessionId/url') |
| 22 LAUNCH_APP = (_Method.POST, '/session/:sessionId/launch') |
22 GET_ALERT = (_Method.GET, '/session/:sessionId/alert') | 23 GET_ALERT = (_Method.GET, '/session/:sessionId/alert') |
23 DISMISS_ALERT = (_Method.POST, '/session/:sessionId/dismiss_alert') | 24 DISMISS_ALERT = (_Method.POST, '/session/:sessionId/dismiss_alert') |
24 ACCEPT_ALERT = (_Method.POST, '/session/:sessionId/accept_alert') | 25 ACCEPT_ALERT = (_Method.POST, '/session/:sessionId/accept_alert') |
25 GET_ALERT_TEXT = (_Method.GET, '/session/:sessionId/alert_text') | 26 GET_ALERT_TEXT = (_Method.GET, '/session/:sessionId/alert_text') |
26 SET_ALERT_VALUE = (_Method.POST, '/session/:sessionId/alert_text') | 27 SET_ALERT_VALUE = (_Method.POST, '/session/:sessionId/alert_text') |
27 GO_FORWARD = (_Method.POST, '/session/:sessionId/forward') | 28 GO_FORWARD = (_Method.POST, '/session/:sessionId/forward') |
28 GO_BACK = (_Method.POST, '/session/:sessionId/back') | 29 GO_BACK = (_Method.POST, '/session/:sessionId/back') |
29 REFRESH = (_Method.POST, '/session/:sessionId/refresh') | 30 REFRESH = (_Method.POST, '/session/:sessionId/refresh') |
30 EXECUTE_SCRIPT = (_Method.POST, '/session/:sessionId/execute') | 31 EXECUTE_SCRIPT = (_Method.POST, '/session/:sessionId/execute') |
31 EXECUTE_ASYNC_SCRIPT = (_Method.POST, '/session/:sessionId/execute_async') | 32 EXECUTE_ASYNC_SCRIPT = (_Method.POST, '/session/:sessionId/execute_async') |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 self._http_client.request(command[0], '/'.join(substituted_parts), body) | 164 self._http_client.request(command[0], '/'.join(substituted_parts), body) |
164 response = self._http_client.getresponse() | 165 response = self._http_client.getresponse() |
165 | 166 |
166 if response.status == 303: | 167 if response.status == 303: |
167 self._http_client.request(_Method.GET, response.getheader('location')) | 168 self._http_client.request(_Method.GET, response.getheader('location')) |
168 response = self._http_client.getresponse() | 169 response = self._http_client.getresponse() |
169 if response.status != 200: | 170 if response.status != 200: |
170 raise RuntimeError('Server returned error: ' + response.reason) | 171 raise RuntimeError('Server returned error: ' + response.reason) |
171 | 172 |
172 return json.loads(response.read()) | 173 return json.loads(response.read()) |
OLD | NEW |