Bug 909121 - Inspector breaks when navigating backwards. r=bgrinstead

This commit is contained in:
Dave Camp 2013-09-09 08:11:22 -07:00
parent 64da54d218
commit 566df7c9a5
4 changed files with 86 additions and 9 deletions

View File

@ -56,8 +56,8 @@ InspectorPanel.prototype = {
_deferredOpen: function(defaultSelection) {
let deferred = promise.defer();
this.onNavigatedAway = this.onNavigatedAway.bind(this);
this.target.on("navigate", this.onNavigatedAway);
this.onNewRoot = this.onNewRoot.bind(this);
this.walker.on("new-root", this.onNewRoot);
this.nodemenu = this.panelDoc.getElementById("inspector-node-popup");
this.lastNodemenuItem = this.nodemenu.lastChild;
@ -292,9 +292,9 @@ InspectorPanel.prototype = {
},
/**
* Reset the inspector on navigate away.
* Reset the inspector on new root mutation.
*/
onNavigatedAway: function InspectorPanel_onNavigatedAway() {
onNewRoot: function InspectorPanel_onNewRoot() {
this._defaultNode = null;
this.selection.setNodeFront(null);
this._destroyMarkup();
@ -448,6 +448,7 @@ InspectorPanel.prototype = {
return this._destroyPromise;
}
if (this.walker) {
this.walker.off("new-root", this.onNewRoot);
this._destroyPromise = this.walker.release().then(null, console.error);
delete this.walker;
delete this.pageStyle;
@ -463,8 +464,6 @@ InspectorPanel.prototype = {
this.browser = null;
}
this.target.off("navigate", this.onNavigatedAway);
if (this.highlighter) {
this.highlighter.off("locked", this.onLockStateChanged);
this.highlighter.off("unlocked", this.onLockStateChanged);

View File

@ -38,6 +38,7 @@ MOCHITEST_BROWSER_FILES := \
browser_inspector_bug_835722_infobar_reappears.js \
browser_inspector_bug_840156_destroy_after_navigation.js \
browser_inspector_reload.js \
browser_inspector_navigation.js \
browser_inspector_select_last_selected.js \
browser_inspector_select_last_selected.html \
browser_inspector_select_last_selected2.html \

View File

@ -0,0 +1,67 @@
/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function test() {
let inspector, toolbox;
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onload() {
gBrowser.selectedBrowser.removeEventListener("load", onload, true);
waitForFocus(function() {
let target = TargetFactory.forTab(gBrowser.selectedTab);
gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
startInspectorTests(toolbox);
}).then(null, console.error);
}, content);
}, true);
content.location = "http://test1.example.org/browser/browser/devtools/inspector/test/browser_inspector_breadcrumbs.html";
function startInspectorTests(aToolbox)
{
toolbox = aToolbox;
inspector = toolbox.getCurrentPanel();
info("Inspector started");
let node = content.document.querySelector("#i1");
inspector.selection.setNode(node);
inspector.once("inspector-updated", () => {
is(inspector.selection.node, node, "Node selected.");
inspector.once("markuploaded", onSecondLoad);
content.location = "http://test2.example.org/browser/browser/devtools/inspector/test/browser_inspector_breadcrumbs.html";
});
}
function onSecondLoad() {
info("New page loaded");
let node = content.document.querySelector("#i1");
inspector.selection.setNode(node);
inspector.once("inspector-updated", () => {
is(inspector.selection.node, node, "Node re-selected.");
inspector.once("markuploaded", onThirdLoad);
content.history.go(-1);
});
}
function onThirdLoad() {
info("Old page loaded");
is(content.location.href, "http://test1.example.org/browser/browser/devtools/inspector/test/browser_inspector_breadcrumbs.html");
let node = content.document.querySelector("#i1");
inspector.selection.setNode(node);
inspector.once("inspector-updated", () => {
is(inspector.selection.node, node, "Node re-selected.");
inspector.once("markuploaded", onThirdLoad);
toolbox.destroy();
gBrowser.removeCurrentTab();
finish();
});
}
}

View File

@ -1848,7 +1848,7 @@ var WalkerFront = exports.WalkerFront = protocol.FrontClass(WalkerActor, {
}),
initialize: function(client, form) {
this._rootNodeDeferred = promise.defer();
this._createRootNodePromise();
protocol.Front.prototype.initialize.call(this, client, form);
this._orphaned = new Set();
this._retainedOrphans = new Set();
@ -1875,6 +1875,17 @@ var WalkerFront = exports.WalkerFront = protocol.FrontClass(WalkerActor, {
return this._rootNodeDeferred.promise;
},
/**
* Create the root node promise, triggering the "new-root" notification
* on resolution.
*/
_createRootNodePromise: function() {
this._rootNodeDeferred = promise.defer();
this._rootNodeDeferred.promise.then(() => {
events.emit(this, "new-root");
});
},
/**
* When reading an actor form off the wire, we want to hook it up to its
* parent front. The protocol guarantees that the parent will be seen
@ -2047,8 +2058,7 @@ var WalkerFront = exports.WalkerFront = protocol.FrontClass(WalkerActor, {
}
} else if (change.type === "documentUnload") {
if (targetFront === this.rootNode) {
this.rootNode = null;
this._rootNodeDeferred = promise.defer();
this._createRootNodePromise();
}
// We try to give fronts instead of actorIDs, but these fronts need