--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -1495,70 +1495,70 @@ class Marionette(object):
def go_forward(self):
"""Causes the browser to perform a forward navigation."""
self._send_message("goForward")
def refresh(self):
"""Causes the browser to perform to refresh the current page."""
self._send_message("refresh")
- def wrapArguments(self, args):
- if isinstance(args, list):
+ def _to_json(self, args):
+ if isinstance(args, list) or isinstance(args, tuple):
wrapped = []
for arg in args:
- wrapped.append(self.wrapArguments(arg))
+ wrapped.append(self._to_json(arg))
elif isinstance(args, dict):
wrapped = {}
for arg in args:
- wrapped[arg] = self.wrapArguments(args[arg])
+ wrapped[arg] = self._to_json(args[arg])
elif type(args) == HTMLElement:
wrapped = {W3C_WEBELEMENT_KEY: args.id,
WEBELEMENT_KEY: args.id}
elif (isinstance(args, bool) or isinstance(args, basestring) or
isinstance(args, int) or isinstance(args, float) or args is None):
wrapped = args
return wrapped
- def unwrapValue(self, value):
+ def _from_json(self, value):
if isinstance(value, list):
unwrapped = []
for item in value:
- unwrapped.append(self.unwrapValue(item))
+ unwrapped.append(self._from_json(item))
elif isinstance(value, dict):
unwrapped = {}
for key in value:
if key == W3C_WEBELEMENT_KEY:
unwrapped = HTMLElement(self, value[key])
break
elif key == WEBELEMENT_KEY:
unwrapped = HTMLElement(self, value[key])
break
else:
- unwrapped[key] = self.unwrapValue(value[key])
+ unwrapped[key] = self._from_json(value[key])
else:
unwrapped = value
return unwrapped
def execute_js_script(self, script, script_args=None, async=True,
new_sandbox=True, script_timeout=None,
inactivity_timeout=None, filename=None,
sandbox='default'):
if script_args is None:
script_args = []
- args = self.wrapArguments(script_args)
+ args = self._to_json(script_args)
body = {"script": script,
"args": args,
"async": async,
"newSandbox": new_sandbox,
"scriptTimeout": script_timeout,
"inactivityTimeout": inactivity_timeout,
"filename": filename,
"line": None}
rv = self._send_message("executeJSScript", body, key="value")
- return self.unwrapValue(rv)
+ return self._from_json(rv)
def execute_script(self, script, script_args=None, new_sandbox=True,
sandbox="default", script_timeout=None):
"""Executes a synchronous JavaScript script, and returns the
result (or None if the script does return a value).
The script is executed in the context set by the most recent
set_context() call, or to the CONTEXT_CONTENT context if set_context()
@@ -1615,28 +1615,28 @@ class Marionette(object):
marionette.execute_script("global.test1 = 'foo';")
result = self.marionette.execute_script("return global.test1;", new_sandbox=False)
assert result == "foo"
"""
if script_args is None:
script_args = []
- args = self.wrapArguments(script_args)
+ args = self._to_json(script_args)
stack = traceback.extract_stack()
frame = stack[-2:-1][0] # grab the second-to-last frame
body = {"script": script,
"args": args,
"newSandbox": new_sandbox,
"sandbox": sandbox,
"scriptTimeout": script_timeout,
"line": int(frame[1]),
"filename": os.path.basename(frame[0])}
rv = self._send_message("executeScript", body, key="value")
- return self.unwrapValue(rv)
+ return self._from_json(rv)
def execute_async_script(self, script, script_args=None, new_sandbox=True,
sandbox="default", script_timeout=None,
debug_script=False):
"""Executes an asynchronous JavaScript script, and returns the
result (or None if the script does return a value).
The script is executed in the context set by the most recent
@@ -1665,29 +1665,29 @@ class Marionette(object):
setTimeout(function() {
marionetteScriptFinished(1);
}, 5000);
''')
assert result == 1
"""
if script_args is None:
script_args = []
- args = self.wrapArguments(script_args)
+ args = self._to_json(script_args)
stack = traceback.extract_stack()
frame = stack[-2:-1][0] # grab the second-to-last frame
body = {"script": script,
"args": args,
"newSandbox": new_sandbox,
"sandbox": sandbox,
"scriptTimeout": script_timeout,
"line": int(frame[1]),
"filename": os.path.basename(frame[0]),
"debug_script": debug_script}
rv = self._send_message("executeAsyncScript", body, key="value")
- return self.unwrapValue(rv)
+ return self._from_json(rv)
def find_element(self, method, target, id=None):
"""Returns an HTMLElement instances that matches the specified
method and target in the current context.
An HTMLElement instance may be used to call other methods on the
element, such as click(). If no element is immediately found, the
attempt to locate an element will be repeated for up to the amount of