Bug 1396182 - Wait for the styleditor animations to be done before running tests; r=ochameau
MozReview-Commit-ID: 2QiW1E5RroI
--- 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);