Bug 1354211 - Add element.isReadOnly. r?automatedtester
Introduces new function for testing whether an element is read-only.
This content IDL attribute only applies to <input> and <textarea>
elements.
MozReview-Commit-ID: 1YLizKUYMU6
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -778,16 +778,32 @@ element.isSelected = function(el) {
return el.selected;
}
}
return false;
};
/**
+ * An element is considered read only if it is an
+ * <code><input></code> or <code><textarea></code>
+ * element whose <code>readOnly</code> content IDL attribute is set.
+ *
+ * @param {Element} el
+ * Element to test is read only.
+ *
+ * @return {boolean}
+ * True if element is read only.
+ */
+element.isReadOnly = function(el) {
+ return element.isDOMElement(el) &&
+ ["input", "textarea"].includes(el.localName) && el.readOnly;
+};
+
+/**
* This function generates a pair of coordinates relative to the viewport
* given a target element and coordinates relative to that element's
* top-left corner.
*
* @param {Node} node
* Target node.
* @param {number=} xOffset
* Horizontal offset relative to target's top-left corner.
--- a/testing/marionette/test_element.js
+++ b/testing/marionette/test_element.js
@@ -189,16 +189,26 @@ add_test(function test_isDOMWindow() {
ok(!element.isDOMWindow(xulEl));
for (let typ of [true, 42, {}, [], undefined, null]) {
ok(!element.isDOMWindow(typ));
}
run_next_test();
});
+add_test(function test_isReadOnly() {
+ ok(!element.isReadOnly(null));
+ ok(!element.isReadOnly(domEl));
+ ok(!element.isReadOnly(new DOMElement("p", {readOnly: true})));
+ ok(element.isReadOnly(new DOMElement("input", {readOnly: true})));
+ ok(element.isReadOnly(new DOMElement("textarea", {readOnly: true})));
+
+ run_next_test();
+});
+
add_test(function test_coordinates() {
let p = element.coordinates(domEl);
ok(p.hasOwnProperty("x"));
ok(p.hasOwnProperty("y"));
equal("number", typeof p.x);
equal("number", typeof p.y);
deepEqual({x: 50, y: 50}, element.coordinates(domEl));