From 6d9b45fcb2da7d4c95f365df0d77e21b0be97b2e Mon Sep 17 00:00:00 2001 From: Alastair Robertson Date: Thu, 8 Sep 2011 12:52:36 +0200 Subject: [PATCH] Bug 665702 - expose session information in getBrowserState. r=zpao --- .../sessionstore/src/nsSessionStore.js | 22 ++++++++++------- .../sessionstore/test/browser/Makefile.in | 1 + .../browser/browser_665702-state_session.js | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 browser/components/sessionstore/test/browser/browser_665702-state_session.js diff --git a/browser/components/sessionstore/src/nsSessionStore.js b/browser/components/sessionstore/src/nsSessionStore.js index 5c15e6e0ccee..d322a8ba174c 100644 --- a/browser/components/sessionstore/src/nsSessionStore.js +++ b/browser/components/sessionstore/src/nsSessionStore.js @@ -2481,7 +2481,19 @@ SessionStoreService.prototype = { if (ix != -1 && total[ix] && total[ix].sizemode == "minimized") ix = -1; - return { windows: total, selectedWindow: ix + 1, _closedWindows: lastClosedWindowsCopy }; + let session = { + state: this._loadState == STATE_RUNNING ? STATE_RUNNING_STR : STATE_STOPPED_STR, + lastUpdate: Date.now(), + startTime: this._sessionStartTime, + recentCrashes: this._recentCrashes + }; + + return { + windows: total, + selectedWindow: ix + 1, + _closedWindows: lastClosedWindowsCopy, + session: session + }; }, /** @@ -3526,14 +3538,6 @@ SessionStoreService.prototype = { } } - oState.session = { - state: this._loadState == STATE_RUNNING ? STATE_RUNNING_STR : STATE_STOPPED_STR, - lastUpdate: Date.now(), - startTime: this._sessionStartTime - }; - if (this._recentCrashes) - oState.session.recentCrashes = this._recentCrashes; - // Persist the last session if we deferred restoring it if (this._lastSessionState) oState.lastSessionState = this._lastSessionState; diff --git a/browser/components/sessionstore/test/browser/Makefile.in b/browser/components/sessionstore/test/browser/Makefile.in index 2f80d4349231..1cdeb039790f 100644 --- a/browser/components/sessionstore/test/browser/Makefile.in +++ b/browser/components/sessionstore/test/browser/Makefile.in @@ -152,6 +152,7 @@ _BROWSER_TEST_FILES = \ browser_645428.js \ browser_659591.js \ browser_662812.js \ + browser_665702-state_session.js \ $(NULL) ifneq ($(OS_ARCH),Darwin) diff --git a/browser/components/sessionstore/test/browser/browser_665702-state_session.js b/browser/components/sessionstore/test/browser/browser_665702-state_session.js new file mode 100644 index 000000000000..aee0f2554cd0 --- /dev/null +++ b/browser/components/sessionstore/test/browser/browser_665702-state_session.js @@ -0,0 +1,24 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +function compareArray(a, b) { + if (a.length !== b.length) { + return false; + } + for (let i = 0; i < a.length; i++) { + if (a[i] !== b[i]) { + return false; + } + } + return true; +} + +function test() { + let currentState = JSON.parse(ss.getBrowserState()); + ok(currentState.session, "session data returned by getBrowserState"); + + let keys = Object.keys(currentState.session); + let expectedKeys = ["state", "lastUpdate", "startTime", "recentCrashes"]; + ok(compareArray(keys.sort(), expectedKeys.sort()), + "session object from getBrowserState has correct keys"); +}