browser/base/content/test/general/browser_bug817947.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug817947.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +
     1.8 +const URL = "http://mochi.test:8888/browser/";
     1.9 +const PREF = "browser.sessionstore.restore_on_demand";
    1.10 +
    1.11 +function test() {
    1.12 +  waitForExplicitFinish();
    1.13 +
    1.14 +  Services.prefs.setBoolPref(PREF, true);
    1.15 +  registerCleanupFunction(function () {
    1.16 +    Services.prefs.clearUserPref(PREF);
    1.17 +  });
    1.18 +
    1.19 +  preparePendingTab(function (aTab) {
    1.20 +    let win = gBrowser.replaceTabWithWindow(aTab);
    1.21 +
    1.22 +    whenDelayedStartupFinished(win, function () {
    1.23 +      let [tab] = win.gBrowser.tabs;
    1.24 +
    1.25 +      whenLoaded(tab.linkedBrowser, function () {
    1.26 +        is(tab.linkedBrowser.currentURI.spec, URL, "correct url should be loaded");
    1.27 +        ok(!tab.hasAttribute("pending"), "tab should not be pending");
    1.28 +
    1.29 +        win.close();
    1.30 +        finish();
    1.31 +      });
    1.32 +    });
    1.33 +  });
    1.34 +}
    1.35 +
    1.36 +function preparePendingTab(aCallback) {
    1.37 +  let tab = gBrowser.addTab(URL);
    1.38 +
    1.39 +  whenLoaded(tab.linkedBrowser, function () {
    1.40 +    gBrowser.removeTab(tab);
    1.41 +    let [{state}] = JSON.parse(SessionStore.getClosedTabData(window));
    1.42 +
    1.43 +    tab = gBrowser.addTab("about:blank");
    1.44 +    whenLoaded(tab.linkedBrowser, function () {
    1.45 +      SessionStore.setTabState(tab, JSON.stringify(state));
    1.46 +      ok(tab.hasAttribute("pending"), "tab should be pending");
    1.47 +      aCallback(tab);
    1.48 +    });
    1.49 +  });
    1.50 +}
    1.51 +
    1.52 +function whenLoaded(aElement, aCallback) {
    1.53 +  aElement.addEventListener("load", function onLoad() {
    1.54 +    aElement.removeEventListener("load", onLoad, true);
    1.55 +    executeSoon(aCallback);
    1.56 +  }, true);
    1.57 +}

mercurial