Commit 28cac4b7 authored by Tim Taubert's avatar Tim Taubert
Browse files

Bug 707862 - Reset childCount on SHEntry when all children have been removed; r=smaug

parent 97bb2ea4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ _BROWSER_TEST_FILES = \
	browser_687710_2.js \
	browser_694378.js \
	browser_705597.js \
	browser_707862.js \
	$(NULL)

ifneq ($(OS_ARCH),Darwin)
+56 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

let tabState = {
  entries: [{url: "about:home", children: [{url: "about:mozilla"}]}]
};

function test() {
  waitForExplicitFinish();

  let tab = gBrowser.addTab("about:blank");
  registerCleanupFunction(function () gBrowser.removeTab(tab));

  let browser = tab.linkedBrowser;

  whenBrowserLoaded(browser, function () {
    ss.setTabState(tab, JSON.stringify(tabState));

    let sessionHistory = browser.sessionHistory;
    let entry = sessionHistory.getEntryAtIndex(0, false);

    whenChildCount(entry, 1, function () {
      whenChildCount(entry, 2, function () {
        whenBrowserLoaded(browser, function () {
          let sessionHistory = browser.sessionHistory;
          let entry = sessionHistory.getEntryAtIndex(0, false);

          whenChildCount(entry, 0, finish);
        });

        // reload the browser to deprecate the subframes
        browser.reload();
      });

      // create a dynamic subframe
      let doc = browser.contentDocument;
      let iframe = doc.createElement("iframe");
      iframe.setAttribute("src", "about:mozilla");
      doc.body.appendChild(iframe);
    });
  });
}

function whenBrowserLoaded(aBrowser, aCallback) {
  aBrowser.addEventListener("load", function onLoad() {
    aBrowser.removeEventListener("load", onLoad, true);
    executeSoon(aCallback);
  }, true);
}

function whenChildCount(aEntry, aChildCount, aCallback) {
  if (aEntry.childCount == aChildCount)
    aCallback();
  else
    executeSoon(function () whenChildCount(aEntry, aChildCount, aCallback));
}
+9 −1
Original line number Diff line number Diff line
@@ -655,8 +655,16 @@ nsSHEntry::RemoveChild(nsISHEntry * aChild)
      childRemoved = mChildren.ReplaceObjectAt(nsnull, index);
    }
  }
  if (childRemoved)
  if (childRemoved) {
    aChild->SetParent(nsnull);

    // reduce the child count, i.e. remove empty children at the end
    for (PRInt32 i = mChildren.Count() - 1; i >= 0 && !mChildren[i]; --i) {
      if (!mChildren.RemoveObjectAt(i)) {
        break;
      }
    }
  }
  return NS_OK;
}