michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let stateBackup = JSON.parse(ss.getBrowserState()); michael@0: michael@0: function test() { michael@0: /** Test for Bug 600545 **/ michael@0: waitForExplicitFinish(); michael@0: testBug600545(); michael@0: } michael@0: michael@0: function testBug600545() { michael@0: // Set the pref to false to cause non-app tabs to be stripped out on a save michael@0: Services.prefs.setBoolPref("browser.sessionstore.resume_from_crash", false); michael@0: Services.prefs.setIntPref("browser.sessionstore.interval", 2000); michael@0: michael@0: registerCleanupFunction(function () { michael@0: Services.prefs.clearUserPref("browser.sessionstore.resume_from_crash"); michael@0: Services.prefs.clearUserPref("browser.sessionstore.interval"); michael@0: }); michael@0: michael@0: // This tests the following use case: When multiple windows are open michael@0: // and browser.sessionstore.resume_from_crash preference is false, michael@0: // tab session data for non-active window is stripped for non-pinned michael@0: // tabs. This occurs after "sessionstore-state-write-complete" michael@0: // fires which will only fire in this case if there is at least one michael@0: // pinned tab. michael@0: let state = { windows: [ michael@0: { michael@0: tabs: [ michael@0: { entries: [{ url: "http://example.org#0" }], pinned:true }, michael@0: { entries: [{ url: "http://example.com#1" }] }, michael@0: { entries: [{ url: "http://example.com#2" }] }, michael@0: ], michael@0: selected: 2 michael@0: }, michael@0: { michael@0: tabs: [ michael@0: { entries: [{ url: "http://example.com#3" }] }, michael@0: { entries: [{ url: "http://example.com#4" }] }, michael@0: { entries: [{ url: "http://example.com#5" }] }, michael@0: { entries: [{ url: "http://example.com#6" }] } michael@0: ], michael@0: selected: 3 michael@0: } michael@0: ] }; michael@0: michael@0: waitForBrowserState(state, function() { michael@0: // Need to wait for SessionStore's saveState function to be called michael@0: // so that non-pinned tabs will be stripped from non-active window michael@0: waitForSaveState(function () { michael@0: let expectedNumberOfTabs = getStateTabCount(state); michael@0: let retrievedState = JSON.parse(ss.getBrowserState()); michael@0: let actualNumberOfTabs = getStateTabCount(retrievedState); michael@0: michael@0: is(actualNumberOfTabs, expectedNumberOfTabs, michael@0: "Number of tabs in retreived session data, matches number of tabs set."); michael@0: michael@0: done(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function done() { michael@0: // Enumerate windows and close everything but our primary window. We can't michael@0: // use waitForFocus() because apparently it's buggy. See bug 599253. michael@0: let windowsEnum = Services.wm.getEnumerator("navigator:browser"); michael@0: while (windowsEnum.hasMoreElements()) { michael@0: let currentWindow = windowsEnum.getNext(); michael@0: if (currentWindow != window) michael@0: currentWindow.close(); michael@0: } michael@0: michael@0: waitForBrowserState(stateBackup, finish); michael@0: } michael@0: michael@0: // Count up the number of tabs in the state data michael@0: function getStateTabCount(aState) { michael@0: let tabCount = 0; michael@0: for (let i in aState.windows) michael@0: tabCount += aState.windows[i].tabs.length; michael@0: return tabCount; michael@0: }