Bug 1105825 - Fix the toolbox/inspector/sidebar destroy sequence; r=past

This commit is contained in:
Patrick Brosset 2014-12-22 14:54:09 +01:00
parent 7ea173734b
commit 76e51a4719
22 changed files with 80 additions and 101 deletions

View File

@ -7,6 +7,7 @@
const {Cu} = require("chrome");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
var {Promise: promise} = require("resource://gre/modules/Promise.jsm");
var EventEmitter = require("devtools/toolkit/event-emitter");
@ -118,12 +119,17 @@ ToolSidebar.prototype = {
/**
* Remove an existing tab.
*/
removeTab: function(id) {
removeTab: Task.async(function*(id) {
let tab = this._tabbox.tabs.querySelector("tab#sidebar-tab-" + id);
if (!tab) {
return;
}
let win = this.getWindowForTab(id);
if ("destroy" in win) {
yield win.destroy();
}
tab.remove();
let panel = this.getTab(id);
@ -134,7 +140,7 @@ ToolSidebar.prototype = {
this._tabs.delete(id);
this.emit("tab-unregistered", id);
},
}),
/**
* Select a specific tab.
@ -241,7 +247,7 @@ ToolSidebar.prototype = {
/**
* Clean-up.
*/
destroy: function ToolSidebar_destroy() {
destroy: Task.async(function*() {
if (this._destroyed) {
return promise.resolve(null);
}
@ -252,7 +258,12 @@ ToolSidebar.prototype = {
this._tabbox.tabpanels.removeEventListener("select", this, true);
while (this._tabbox.tabpanels.hasChildNodes()) {
this._tabbox.tabpanels.removeChild(this._tabbox.tabpanels.firstChild);
let panel = this._tabbox.tabpanels.firstChild;
let win = panel.firstChild.contentWindow;
if ("destroy" in win) {
yield win.destroy();
}
panel.remove();
}
while (this._tabbox.tabs.hasChildNodes()) {
@ -271,5 +282,5 @@ ToolSidebar.prototype = {
this._toolPanel = null;
return promise.resolve(null);
},
}),
}

View File

@ -1578,9 +1578,12 @@ Toolbox.prototype = {
* @return {promise} to be resolved when the host is destroyed.
*/
destroyHost: function() {
// The host iframe's contentDocument may already be gone.
if (this.doc) {
this.doc.removeEventListener("keypress",
this._splitConsoleOnKeypress, false);
this.doc.removeEventListener("focus", this._onFocus, true);
}
return this._host.destroy();
},
@ -1645,18 +1648,17 @@ Toolbox.prototype = {
// We need to grab a reference to win before this._host is destroyed.
let win = this.frame.ownerGlobal;
// Remove the host UI
outstanding.push(this.destroyHost());
if (this._requisition) {
this._requisition.destroy();
}
this._telemetry.toolClosed("toolbox");
this._telemetry.destroy();
// Finish all outstanding tasks (successfully or not) before destroying the
// Finish all outstanding tasks (which means finish destroying panels and
// then destroying the host, successfully or not) before destroying the
// target.
this._destroyer = promise.all(outstanding).then(null, console.error).then(() => {
this._destroyer = promise.all(outstanding)
.then(() => this.destroyHost()).then(null, console.error).then(() => {
// Targets need to be notified that the toolbox is being torn down.
// This is done after other destruction tasks since it may tear down
// fronts and the debugger transport which earlier destroy methods may

View File

@ -549,7 +549,7 @@ InspectorPanel.prototype = {
this._toolbox.off("select", this.updateDebuggerPausedWarning);
this.sidebar.off("select", this._setDefaultSidebar);
this.sidebar.destroy();
let sidebarDestroyer = this.sidebar.destroy();
this.sidebar = null;
this.nodemenu.removeEventListener("popupshowing", this._setupNodeMenu, true);
@ -561,7 +561,7 @@ InspectorPanel.prototype = {
this.selection.off("before-new-node", this.onBeforeNewSelection);
this.selection.off("before-new-node-front", this.onBeforeNewSelection);
this.selection.off("detached-front", this.onDetached);
this._panelDestroyer = this._destroyMarkup();
let markupDestroyer = this._destroyMarkup();
this.panelWin.inspector = null;
this.target = null;
this.panelDoc = null;
@ -572,6 +572,11 @@ InspectorPanel.prototype = {
this.nodemenu = null;
this._toolbox = null;
this._panelDestroyer = promise.all([
sidebarDestroyer,
markupDestroyer
]);
return this._panelDestroyer;
},

View File

@ -35,6 +35,4 @@ add_task(function*() {
highlightedNode = yield getHighlitNode(toolbox);
is(highlightedNode, getNode("span"), "The highlighter highlights the right node");
gBrowser.removeCurrentTab();
});

View File

@ -17,8 +17,6 @@ add_task(function*() {
let {inspector} = yield openInspector();
yield checkDivHeight(inspector);
gBrowser.removeCurrentTab();
});
function* checkDivHeight(inspector) {

View File

@ -28,6 +28,4 @@ add_task(function*() {
let node = yield getHighlitNode(toolbox);
is(node, getNode("h1"), "The highlighter highlights the right node");
gBrowser.removeCurrentTab();
});

View File

@ -44,6 +44,4 @@ add_task(function*() {
info("Hide the box-model highlighter");
yield toolbox.highlighter.hideBoxModel();
gBrowser.removeCurrentTab();
});

View File

@ -16,8 +16,6 @@ add_task(function*() {
yield manyInstancesOfCustomHighlighters(inspector);
yield showHideMethodsAreAvailable(inspector);
yield unknownHighlighterTypeShouldntBeAccepted(inspector);
gBrowser.removeCurrentTab();
});
function* onlyOneInstanceOfMainHighlighter({inspector}) {

View File

@ -26,8 +26,6 @@ add_task(function*() {
yield linesLinkThePolygons(highlighter, inspector);
yield highlighter.finalize();
gBrowser.removeCurrentTab();
});
function* isHiddenByDefault(highlighterFront, inspector) {

View File

@ -53,8 +53,6 @@ add_task(function*() {
info("Hiding the transform highlighter");
yield highlighter.hide();
yield highlighter.finalize();
gBrowser.removeCurrentTab();
});
function* getAttribute(nodeID, name, {actorID}) {

View File

@ -149,8 +149,6 @@ add_task(function*() {
info("Hide the box-model highlighter");
yield toolbox.highlighter.hideBoxModel();
}
gBrowser.removeCurrentTab();
});
function* getAttribute(nodeID, name, toolbox) {

View File

@ -105,7 +105,6 @@ add_task(function*() {
yield highlighter.hide();
yield highlighter.finalize();
gBrowser.removeCurrentTab();
});
function* getAttribute(highlighter, name) {

View File

@ -33,7 +33,6 @@ add_task(function*() {
yield highlighter.hide();
yield highlighter.finalize();
gBrowser.removeCurrentTab();
});
function* getAttribute(highlighter, name) {

View File

@ -60,5 +60,4 @@ add_task(function*() {
}
yield highlighter.finalize();
gBrowser.removeCurrentTab();
});

View File

@ -58,5 +58,4 @@ add_task(function*() {
}
yield highlighter.finalize();
gBrowser.removeCurrentTab();
});

View File

@ -47,8 +47,6 @@ add_task(function*() {
let style = yield getRootNodeStyle(toolbox);
is(style, expected, "The style attribute of the root element is correct");
}
gBrowser.removeCurrentTab();
});
function* hoverElement(selector, inspector) {

View File

@ -50,8 +50,6 @@ add_task(function*() {
for (let currTest of testData) {
yield testPosition(currTest, inspector);
}
gBrowser.removeCurrentTab();
});
function* testPosition(test, inspector) {

View File

@ -64,7 +64,6 @@ add_task(function*() {
yield newRoot;
Services.prefs.clearUserPref("devtools.command-button-frames.enabled");
gBrowser.removeCurrentTab();
});
function assertMarkupViewIsLoaded(inspector) {

View File

@ -32,15 +32,11 @@ let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
Services.scriptloader.loadSubScript(testDir + "../../../commandline/test/helpers.js", this);
gDevTools.testing = true;
SimpleTest.registerCleanupFunction(() => {
registerCleanupFunction(() => {
gDevTools.testing = false;
});
SimpleTest.registerCleanupFunction(() => {
console.error("Here we are\n");
let {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
console.error("DebuggerServer open connections: " + Object.getOwnPropertyNames(DebuggerServer._connections).length);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("devtools.dump.emit");
Services.prefs.clearUserPref("devtools.inspector.activeSidebar");
});
@ -58,7 +54,6 @@ registerCleanupFunction(function*() {
while (gBrowser.tabs.length > 1) {
gBrowser.removeCurrentTab();
}
});
/**

View File

@ -34,4 +34,6 @@ add_task(function*() {
ok(TimelineController.getInterval().endTime >
TimelineController.getInterval().startTime,
"Some time has passed since the recording started.");
yield TimelineController.toggleRecording();
});

View File

@ -10,32 +10,25 @@ let { isTargetSupported } = Tools.scratchpad;
Tools.scratchpad.isTargetSupported = () => true;
function test()
{
add_task(function*() {
waitForExplicitFinish();
yield loadTab(TEST_URI);
loadTab(TEST_URI).then(() => {
info("Opening toolbox with Scratchpad panel");
let target = TargetFactory.forTab(gBrowser.selectedTab);
gDevTools.showToolbox(target, "scratchpad", "window").then(runTests);
});
}
let toolbox = yield gDevTools.showToolbox(target, "scratchpad", "window");
function runTests(aToolbox)
{
Task.spawn(function*() {
let scratchpadPanel = aToolbox.getPanel("scratchpad");
let scratchpadPanel = toolbox.getPanel("scratchpad");
let { scratchpad } = scratchpadPanel;
is(aToolbox.getCurrentPanel(), scratchpadPanel,
is(toolbox.getCurrentPanel(), scratchpadPanel,
"Scratchpad is currently selected panel");
info("Switching to webconsole panel");
let webconsolePanel = yield aToolbox.selectTool("webconsole");
let webconsolePanel = yield toolbox.selectTool("webconsole");
let { hud } = webconsolePanel;
is(aToolbox.getCurrentPanel(), webconsolePanel,
is(toolbox.getCurrentPanel(), webconsolePanel,
"Webconsole is currently selected panel");
info("console.log()ing from Scratchpad");
@ -53,13 +46,13 @@ function runTests(aToolbox)
ok(matched, "Found logged message from Scratchpad");
let anchor = matched.querySelector("a.message-location");
aToolbox.on("scratchpad-selected", function selected() {
aToolbox.off("scratchpad-selected", selected);
toolbox.on("scratchpad-selected", function selected() {
toolbox.off("scratchpad-selected", selected);
is(aToolbox.getCurrentPanel(), scratchpadPanel,
is(toolbox.getCurrentPanel(), scratchpadPanel,
"Clicking link switches to Scratchpad panel");
is(Services.ww.activeWindow, aToolbox.frame.ownerGlobal,
is(Services.ww.activeWindow, toolbox.frame.ownerGlobal,
"Scratchpad's toolbox is focused");
Tools.scratchpad.isTargetSupported = isTargetSupported;
@ -68,4 +61,3 @@ function runTests(aToolbox)
EventUtils.synthesizeMouse(anchor, 2, 2, {}, hud.iframeWindow);
});
}

View File

@ -319,8 +319,7 @@ let finishTest = Task.async(function* () {
finish();
});
function tearDown()
{
registerCleanupFunction(function*() {
gDevTools.testing = false;
dumpConsoles();
@ -330,14 +329,12 @@ function tearDown()
}
let target = TargetFactory.forTab(gBrowser.selectedTab);
gDevTools.closeToolbox(target);
yield gDevTools.closeToolbox(target);
while (gBrowser.tabs.length > 1) {
gBrowser.removeCurrentTab();
}
}
registerCleanupFunction(tearDown);
});
waitForExplicitFinish();