Bug 1147765 - Fix console and style inspector tests that interact with style editor. r=ejpbruel

CLOSED TREE
This commit is contained in:
Sami Jaktholm 2015-03-21 19:03:35 +02:00
parent d5e336131a
commit 039793baf6
2 changed files with 21 additions and 11 deletions

View File

@ -916,21 +916,37 @@ function waitForStyleEditor(toolbox, href) {
let def = promise.defer();
info("Waiting for the toolbox to switch to the styleeditor");
toolbox.once("styleeditor-ready").then(() => {
toolbox.once("styleeditor-selected").then(() => {
let panel = toolbox.getCurrentPanel();
ok(panel && panel.UI, "Styleeditor panel switched to front");
panel.UI.on("editor-selected", function onEditorSelected(event, editor) {
// A helper that resolves the promise once it receives an editor that
// matches the expected href. Returns false if the editor was not correct.
let gotEditor = (event, editor) => {
let currentHref = editor.styleSheet.href;
if (!href || (href && currentHref.endsWith(href))) {
info("Stylesheet editor selected");
panel.UI.off("editor-selected", onEditorSelected);
panel.UI.off("editor-selected", gotEditor);
editor.getSourceEditor().then(editor => {
info("Stylesheet editor fully loaded");
def.resolve(editor);
});
return true;
}
});
info("The editor was incorrect. Waiting for editor-selected event.");
return false;
};
// The expected editor may already be selected. Check the if the currently
// selected editor is the expected one and if not wait for an
// editor-selected event.
if (!gotEditor("styleeditor-selected", panel.UI.selectedEditor)) {
// The expected editor is not selected (yet). Wait for it.
panel.UI.on("editor-selected", gotEditor);
}
});
return def.promise;

View File

@ -48,13 +48,7 @@ function testViewSource()
let toolbox = gDevTools.getToolbox(target);
toolbox.once("styleeditor-selected", (event, panel) => {
StyleEditorUI = panel.UI;
let count = 0;
StyleEditorUI.on("editor-added", function() {
if (++count == 2) {
deferred.resolve(panel);
}
});
deferred.resolve(panel);
});
EventUtils.sendMouseEvent({ type: "click" }, nodes[0]);