Bug 1388082 - Switch to async/await in interaction module. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 07 Aug 2017 18:56:29 +0100
changeset 645934 2f121a4e009352c15f558ef39b349fb9bcf06eed
parent 645933 1c195a22b4304c819a9fef747706e177e3a195cf
child 645935 7ea257026743495e61dd35cab75dce59f0579f6c
push id73947
push userbmo:ato@sny.no
push dateMon, 14 Aug 2017 16:03:22 +0000
reviewersautomatedtester
bugs1388082
milestone57.0a1
Bug 1388082 - Switch to async/await in interaction module. r?automatedtester MozReview-Commit-ID: 2aUUrT3KXRF
testing/marionette/interaction.js
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -344,25 +344,25 @@ interaction.flushEventLoop = async funct
 /**
  * Appends <var>path</var> to an <tt>&lt;input type=file&gt;</tt>'s
  * file list.
  *
  * @param {HTMLInputElement} el
  *     An <tt>&lt;input type=file&gt;</tt> element.
  * @param {string} path
  *     Full path to file.
+ *
+ * @throws {InvalidArgumentError}
+ *     If <var>path</var> can not be found.
  */
-interaction.uploadFile = function* (el, path) {
-  let file = yield File.createFromFileName(path).then(file => {
-    return file;
-  }, () => {
-    return null;
-  });
-
-  if (!file) {
+interaction.uploadFile = async function(el, path) {
+  let file;
+  try {
+    file = await File.createFromFileName(path);
+  } catch (e) {
     throw new InvalidArgumentError("File not found: " + path);
   }
 
   let fs = Array.prototype.slice.call(el.files);
   fs.push(file);
 
   // <input type=file> opens OS widget dialogue
   // which means the mousedown/focus/mouseup/click events
@@ -385,17 +385,17 @@ interaction.uploadFile = function* (el, 
  * @param {DOMElement} el
  *     An form element, e.g. input, textarea, etc.
  * @param {string} value
  *     The value to be set.
  *
  * @throws {TypeError}
  *     If <var>el</var> is not an supported form element.
  */
-interaction.setFormControlValue = function* (el, value) {
+interaction.setFormControlValue = function(el, value) {
   if (!COMMON_FORM_CONTROLS.has(el.localName)) {
     throw new TypeError("This function is for form elements only");
   }
 
   el.value = value;
 
   if (INPUT_TYPES_NO_EVENT.has(el.type)) {
     return;
@@ -412,24 +412,23 @@ interaction.setFormControlValue = functi
  *     Element to send key events to.
  * @param {Array.<string>} value
  *     Sequence of keystrokes to send to the element.
  * @param {boolean} ignoreVisibility
  *     Flag to enable or disable element visibility tests.
  * @param {boolean=} [strict=false] strict
  *     Enforce strict accessibility tests.
  */
-interaction.sendKeysToElement = function(
+interaction.sendKeysToElement = async function(
     el, value, ignoreVisibility, strict = false) {
   let win = getWindow(el);
   let a11y = accessibility.get(strict);
-  return a11y.getAccessible(el, true).then(acc => {
-    a11y.assertActionable(acc, el);
-    event.sendKeysToElement(value, el, {ignoreVisibility: false}, win);
-  });
+  let acc = await a11y.getAccessible(el, true);
+  a11y.assertActionable(acc, el);
+  event.sendKeysToElement(value, el, {ignoreVisibility: false}, win);
 };
 
 /**
  * Determine the element displayedness of an element.
  *
  * @param {DOMElement|XULElement} el
  *     Element to determine displayedness of.
  * @param {boolean=} [strict=false] strict