mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 05:45:37 +00:00
Bug 1400233 - Drop ContentWebElement.LegacyIdentifier key from Marionette. r=ato,whimboo
Remove the legacy key that Marionette uses to identify web elements.
This commit is contained in:
parent
501b992f9a
commit
ed1ae60ec8
@ -26,7 +26,6 @@ from .timeout import Timeouts
|
||||
|
||||
CHROME_ELEMENT_KEY = "chromeelement-9fc5-4b51-a3c8-01716eedeb04"
|
||||
FRAME_KEY = "frame-075b-4da1-b6ba-e579c2d3230a"
|
||||
LEGACY_ELEMENT_KEY = "ELEMENT"
|
||||
WEB_ELEMENT_KEY = "element-6066-11e4-a52e-4f735466cecf"
|
||||
WINDOW_KEY = "window-fcc6-11e5-b4f8-330a88ab9d7f"
|
||||
|
||||
@ -34,8 +33,7 @@ WINDOW_KEY = "window-fcc6-11e5-b4f8-330a88ab9d7f"
|
||||
class HTMLElement(object):
|
||||
"""Represents a DOM Element."""
|
||||
|
||||
identifiers = (CHROME_ELEMENT_KEY, FRAME_KEY, WINDOW_KEY,
|
||||
LEGACY_ELEMENT_KEY, WEB_ELEMENT_KEY)
|
||||
identifiers = (CHROME_ELEMENT_KEY, FRAME_KEY, WINDOW_KEY, WEB_ELEMENT_KEY)
|
||||
|
||||
def __init__(self, marionette, id):
|
||||
self.marionette = marionette
|
||||
@ -187,8 +185,6 @@ class HTMLElement(object):
|
||||
if isinstance(json, dict):
|
||||
if WEB_ELEMENT_KEY in json:
|
||||
return cls(marionette, json[WEB_ELEMENT_KEY])
|
||||
elif LEGACY_ELEMENT_KEY in json:
|
||||
return cls(marionette, json[LEGACY_ELEMENT_KEY])
|
||||
elif CHROME_ELEMENT_KEY in json:
|
||||
return cls(marionette, json[CHROME_ELEMENT_KEY])
|
||||
elif FRAME_KEY in json:
|
||||
@ -1611,7 +1607,7 @@ class Marionette(object):
|
||||
wrapped[arg] = self._to_json(args[arg])
|
||||
elif type(args) == HTMLElement:
|
||||
wrapped = {WEB_ELEMENT_KEY: args.id,
|
||||
LEGACY_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
|
||||
|
@ -1443,7 +1443,6 @@ class WebElement {
|
||||
for (let key of keys) {
|
||||
switch (key) {
|
||||
case ContentWebElement.Identifier:
|
||||
case ContentWebElement.LegacyIdentifier:
|
||||
return ContentWebElement.fromJSON(json);
|
||||
|
||||
case ContentWebWindow.Identifier:
|
||||
@ -1502,8 +1501,7 @@ class WebElement {
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -1517,7 +1515,6 @@ class WebElement {
|
||||
}
|
||||
|
||||
if ((ContentWebElement.Identifier in obj) ||
|
||||
(ContentWebElement.LegacyIdentifier in obj) ||
|
||||
(ContentWebWindow.Identifier in obj) ||
|
||||
(ContentWebFrame.Identifier in obj) ||
|
||||
(ChromeWebElement.Identifier in obj)) {
|
||||
@ -1545,26 +1542,22 @@ this.WebElement = WebElement;
|
||||
*/
|
||||
class ContentWebElement extends WebElement {
|
||||
toJSON() {
|
||||
return {
|
||||
[ContentWebElement.Identifier]: this.uuid,
|
||||
[ContentWebElement.LegacyIdentifier]: this.uuid,
|
||||
};
|
||||
return {[ContentWebElement.Identifier]: 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;
|
||||
|
||||
/**
|
||||
@ -1574,10 +1567,7 @@ this.ContentWebElement = ContentWebElement;
|
||||
*/
|
||||
class ContentWebWindow extends WebElement {
|
||||
toJSON() {
|
||||
return {
|
||||
[ContentWebWindow.Identifier]: this.uuid,
|
||||
[ContentWebElement.LegacyIdentifier]: this.uuid,
|
||||
};
|
||||
return {[ContentWebWindow.Identifier]: this.uuid};
|
||||
}
|
||||
|
||||
static fromJSON(json) {
|
||||
@ -1599,10 +1589,7 @@ this.ContentWebWindow = ContentWebWindow;
|
||||
*/
|
||||
class ContentWebFrame extends WebElement {
|
||||
toJSON() {
|
||||
return {
|
||||
[ContentWebFrame.Identifier]: this.uuid,
|
||||
[ContentWebElement.LegacyIdentifier]: this.uuid,
|
||||
};
|
||||
return {[ContentWebFrame.Identifier]: this.uuid};
|
||||
}
|
||||
|
||||
static fromJSON(json) {
|
||||
@ -1623,10 +1610,7 @@ this.ContentWebFrame = ContentWebFrame;
|
||||
*/
|
||||
class ChromeWebElement extends WebElement {
|
||||
toJSON() {
|
||||
return {
|
||||
[ChromeWebElement.Identifier]: this.uuid,
|
||||
[ContentWebElement.LegacyIdentifier]: this.uuid,
|
||||
};
|
||||
return {[ChromeWebElement.Identifier]: this.uuid};
|
||||
}
|
||||
|
||||
static fromJSON(json) {
|
||||
|
@ -358,37 +358,15 @@ add_test(function test_WebElement_from() {
|
||||
});
|
||||
|
||||
add_test(function test_WebElement_fromJSON_ContentWebElement() {
|
||||
const {Identifier, LegacyIdentifier} = ContentWebElement;
|
||||
const {Identifier} = 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");
|
||||
|
||||
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);
|
||||
@ -450,7 +428,6 @@ add_test(function test_WebElement_isReference() {
|
||||
}
|
||||
|
||||
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"}));
|
||||
@ -464,37 +441,23 @@ add_test(function test_WebElement_generateUUID() {
|
||||
});
|
||||
|
||||
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;
|
||||
const {Identifier} = ContentWebElement;
|
||||
|
||||
let newEl = ContentWebElement.fromJSON({[Identifier]: "foo"});
|
||||
ok(newEl instanceof ContentWebElement);
|
||||
equal(newEl.uuid, "foo");
|
||||
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user