Bug 1378133 - Fix the inspector when loading pages from bfcache. r=jdescottes
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 24 Jul 2017 15:55:42 +0200
changeset 419333 b4c1365ff9419c7cde5b5e61759c2f19598598c9
parent 419332 14eb6424b03d36ccb2d4c2bd99893706e7a81d9b
child 419334 27b5181a3c773020e5e6b659c0d951e75d7ee581
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1378133
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1378133 - Fix the inspector when loading pages from bfcache. r=jdescottes MozReview-Commit-ID: Ek2lw4Vh1km
devtools/client/inspector/test/browser_inspector_navigation.js
devtools/server/actors/tab.js
--- 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