Bug 1452483 - Use relative path to source file for injected scripts. r?maja_zf
The basename is not sufficient to locate the file. Using the file's
relative path will match the behaviour of JavaScript stacktraces.
We can't use relative paths on Windows because the source file may
exist on another disk drive, and on Windows you cannot make relative
paths across disk drives because they don't share the same root.
MozReview-Commit-ID: 4EPITa2kH6J
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -1701,26 +1701,25 @@ class Marionette(object):
marionette.execute_script("global.test1 = 'foo';")
result = self.marionette.execute_script("return global.test1;", new_sandbox=False)
assert result == "foo"
"""
args = self._to_json(script_args)
stack = traceback.extract_stack()
frame = stack[-2:-1][0] # grab the second-to-last frame
+ filename = frame[0] if sys.platform == "win32" else os.path.relpath(frame[0])
body = {"script": script.strip(),
"args": args,
"newSandbox": new_sandbox,
"sandbox": sandbox,
"scriptTimeout": script_timeout,
"line": int(frame[1]),
- "filename": os.path.basename(frame[0])}
-
- rv = self._send_message("WebDriver:ExecuteScript",
- body, key="value")
+ "filename": filename}
+ rv = self._send_message("WebDriver:ExecuteScript", body, key="value")
return self._from_json(rv)
def execute_async_script(self, script, script_args=(), 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).
@@ -1751,23 +1750,24 @@ class Marionette(object):
marionetteScriptFinished(1);
}, 5000);
''')
assert result == 1
"""
args = self._to_json(script_args)
stack = traceback.extract_stack()
frame = stack[-2:-1][0] # grab the second-to-last frame
+ filename = frame[0] if sys.platform == "win32" else os.path.relpath(frame[0])
body = {"script": script.strip(),
"args": args,
"newSandbox": new_sandbox,
"sandbox": sandbox,
"scriptTimeout": script_timeout,
"line": int(frame[1]),
- "filename": os.path.basename(frame[0]),
+ "filename": filename,
"debug_script": debug_script}
rv = self._send_message("WebDriver:ExecuteAsyncScript",
body, key="value")
return self._from_json(rv)
def find_element(self, method, target, id=None):
"""Returns an :class:`~marionette_driver.marionette.HTMLElement`