Bug 1396182 - Wait for the styleditor animations to be done before running tests; r=ochameau
authorPatrick Brosset <pbrosset@mozilla.com>
Mon, 11 Sep 2017 10:34:06 +0200
changeset 430368 2b4360780665ef3ddf3e96d04041a8c191a633ce
parent 430367 2194f20eac24ac06a91fbc8b34d478fa82bc0a82
child 430369 df71f64a2925339d0f431b07bdef74a61555c198
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1396182
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1396182 - Wait for the styleditor animations to be done before running tests; r=ochameau MozReview-Commit-ID: 2QiW1E5RroI
devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_sourcemaps.js
devtools/client/styleeditor/test/head.js
--- a/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_sourcemaps.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_sourcemaps.js
@@ -12,19 +12,19 @@ const LABELS = ["screen and (max-width: 
                 "screen and (min-width: 1200px)"];
 const LINE_NOS = [5, 8];
 
 waitForExplicitFinish();
 
 add_task(function* () {
   Services.prefs.setBoolPref(MAP_PREF, true);
 
-  let { ui } = yield openStyleEditorForURL(TESTCASE_URI);
+  let { ui, onMediaListChanged } = yield openStyleEditorForURL(TESTCASE_URI);
 
-  yield listenForMediaChange(ui);
+  yield onMediaListChanged;
 
   is(ui.editors.length, 1, "correct number of editors");
 
   // Test editor with @media rules
   let mediaEditor = ui.editors[0];
   yield openEditor(mediaEditor);
   testMediaEditor(mediaEditor);
 
@@ -53,19 +53,11 @@ function testRule(rule, text, lineno) {
 /* Helpers */
 
 function openEditor(editor) {
   getLinkFor(editor).click();
 
   return editor.getSourceEditor();
 }
 
-function listenForMediaChange(UI) {
-  return new Promise(resolve => {
-    UI.once("media-list-changed", () => {
-      resolve();
-    });
-  });
-}
-
 function getLinkFor(editor) {
   return editor.summary.querySelector(".stylesheet-name");
 }
--- a/devtools/client/styleeditor/test/head.js
+++ b/devtools/client/styleeditor/test/head.js
@@ -77,17 +77,25 @@ var openStyleEditor = Task.async(functio
   if (!tab) {
     tab = gBrowser.selectedTab;
   }
   let target = TargetFactory.forTab(tab);
   let toolbox = yield gDevTools.showToolbox(target, "styleeditor");
   let panel = toolbox.getPanel("styleeditor");
   let ui = panel.UI;
 
-  return { toolbox, panel, ui };
+  // This event is sometimes needed by tests, but may be emitted before the list
+  // animation is done. So we listen to it here so tests don't have to and can't miss it.
+  let onMediaListChanged = ui.once("media-list-changed");
+
+  // The stylesheet list appears with an animation. Let this animation finish.
+  let animations = ui._root.getAnimations({subtree: true});
+  yield Promise.all(animations.map(a => a.finished));
+
+  return { toolbox, panel, ui, onMediaListChanged };
 });
 
 /**
  * Creates a new tab in specified window navigates it to the given URL and
  * opens style editor in it.
  */
 var openStyleEditorForURL = Task.async(function* (url, win) {
   let tab = yield addTab(url, win);