Bug 1215049 - Prevent reopening toolbox when selecting the same project. r=jryans

This commit is contained in:
Alexandre Poirot 2015-10-22 08:06:16 -07:00
parent 1cffee299e
commit 0b30b09e30
2 changed files with 34 additions and 3 deletions

View File

@ -365,10 +365,29 @@ var AppManager = exports.AppManager = {
_selectedProject: null,
set selectedProject(project) {
// A regular comparison still sees a difference when equal in some cases
if (JSON.stringify(this._selectedProject) ===
JSON.stringify(project)) {
// A regular comparison doesn't work as we recreate a new object every time
let prev = this._selectedProject;
if (!prev && !project) {
return;
} else if (prev && project && prev.type === project.type) {
let type = project.type;
if (type === "runtimeApp") {
if (prev.app.manifestURL === project.app.manifestURL) {
return;
}
} else if (type === "tab") {
if (prev.app.actor === project.app.actor) {
return;
}
} else if (type === "packaged" || type === "hosted") {
if (prev.location === project.location) {
return;
}
} else if (type === "mainProcess") {
return;
} else {
throw new Error("Unsupported project type: " + type);
}
}
let cancelled = false;

View File

@ -78,6 +78,18 @@
ok(win.AppManager.isMainProcessDebuggable(), "Main process available");
is(win.AppManager.selectedProject.type, "mainProcess", "Main process reselected");
// Wait for the toolbox to be fully loaded
yield win.UI.toolboxPromise;
// If we happen to pass a project object targeting the same context,
// here, the main process, the `selectedProject` attribute shouldn't be updated
// so that no `project` event would fire.
let oldProject = win.AppManager.selectedProject;
win.AppManager.selectedProject = {
type: "mainProcess"
};
is(win.AppManager.selectedProject, oldProject, "AppManager.selectedProject shouldn't be updated if we selected the same project");
yield win.Cmds.disconnectRuntime();
yield closeWebIDE(win);