Chromium Code Reviews| 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 sys | 5 import sys |
| 6 import platform | 6 import platform |
| 7 | 7 |
| 8 import command_executor | 8 import command_executor |
| 9 from command_executor import Command | 9 from command_executor import Command |
| 10 from webelement import WebElement | 10 from webelement import WebElement |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 105 |
| 106 def __init__(self, server_url, chrome_binary=None, android_package=None, | 106 def __init__(self, server_url, chrome_binary=None, android_package=None, |
| 107 android_activity=None, android_process=None, | 107 android_activity=None, android_process=None, |
| 108 android_use_running_app=None, chrome_switches=None, | 108 android_use_running_app=None, chrome_switches=None, |
| 109 chrome_extensions=None, chrome_log_path=None, | 109 chrome_extensions=None, chrome_log_path=None, |
| 110 debugger_address=None, logging_prefs=None, | 110 debugger_address=None, logging_prefs=None, |
| 111 mobile_emulation=None, experimental_options=None, | 111 mobile_emulation=None, experimental_options=None, |
| 112 download_dir=None, network_connection=None, | 112 download_dir=None, network_connection=None, |
| 113 send_w3c_capability=None, send_w3c_request=None, | 113 send_w3c_capability=None, send_w3c_request=None, |
| 114 page_load_strategy=None): | 114 page_load_strategy=None): |
| 115 | |
|
samuong
2016/08/11 18:13:20
nit: no need for a new blank line
roisinmcl
2016/08/13 01:47:26
Done.
| |
| 115 self._executor = command_executor.CommandExecutor(server_url) | 116 self._executor = command_executor.CommandExecutor(server_url) |
| 116 | 117 |
| 117 options = {} | 118 options = {} |
| 118 | 119 |
| 119 if experimental_options: | 120 if experimental_options: |
| 120 assert isinstance(experimental_options, dict) | 121 assert isinstance(experimental_options, dict) |
| 121 options = experimental_options.copy() | 122 options = experimental_options.copy() |
| 122 | 123 |
| 123 if android_package: | 124 if android_package: |
| 124 options['androidPackage'] = android_package | 125 options['androidPackage'] = android_package |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 self.capabilities = self._UnwrapValue(response['value']) | 210 self.capabilities = self._UnwrapValue(response['value']) |
| 210 | 211 |
| 211 def _WrapValue(self, value): | 212 def _WrapValue(self, value): |
| 212 """Wrap value from client side for chromedriver side.""" | 213 """Wrap value from client side for chromedriver side.""" |
| 213 if isinstance(value, dict): | 214 if isinstance(value, dict): |
| 214 converted = {} | 215 converted = {} |
| 215 for key, val in value.items(): | 216 for key, val in value.items(): |
| 216 converted[key] = self._WrapValue(val) | 217 converted[key] = self._WrapValue(val) |
| 217 return converted | 218 return converted |
| 218 elif isinstance(value, WebElement): | 219 elif isinstance(value, WebElement): |
| 219 return {'ELEMENT': value._id} | 220 if (self.w3c_compliant): |
| 221 return {'element-6066-11e4-a52e-4f735466cecf': value._id} | |
| 222 else: | |
| 223 return {'ELEMENT': value._id} | |
|
samuong
2016/08/11 18:13:20
let's create constants for the element keys, since
roisinmcl
2016/08/13 01:47:26
Done.
| |
| 220 elif isinstance(value, list): | 224 elif isinstance(value, list): |
| 221 return list(self._WrapValue(item) for item in value) | 225 return list(self._WrapValue(item) for item in value) |
| 222 else: | 226 else: |
| 223 return value | 227 return value |
| 224 | 228 |
| 225 def _UnwrapValue(self, value): | 229 def _UnwrapValue(self, value): |
| 226 """Unwrap value from chromedriver side for client side.""" | 230 """Unwrap value from chromedriver side for client side.""" |
| 227 if isinstance(value, dict): | 231 if isinstance(value, dict): |
| 228 if (len(value) == 1 and 'ELEMENT' in value | 232 if (self.w3c_compliant and len(value) == 1 |
| 233 and 'element-6066-11e4-a52e-4f735466cecf' in value | |
| 234 and isinstance( | |
| 235 value['element-6066-11e4-a52e-4f735466cecf'], basestring)): | |
|
samuong
2016/08/11 18:13:20
this is a big conjunction, let's do the len(value)
roisinmcl
2016/08/13 01:47:26
Done.
| |
| 236 return WebElement(self, value['element-6066-11e4-a52e-4f735466cecf']) | |
| 237 elif (len(value) == 1 and 'ELEMENT' in value | |
| 229 and isinstance(value['ELEMENT'], basestring)): | 238 and isinstance(value['ELEMENT'], basestring)): |
| 230 return WebElement(self, value['ELEMENT']) | 239 return WebElement(self, value['ELEMENT']) |
| 231 else: | 240 else: |
| 232 unwraped = {} | 241 unwraped = {} |
| 233 for key, val in value.items(): | 242 for key, val in value.items(): |
| 234 unwraped[key] = self._UnwrapValue(val) | 243 unwraped[key] = self._UnwrapValue(val) |
| 235 return unwraped | 244 return unwraped |
| 236 elif isinstance(value, list): | 245 elif isinstance(value, list): |
| 237 return list(self._UnwrapValue(item) for item in value) | 246 return list(self._UnwrapValue(item) for item in value) |
| 238 else: | 247 else: |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 | 481 |
| 473 def GetNetworkConnection(self): | 482 def GetNetworkConnection(self): |
| 474 return self.ExecuteCommand(Command.GET_NETWORK_CONNECTION) | 483 return self.ExecuteCommand(Command.GET_NETWORK_CONNECTION) |
| 475 | 484 |
| 476 def DeleteNetworkConditions(self): | 485 def DeleteNetworkConditions(self): |
| 477 self.ExecuteCommand(Command.DELETE_NETWORK_CONDITIONS) | 486 self.ExecuteCommand(Command.DELETE_NETWORK_CONDITIONS) |
| 478 | 487 |
| 479 def SetNetworkConnection(self, connection_type): | 488 def SetNetworkConnection(self, connection_type): |
| 480 params = {'parameters': {'type': connection_type}} | 489 params = {'parameters': {'type': connection_type}} |
| 481 self.ExecuteCommand(Command.SET_NETWORK_CONNECTION, params) | 490 self.ExecuteCommand(Command.SET_NETWORK_CONNECTION, params) |
| OLD | NEW |