Bug 1400256 - Remove element.isWebElementReference. r?whimboo
Remove element.isWebElementReference in favour of
WebElement.isReference.
MozReview-Commit-ID: IOqx7XMUfCu
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -4,17 +4,20 @@
/* eslint no-dupe-keys:off */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("chrome://marionette/content/assert.js");
-Cu.import("chrome://marionette/content/element.js");
+const {
+ element,
+ WebElement,
+} = Cu.import("chrome://marionette/content/element.js", {});
const {
InvalidArgumentError,
MoveTargetOutOfBoundsError,
UnsupportedOperationError,
} = Cu.import("chrome://marionette/content/error.js", {});
Cu.import("chrome://marionette/content/event.js");
const {pprint} = Cu.import("chrome://marionette/content/format.js", {});
Cu.import("chrome://marionette/content/interaction.js");
@@ -357,17 +360,17 @@ action.PointerOrigin = {
action.PointerOrigin.get = function(obj) {
let origin = obj;
if (typeof obj == "undefined") {
origin = this.Viewport;
} else if (typeof obj == "string") {
let name = capitalize(obj);
assert.in(name, this, pprint`Unknown pointer-move origin: ${obj}`);
origin = this[name];
- } else if (!element.isWebElementReference(obj)) {
+ } else if (!WebElement.isReference(obj)) {
throw new InvalidArgumentError("Expected 'origin' to be a string or a " +
pprint`web element reference, got ${obj}`);
}
return origin;
};
/** Represents possible subtypes for a pointer input source. */
action.PointerType = {
@@ -1315,18 +1318,18 @@ function dispatchPointerMove(a, inputSta
const timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
// interval between pointermove increments in ms, based on common vsync
const fps60 = 17;
return new Promise(resolve => {
const start = Date.now();
const [startX, startY] = [inputState.x, inputState.y];
- let target = action.computePointerDestination(a, inputState,
- getElementCenter(a.origin, seenEls, window));
+ let coords = getElementCenter(a.origin);
+ let target = action.computePointerDestination(a, inputState, coords);
const [targetX, targetY] = [target.x, target.y];
if (!inViewPort(targetX, targetY, window)) {
throw new MoveTargetOutOfBoundsError(
`(${targetX}, ${targetY}) is out of bounds of viewport ` +
`width (${window.innerWidth}) ` +
`and height (${window.innerHeight})`);
}
@@ -1425,17 +1428,14 @@ function capitalize(str) {
function inViewPort(x, y, win) {
assert.number(x, `Expected x to be finite number`);
assert.number(y, `Expected y to be finite number`);
// Viewport includes scrollbars if rendered.
return !(x < 0 || y < 0 || x > win.innerWidth || y > win.innerHeight);
}
-function getElementCenter(elementReference, seenEls, window) {
- if (element.isWebElementReference(elementReference)) {
- let uuid = elementReference[element.Key] ||
- elementReference[element.LegacyKey];
- let el = seenEls.get(uuid, window);
+function getElementCenter(el) {
+ if (element.isDOMElement(el)) {
return element.coordinates(el);
}
return {};
}
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -658,31 +658,16 @@ element.isCollection = function(seq) {
element.makeWebElement = function(uuid) {
return {
[element.Key]: uuid,
[element.LegacyKey]: uuid,
};
};
-/**
- * Checks if |ref| has either |element.Key| or |element.LegacyKey|
- * as properties.
- *
- * @param {Object.<string, string>} ref
- * Object that represents a web element reference.
- * @return {boolean}
- * True if |ref| has either expected property.
- */
-element.isWebElementReference = function(ref) {
- let properties = Object.getOwnPropertyNames(ref);
- return properties.includes(element.Key) ||
- properties.includes(element.LegacyKey);
-};
-
element.generateUUID = function() {
let uuid = uuidGen.generateUUID().toString();
return uuid.substring(1, uuid.length - 1);
};
/**
* Determines if <var>el</var> is stale.
*
--- a/testing/marionette/test_element.js
+++ b/testing/marionette/test_element.js
@@ -209,27 +209,16 @@ add_test(function test_coordinates() {
Assert.throws(() => element.coordinates(domEl, {}, {}));
Assert.throws(() => element.coordinates(domEl, [], undefined));
Assert.throws(() => element.coordinates(domEl, undefined, []));
Assert.throws(() => element.coordinates(domEl, [], []));
run_next_test();
});
-add_test(function test_isWebElementReference() {
- strictEqual(element.isWebElementReference({[element.Key]: "some_id"}), true);
- strictEqual(element.isWebElementReference({[element.LegacyKey]: "some_id"}), true);
- strictEqual(element.isWebElementReference(
- {[element.LegacyKey]: "some_id", [element.Key]: "2"}), true);
- strictEqual(element.isWebElementReference({}), false);
- strictEqual(element.isWebElementReference({"key": "blah"}), false);
-
- run_next_test();
-});
-
add_test(function test_WebElement_ctor() {
let el = new WebElement("foo");
equal(el.uuid, "foo");
for (let t of [42, true, [], {}, null, undefined]) {
Assert.throws(() => new WebElement(t));
}