Bug 1321516 - Remove Selenium displayedness check; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Sat, 10 Dec 2016 17:52:44 -1000
changeset 448596 4621bf3406a294990954ab506978ef9c3be8746e
parent 448593 1aed65fe80ef18b9b98ed43cf4022148b06e8997
child 539320 86a8960dee919165a2d88db1e9b85d0b4427ae99
push id38375
push userbmo:ato@mozilla.com
push dateSun, 11 Dec 2016 04:08:24 +0000
reviewersautomatedtester
bugs1321516
milestone53.0a1
Bug 1321516 - Remove Selenium displayedness check; r?automatedtester MozReview-Commit-ID: AuiqD7zg98V
testing/marionette/element.js
testing/marionette/event.js
testing/marionette/interaction.js
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -874,55 +874,16 @@ element.inViewport = function(el, x = un
   };
 
   return (vp.left <= c.x + win.pageXOffset &&
       c.x + win.pageXOffset <= vp.right &&
       vp.top <= c.y + win.pageYOffset &&
       c.y + win.pageYOffset <= vp.bottom);
 };
 
-/**
- * This function throws the visibility of the element error if the element is
- * not displayed or the given coordinates are not within the viewport.
- *
- * @param {Element} element
- *     Element to check if visible.
- * @param {Window} window
- *     Window object.
- * @param {number=} x
- *     Horizontal offset relative to target.  Defaults to the centre of
- *     the target's bounding box.
- * @param {number=} y
- *     Vertical offset relative to target.  Defaults to the centre of
- *     the target's bounding box.
- *
- * @return {boolean}
- *     True if visible, false otherwise.
- */
-element.isVisible = function(el, x = undefined, y = undefined) {
-  let win = el.ownerDocument.defaultView;
-
-  // Bug 1094246: webdriver's isShown doesn't work with content xul
-  if (!element.isXULElement(el) && !atom.isElementDisplayed(el, win)) {
-    return false;
-  }
-
-  if (el.tagName.toLowerCase() == "body") {
-    return true;
-  }
-
-  if (!element.inViewport(el, x, y)) {
-    element.scrollIntoView(el);
-    if (!element.inViewport(el)) {
-      return false;
-    }
-  }
-  return true;
-};
-
 element.isInteractable = function(el) {
   return element.isPointerInteractable(el) ||
       element.isKeyboardInteractable(el);
 };
 
 /**
  * A pointer-interactable element is defined to be the first
  * non-transparent element, defined by the paint order found at the centre
--- a/testing/marionette/event.js
+++ b/testing/marionette/event.js
@@ -1255,33 +1255,37 @@ function focusElement(element) {
  * @param {Array.<string>} keySequence
  * @param {Element} element
  * @param {Object.<string, boolean>=} opts
  * @param {Window=} window
  */
 event.sendKeysToElement = function(
     keySequence, el, opts = {}, window = undefined) {
 
-  if (opts.ignoreVisibility || element.isVisible(el)) {
-    focusElement(el);
+  // TODO(ato): Replace this with isKeyboardInteractable,
+  // but this is not defined in the WebDriver spec yet
+  if (!element.isPointerInteractable(el)) {
+    element.scrollIntoView(el);
+  }
+  if (!opts.ignoreVisibility && !element.isPointerInteractable(el)) {
+    throw new ElementNotVisibleError();
+  }
 
-    // make Object.<modifier, false> map
-    let modifiers = Object.create(event.Modifiers);
-    for (let modifier in event.Modifiers) {
-      modifiers[modifier] = false;
-    }
+  focusElement(el);
 
-    let value = keySequence.join("");
-    for (let i = 0; i < value.length; i++) {
-      let c = value.charAt(i);
-      event.sendSingleKey(c, modifiers, window);
-    }
+  // make Object.<modifier, false> map
+  let modifiers = Object.create(event.Modifiers);
+  for (let modifier in event.Modifiers) {
+    modifiers[modifier] = false;
+  }
 
-  } else {
-    throw new ElementNotVisibleError("Element is not visible");
+  let value = keySequence.join("");
+  for (let i = 0; i < value.length; i++) {
+    let c = value.charAt(i);
+    event.sendSingleKey(c, modifiers, window);
   }
 };
 
 event.sendEvent = function(eventType, el, modifiers = {}, opts = {}) {
   opts.canBubble = opts.canBubble || true;
 
   let doc = el.ownerDocument || el.document;
   let ev = doc.createEvent("Event");
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -79,71 +79,58 @@ const SELECTED_PROPERTY_SUPPORTED_XUL = 
 this.interaction = {};
 
 /**
  * Interact with an element by clicking it.
  *
  * The element is scrolled into view before visibility- or interactability
  * checks are performed.
  *
- * Selenium-style visibility checks will be performed if |specCompat|
- * is false (default).  Otherwise pointer-interactability checks will be
- * performed.  If either of these fail an {@code ElementNotVisibleError}
- * is returned.
- *
  * If |strict| is enabled (defaults to disabled), further accessibility
  * checks will be performed, and these may result in an {@code
  * ElementNotAccessibleError} being returned.
  *
  * When |el| is not enabled, an {@code InvalidElementStateError}
  * is returned.
  *
  * @param {DOMElement|XULElement} el
  *     Element to click.
  * @param {boolean=} strict
  *     Enforce strict accessibility tests.
- * @param {boolean=} specCompat
- *     Use WebDriver specification compatible interactability definition.
  *
  * @throws {ElementNotVisibleError}
  *     If either Selenium-style visibility check or
  *     pointer-interactability check fails.
  * @throws {ElementNotAccessibleError}
  *     If |strict| is true and element is not accessible.
  * @throws {InvalidElementStateError}
  *     If |el| is not enabled.
  */
-interaction.clickElement = function*(el, strict = false, specCompat = false) {
+interaction.clickElement = function*(el, strict = false) {
   let win = getWindow(el);
   let a11y = accessibility.get(strict);
 
   let visibilityCheckEl  = el;
   if (el.localName == "option") {
     visibilityCheckEl = interaction.getSelectForOptionElement(el);
   }
 
-  let interactable = false;
-  if (specCompat) {
-    if (!element.isPointerInteractable(visibilityCheckEl)) {
-      element.scrollIntoView(el);
-    }
-    interactable = element.isPointerInteractable(visibilityCheckEl);
-  } else {
-    interactable = element.isVisible(visibilityCheckEl);
+  if (!element.isPointerInteractable(visibilityCheckEl)) {
+    element.scrollIntoView(el);
   }
-  if (!interactable) {
+  if (!element.isPointerInteractable(visibilityCheckEl)) {
     throw new ElementNotVisibleError();
   }
 
   if (!atom.isElementEnabled(el)) {
     throw new InvalidElementStateError("Element is not enabled");
   }
 
   yield a11y.getAccessible(el, true).then(acc => {
-    a11y.assertVisible(acc, el, interactable);
+    a11y.assertVisible(acc, el, true);
     a11y.assertEnabled(acc, el, true);
     a11y.assertActionable(acc, el);
   });
 
   // chrome elements
   if (element.isXULElement(el)) {
     if (el.localName == "option") {
       interaction.selectOption(el);