browser/components/sessionstore/test/browser_618151.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_618151.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const stateBackup = ss.getBrowserState();
     1.9 +const testState = {
    1.10 +  windows: [{
    1.11 +    tabs: [
    1.12 +      { entries: [{ url: "about:blank" }] },
    1.13 +      { entries: [{ url: "about:mozilla" }] }
    1.14 +    ]
    1.15 +  }]
    1.16 +};
    1.17 +
    1.18 +
    1.19 +function test() {
    1.20 +  /** Test for Bug 618151 - Overwriting state can lead to unrestored tabs **/
    1.21 +  waitForExplicitFinish();
    1.22 +  runNextTest();
    1.23 +}
    1.24 +
    1.25 +// Just a subset of tests from bug 615394 that causes a timeout.
    1.26 +let tests = [test_setup, test_hang];
    1.27 +function runNextTest() {
    1.28 +  // set an empty state & run the next test, or finish
    1.29 +  if (tests.length) {
    1.30 +    // Enumerate windows and close everything but our primary window. We can't
    1.31 +    // use waitForFocus() because apparently it's buggy. See bug 599253.
    1.32 +    var windowsEnum = Services.wm.getEnumerator("navigator:browser");
    1.33 +    while (windowsEnum.hasMoreElements()) {
    1.34 +      var currentWindow = windowsEnum.getNext();
    1.35 +      if (currentWindow != window) {
    1.36 +        currentWindow.close();
    1.37 +      }
    1.38 +    }
    1.39 +
    1.40 +    let currentTest = tests.shift();
    1.41 +    info("running " + currentTest.name);
    1.42 +    waitForBrowserState(testState, currentTest);
    1.43 +  }
    1.44 +  else {
    1.45 +    ss.setBrowserState(stateBackup);
    1.46 +    executeSoon(finish);
    1.47 +  }
    1.48 +}
    1.49 +
    1.50 +function test_setup() {
    1.51 +  function onSSTabRestored(aEvent) {
    1.52 +    gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false);
    1.53 +    runNextTest();
    1.54 +  }
    1.55 +
    1.56 +  gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, false);
    1.57 +  ss.setTabState(gBrowser.tabs[1], JSON.stringify({
    1.58 +    entries: [{ url: "http://example.org" }],
    1.59 +    extData: { foo: "bar" } }));
    1.60 +}
    1.61 +
    1.62 +function test_hang() {
    1.63 +  ok(true, "test didn't time out");
    1.64 +  runNextTest();
    1.65 +}

mercurial