зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1363053 - Return JSON representation of return value r=maja_zf
According to a recent change in the WebDriver specification, we need to
return an object's JSON representation iff it exists.
The relevant specification prose change was made in
1ee4c61c11
.
This patch causes return values that have a toJSON property that is a
function, to return the value of calling said function.
MozReview-Commit-ID: GpQNE9GpjCH
--HG--
extra : rebase_source : 7192bbd484cbaa4661f2442990082aefcdd1570b
This commit is contained in:
Родитель
a9505b4395
Коммит
c9a2bed65e
|
@ -247,7 +247,7 @@ evaluate.fromJSON = function (obj, seenEls, win, shadowRoot = undefined) {
|
|||
* web elements.
|
||||
*/
|
||||
evaluate.toJSON = function (obj, seenEls) {
|
||||
let t = Object.prototype.toString.call(obj);
|
||||
const t = Object.prototype.toString.call(obj);
|
||||
|
||||
// null
|
||||
if (t == "[object Undefined]" || t == "[object Null]") {
|
||||
|
@ -270,6 +270,12 @@ evaluate.toJSON = function (obj, seenEls) {
|
|||
return element.makeWebElement(uuid);
|
||||
}
|
||||
|
||||
// custom JSON representation
|
||||
else if (typeof obj["toJSON"] == "function") {
|
||||
let unsafeJSON = obj.toJSON();
|
||||
return evaluate.toJSON(unsafeJSON, seenEls);
|
||||
}
|
||||
|
||||
// arbitrary objects + files
|
||||
else {
|
||||
let rv = {};
|
||||
|
|
|
@ -49,6 +49,9 @@ class TestExecuteContent(MarionetteTestCase):
|
|||
"return typeof arguments[0] != 'undefined'", [property], sandbox=sandbox),
|
||||
"property {} is undefined".format(property))
|
||||
|
||||
def assert_is_web_element(self, element):
|
||||
self.assertIsInstance(element, HTMLElement)
|
||||
|
||||
def test_return_number(self):
|
||||
self.assertEqual(1, self.marionette.execute_script("return 1"))
|
||||
self.assertEqual(1.5, self.marionette.execute_script("return 1.5"))
|
||||
|
@ -330,6 +333,25 @@ class TestExecuteContent(MarionetteTestCase):
|
|||
# test inspection of arguments
|
||||
self.marionette.execute_script("__webDriverArguments.toString()")
|
||||
|
||||
def test_toJSON(self):
|
||||
foo = self.marionette.execute_script("""
|
||||
return {
|
||||
toJSON () {
|
||||
return "foo";
|
||||
}
|
||||
}""",
|
||||
sandbox=None)
|
||||
self.assertEqual("foo", foo)
|
||||
|
||||
def test_unsafe_toJSON(self):
|
||||
el = self.marionette.execute_script("""
|
||||
return {
|
||||
toJSON () {
|
||||
return document.documentElement;
|
||||
}
|
||||
}""",
|
||||
sandbox=None)
|
||||
self.assert_is_web_element(el)
|
||||
|
||||
|
||||
class TestExecuteChrome(WindowManagerMixin, TestExecuteContent):
|
||||
|
|
Загрузка…
Ссылка в новой задаче