Bug 1400233 - Drop ContentWebElement.LegacyIdentifier key from Marionette; r?ato
Remove the legacy key that Marionette uses in addition to the identifier key.
MozReview-Commit-ID: 6IVtLxOJPoS
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -20,18 +20,18 @@ from six import reraise
from . import errors
from . import transport
from .decorators import do_process_check
from .geckoinstance import GeckoInstance
from .keys import Keys
from .timeout import Timeouts
-WEBELEMENT_KEY = "ELEMENT"
-W3C_WEBELEMENT_KEY = "element-6066-11e4-a52e-4f735466cecf"
+WEB_ELEMENT_KEY = "element-6066-11e4-a52e-4f735466cecf"
+CHROME_ELEMENT_KEY = "chromeelement-9fc5-4b51-a3c8-01716eedeb04"
class HTMLElement(object):
"""Represents a DOM Element."""
def __init__(self, marionette, id):
self.marionette = marionette
assert(id is not None)
@@ -746,22 +746,22 @@ class Marionette(object):
self._handle_error(err)
if key is not None:
return self._unwrap_response(res.get(key))
else:
return self._unwrap_response(res)
def _unwrap_response(self, value):
- if isinstance(value, dict) and (WEBELEMENT_KEY in value or
- W3C_WEBELEMENT_KEY in value):
- if value.get(WEBELEMENT_KEY):
- return HTMLElement(self, value.get(WEBELEMENT_KEY))
+ if isinstance(value, dict) and (WEB_ELEMENT_KEY in value or
+ CHROME_ELEMENT_KEY in value):
+ if value.get(WEB_ELEMENT_KEY):
+ return HTMLElement(self, value.get(WEB_ELEMENT_KEY))
else:
- return HTMLElement(self, value.get(W3C_WEBELEMENT_KEY))
+ return HTMLElement(self, value.get(CHROME_ELEMENT_KEY))
elif isinstance(value, list):
return list(self._unwrap_response(item) for item in value)
else:
return value
def _handle_error(self, obj):
error = obj["error"]
message = obj["message"]
@@ -1648,35 +1648,35 @@ class Marionette(object):
wrapped = []
for arg in args:
wrapped.append(self._to_json(arg))
elif isinstance(args, dict):
wrapped = {}
for arg in args:
wrapped[arg] = self._to_json(args[arg])
elif type(args) == HTMLElement:
- wrapped = {W3C_WEBELEMENT_KEY: args.id,
- WEBELEMENT_KEY: args.id}
+ wrapped = {WEB_ELEMENT_KEY: args.id,
+ CHROME_ELEMENT_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 _from_json(self, value):
if isinstance(value, list):
unwrapped = []
for item in value:
unwrapped.append(self._from_json(item))
elif isinstance(value, dict):
unwrapped = {}
for key in value:
- if key == W3C_WEBELEMENT_KEY:
+ if key == WEB_ELEMENT_KEY:
unwrapped = HTMLElement(self, value[key])
break
- elif key == WEBELEMENT_KEY:
+ elif key == CHROME_ELEMENT_KEY:
unwrapped = HTMLElement(self, value[key])
break
else:
unwrapped[key] = self._from_json(value[key])
else:
unwrapped = value
return unwrapped
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -1445,17 +1445,16 @@ class WebElement {
*/
static fromJSON(json) {
assert.object(json);
let keys = Object.keys(json);
for (let key of keys) {
switch (key) {
case ContentWebElement.Identifier:
- case ContentWebElement.LegacyIdentifier:
return ContentWebElement.fromJSON(json);
case ContentWebWindow.Identifier:
return ContentWebWindow.fromJSON(json);
case ContentWebFrame.Identifier:
return ContentWebFrame.fromJSON(json);
@@ -1504,32 +1503,30 @@ class WebElement {
default:
throw new InvalidArgumentError("Unknown context: " + context);
}
}
/**
* Checks if <var>ref<var> is a {@link WebElement} reference,
- * i.e. if it has {@link ContentWebElement.Identifier},
- * {@link ContentWebElement.LegacyIdentifier}, or
+ * i.e. if it has {@link ContentWebElement.Identifier}, or
* {@link ChromeWebElement.Identifier} as properties.
*
* @param {Object.<string, string>} obj
* Object that represents a reference to a {@link WebElement}.
* @return {boolean}
* True if <var>obj</var> is a {@link WebElement}, false otherwise.
*/
static isReference(obj) {
if (Object.prototype.toString.call(obj) != "[object Object]") {
return false;
}
if ((ContentWebElement.Identifier in obj) ||
- (ContentWebElement.LegacyIdentifier in obj) ||
(ContentWebWindow.Identifier in obj) ||
(ContentWebFrame.Identifier in obj) ||
(ChromeWebElement.Identifier in obj)) {
return true;
}
return false;
}
@@ -1549,46 +1546,43 @@ this.WebElement = WebElement;
/**
* DOM elements are represented as web elements when they are
* transported over the wire protocol.
*/
class ContentWebElement extends WebElement {
toJSON() {
return {
[ContentWebElement.Identifier]: this.uuid,
- [ContentWebElement.LegacyIdentifier]: this.uuid,
};
}
static fromJSON(json) {
- const {Identifier, LegacyIdentifier} = ContentWebElement;
+ const {Identifier} = ContentWebElement;
- if (!(Identifier in json) && !(LegacyIdentifier in json)) {
+ if (!(Identifier in json)) {
throw new InvalidArgumentError(
pprint`Expected web element reference, got: ${json}`);
}
- let uuid = json[Identifier] || json[LegacyIdentifier];
+ let uuid = json[Identifier];
return new ContentWebElement(uuid);
}
}
ContentWebElement.Identifier = "element-6066-11e4-a52e-4f735466cecf";
-ContentWebElement.LegacyIdentifier = "ELEMENT";
this.ContentWebElement = ContentWebElement;
/**
* Top-level browsing contexts, such as <code>WindowProxy</code>
* whose <code>opener</code> is null, are represented as web windows
* over the wire protocol.
*/
class ContentWebWindow extends WebElement {
toJSON() {
return {
[ContentWebWindow.Identifier]: this.uuid,
- [ContentWebElement.LegacyIdentifier]: this.uuid,
};
}
static fromJSON(json) {
if (!(ContentWebWindow.Identifier in json)) {
throw new InvalidArgumentError(
pprint`Expected web window reference, got: ${json}`);
}
@@ -1603,17 +1597,16 @@ this.ContentWebWindow = ContentWebWindow
* Nested browsing contexts, such as the <code>WindowProxy</code>
* associated with <tt><frame></tt> and <tt><iframe></tt>,
* are represented as web frames over the wire protocol.
*/
class ContentWebFrame extends WebElement {
toJSON() {
return {
[ContentWebFrame.Identifier]: this.uuid,
- [ContentWebElement.LegacyIdentifier]: this.uuid,
};
}
static fromJSON(json) {
if (!(ContentWebFrame.Identifier in json)) {
throw new InvalidArgumentError(
pprint`Expected web frame reference, got: ${json}`);
}
@@ -1627,17 +1620,16 @@ this.ContentWebFrame = ContentWebFrame;
/**
* XUL elements in chrome space are represented as chrome web elements
* over the wire protocol.
*/
class ChromeWebElement extends WebElement {
toJSON() {
return {
[ChromeWebElement.Identifier]: this.uuid,
- [ContentWebElement.LegacyIdentifier]: this.uuid,
};
}
static fromJSON(json) {
if (!(ChromeWebElement.Identifier in json)) {
throw new InvalidArgumentError("Expected chrome element reference " +
pprint`for XUL/XBL element, got: ${json}`);
}
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_mouse_action.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_mouse_action.py
@@ -3,17 +3,17 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import
import urllib
from marionette_driver import By, errors, Wait
from marionette_driver.keys import Keys
-from marionette_driver.marionette import W3C_WEBELEMENT_KEY
+from marionette_driver.marionette import WEB_ELEMENT_KEY
from marionette_harness import MarionetteTestCase
def inline(doc):
return "data:text/html;charset=utf-8,{}".format(urllib.quote(doc))
@@ -36,17 +36,17 @@ class Actions(object):
}]}
return self.marionette._send_message("performActions", params=params)
def move(self, element, x=0, y=0, duration=250):
self.action_chain.append({
"duration": duration,
"origin": {
- W3C_WEBELEMENT_KEY: element.id
+ WEB_ELEMENT_KEY: element.id
},
"type": "pointerMove",
"x": x,
"y": y,
})
return self
--- a/testing/marionette/test_element.js
+++ b/testing/marionette/test_element.js
@@ -353,47 +353,25 @@ add_test(function test_WebElement_from()
ok(WebElement.from(xulEl) instanceof ChromeWebElement);
Assert.throws(() => WebElement.from({}), InvalidArgumentError);
run_next_test();
});
add_test(function test_WebElement_fromJSON_ContentWebElement() {
- const {Identifier, LegacyIdentifier} = ContentWebElement;
-
- let refNew = {[Identifier]: "foo"};
- let webElNew = WebElement.fromJSON(refNew);
- ok(webElNew instanceof ContentWebElement);
- equal(webElNew.uuid, "foo");
-
- let refOld = {[LegacyIdentifier]: "foo"};
- let webElOld = WebElement.fromJSON(refOld);
- ok(webElOld instanceof ContentWebElement);
- equal(webElOld.uuid, "foo");
+ const {Identifier} = ContentWebElement;
- ok(webElNew.is(webElOld));
- ok(webElOld.is(webElNew));
-
- let refBoth = {
- [Identifier]: "foo",
- [LegacyIdentifier]: "foo",
- };
- let webElBoth = WebElement.fromJSON(refBoth);
- ok(webElBoth instanceof ContentWebElement);
- equal(webElBoth.uuid, "foo");
-
- ok(webElBoth.is(webElNew));
- ok(webElBoth.is(webElOld));
- ok(webElNew.is(webElBoth));
- ok(webElOld.is(webElBoth));
+ let ref = {[Identifier]: "foo"};
+ let webEl = WebElement.fromJSON(ref);
+ ok(webEl instanceof ContentWebElement);
+ equal(webEl.uuid, "foo");
let identifierPrecedence = {
[Identifier]: "identifier-uuid",
- [LegacyIdentifier]: "legacyidentifier-uuid",
};
let precedenceEl = WebElement.fromJSON(identifierPrecedence);
ok(precedenceEl instanceof ContentWebElement);
equal(precedenceEl.uuid, "identifier-uuid");
run_next_test();
});
@@ -445,61 +423,46 @@ add_test(function test_WebElement_fromUU
});
add_test(function test_WebElement_isReference() {
for (let t of [42, true, "foo", [], {}]) {
ok(!WebElement.isReference(t));
}
ok(WebElement.isReference({[ContentWebElement.Identifier]: "foo"}));
- ok(WebElement.isReference({[ContentWebElement.LegacyIdentifier]: "foo"}));
ok(WebElement.isReference({[ContentWebWindow.Identifier]: "foo"}));
ok(WebElement.isReference({[ContentWebFrame.Identifier]: "foo"}));
ok(WebElement.isReference({[ChromeWebElement.Identifier]: "foo"}));
run_next_test();
});
add_test(function test_WebElement_generateUUID() {
equal(typeof WebElement.generateUUID(), "string");
run_next_test();
});
add_test(function test_ContentWebElement_toJSON() {
- const {Identifier, LegacyIdentifier} = ContentWebElement;
+ const {Identifier} = ContentWebElement;
let el = new ContentWebElement("foo");
let json = el.toJSON();
ok(Identifier in json);
- ok(LegacyIdentifier in json);
equal(json[Identifier], "foo");
- equal(json[LegacyIdentifier], "foo");
run_next_test();
});
add_test(function test_ContentWebElement_fromJSON() {
- const {Identifier, LegacyIdentifier} = ContentWebElement;
-
- let newEl = ContentWebElement.fromJSON({[Identifier]: "foo"});
- ok(newEl instanceof ContentWebElement);
- equal(newEl.uuid, "foo");
+ const {Identifier} = ContentWebElement;
- let oldEl = ContentWebElement.fromJSON({[LegacyIdentifier]: "foo"});
- ok(oldEl instanceof ContentWebElement);
- equal(oldEl.uuid, "foo");
-
- let bothRef = {
- [Identifier]: "identifier-uuid",
- [LegacyIdentifier]: "legacyidentifier-foo",
- };
- let bothEl = ContentWebElement.fromJSON(bothRef);
- ok(bothEl instanceof ContentWebElement);
- equal(bothEl.uuid, "identifier-uuid");
+ let el = ContentWebElement.fromJSON({[Identifier]: "foo"});
+ ok(el instanceof ContentWebElement);
+ equal(el.uuid, "foo");
Assert.throws(() => ContentWebElement.fromJSON({}), InvalidArgumentError);
run_next_test();
});
add_test(function test_ContentWebWindow_toJSON() {
let win = new ContentWebWindow("foo");