Bug 1378133 - Fix the inspector when loading pages from bfcache. r=jdescottes
MozReview-Commit-ID: Ek2lw4Vh1km
--- a/devtools/client/inspector/test/browser_inspector_navigation.js
+++ b/devtools/client/inspector/test/browser_inspector_navigation.js
@@ -8,16 +8,23 @@
// Test that inspector updates when page is navigated.
const TEST_URL_FILE = "browser/devtools/client/inspector/test/" +
"doc_inspector_breadcrumbs.html";
const TEST_URL_1 = "http://test1.example.org/" + TEST_URL_FILE;
const TEST_URL_2 = "http://test2.example.org/" + TEST_URL_FILE;
+// Bug 1340592: "srcset" attribute causes bfcache events (pageshow/pagehide)
+// with buggy "persisted" values.
+const TEST_URL_3 = "data:text/html;charset=utf-8," +
+ encodeURIComponent("<img src=\"foo.png\" srcset=\"foo.png 1.5x\" />");
+const TEST_URL_4 = "data:text/html;charset=utf-8," +
+ encodeURIComponent("<h1>bar</h1>");
+
add_task(function* () {
let { inspector, testActor } = yield openInspectorForURL(TEST_URL_1);
yield selectNode("#i1", inspector);
info("Navigating to a different page.");
yield navigateTo(inspector, TEST_URL_2);
@@ -36,8 +43,37 @@ add_task(function* () {
info("Check that the inspector updates");
yield onUpdated;
ok(true, "Old page loaded");
is((yield testActor.eval("location.href;")), TEST_URL_1, "URL is correct.");
yield selectNode("#i1", inspector);
});
+
+add_task(function* () {
+ let { inspector, testActor } = yield openInspectorForURL(TEST_URL_3);
+
+ yield selectNode("img", inspector);
+
+ info("Navigating to a different page.");
+ yield navigateTo(inspector, TEST_URL_4);
+
+ ok(true, "New page loaded");
+ yield selectNode("#h1", inspector);
+
+ let markuploaded = inspector.once("markuploaded");
+ let onUpdated = inspector.once("inspector-updated");
+
+ info("Going back in history");
+ yield testActor.eval("history.go(-1)");
+
+ info("Waiting for markup view to load after going back in history.");
+ yield markuploaded;
+
+ info("Check that the inspector updates");
+ yield onUpdated;
+
+ ok(true, "Old page loaded");
+ is((yield testActor.eval("location.href;")), TEST_URL_3, "URL is correct.");
+
+ yield selectNode("img", inspector);
+});
--- a/devtools/server/actors/tab.js
+++ b/devtools/server/actors/tab.js
@@ -1528,29 +1528,33 @@ DebuggerProgressListener.prototype = {
});
},
onWindowCreated: DevToolsUtils.makeInfallible(function (evt) {
if (!this._tabActor.attached) {
return;
}
- // pageshow events for non-persisted pages have already been handled by a
- // prior DOMWindowCreated event. For persisted pages, act as if the window
- // had just been created since it's been unfrozen from bfcache.
- if (evt.type == "pageshow" && !evt.persisted) {
+ let window = evt.target.defaultView;
+ let innerID = getWindowID(window);
+
+ // This method is alled on DOMWindowCreated and pageshow
+ // The common scenario is DOMWindowCreated, which is fired when the document
+ // loads. But we are to listen for pageshow in order to handle BFCache.
+ // When a page does into the BFCache, a pagehide event is fired with persisted=true
+ // but it doesn't necessarely mean persisted will be true for the pageshow
+ // event fired when the page is reloaded from the BFCache (see bug 1378133)
+ // So just check if we already know this window and accept any that isn't known yet
+ if (this._knownWindowIDs.has(innerID)) {
return;
}
- let window = evt.target.defaultView;
this._tabActor._windowReady(window);
- if (evt.type !== "pageshow") {
- this._knownWindowIDs.set(getWindowID(window), window);
- }
+ this._knownWindowIDs.set(innerID, window);
}, "DebuggerProgressListener.prototype.onWindowCreated"),
onWindowHidden: DevToolsUtils.makeInfallible(function (evt) {
if (!this._tabActor.attached) {
return;
}
// Only act as if the window has been destroyed if the 'pagehide' event
@@ -1558,16 +1562,17 @@ DebuggerProgressListener.prototype = {
// and frozen in the bfcache). If the page isn't persisted, the observer's
// inner-window-destroyed event will handle it.
if (!evt.persisted) {
return;
}
let window = evt.target.defaultView;
this._tabActor._windowDestroyed(window, null, true);
+ this._knownWindowIDs.delete(getWindowID(window));
}, "DebuggerProgressListener.prototype.onWindowHidden"),
observe: DevToolsUtils.makeInfallible(function (subject, topic) {
if (!this._tabActor.attached) {
return;
}
// Because this observer will be called for all inner-window-destroyed in