Bug 1277657 - Wait for mozAfterPaint after creating span in inplace-editor tests;r?miker draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 03 Jun 2016 11:51:45 +0200
changeset 375663 03658e1654f968302d287b0d287f3874f95cdc7a
parent 375662 806e37e584aabb83e3cadaf9e833c17ed516a843
child 522930 af4d001997771cd027049c7f586d929b411cbbd2
push id20342
push userjdescottes@mozilla.com
push dateMon, 06 Jun 2016 12:14:12 +0000
reviewersmiker
bugs1277657
milestone49.0a1
Bug 1277657 - Wait for mozAfterPaint after creating span in inplace-editor tests;r?miker MozReview-Commit-ID: KLmR2kdWVdI
devtools/client/shared/test/helper_inplace_editor.js
--- a/devtools/client/shared/test/helper_inplace_editor.js
+++ b/devtools/client/shared/test/helper_inplace_editor.js
@@ -1,44 +1,52 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 /* eslint no-unused-vars: [2, {"vars": "local", "args": "none"}] */
+/* import-globals-from head.js */
 
 "use strict";
 
 /**
  * Helper methods for the HTMLTooltip integration tests.
  */
 
 const { editableField } = require("devtools/client/shared/inplace-editor");
 
 /**
  * Create an inplace editor linked to a span element and click on the span to
- * to turn to edit mode.
+ * to turn to edit mode. Returns a promise that will resolve once the span has been
+ * rendered and received a click.
  *
  * @param {Object} options
  *        Options passed to the InplaceEditor/editableField constructor.
  * @param {Document} doc
  *        Document where the span element will be created.
  * @param {String} textContent
  *        (optional) String that will be used as the text content of the span.
+ * @return {Promise} promise that resolves when the span is painted and clicked.
  */
-function createInplaceEditorAndClick(options, doc, textContent) {
+const createInplaceEditorAndClick = Task.async(function* (options, doc, textContent) {
   doc.body.innerHTML = "";
+
+  let onSpanReady = once(doc.defaultView, "MozAfterPaint");
   let span = options.element = createSpan(doc);
   if (textContent) {
     span.textContent = textContent;
   }
 
+  // Wait for the span to be painted before interacting.
+  yield onSpanReady;
+
   info("Creating an inplace-editor field");
   editableField(options);
 
   info("Clicking on the inplace-editor field to turn to edit mode");
   span.click();
-}
+});
 
 /**
  * Helper to create a span in the provided document.
  *
  * @param {Document} doc
  *        Document where the span element will be created.
  * @return {Element} the created span element.
  */