From b0809e3b17ec215986e90722bc4a75902b2ff574 Mon Sep 17 00:00:00 2001 From: Misak Khachatryan Date: Sat, 5 Nov 2011 13:36:06 +0400 Subject: [PATCH] Bug 698557 - Port Bug 665702 [expose session information in getBrowserState]. r=Neil --- suite/common/src/nsSessionStore.js | 22 +++++++++------- suite/common/tests/browser/Makefile.in | 1 + .../browser/browser_665702-state_session.js | 25 +++++++++++++++++++ 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 suite/common/tests/browser/browser_665702-state_session.js diff --git a/suite/common/src/nsSessionStore.js b/suite/common/src/nsSessionStore.js index c62eb6107c..060ca3c6a1 100644 --- a/suite/common/src/nsSessionStore.js +++ b/suite/common/src/nsSessionStore.js @@ -2210,7 +2210,19 @@ SessionStoreService.prototype = { if (ix != -1 && 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 + }; }, /** @@ -3182,14 +3194,6 @@ SessionStoreService.prototype = { if (!oState) return; - 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; - this._saveStateObject(oState); }, diff --git a/suite/common/tests/browser/Makefile.in b/suite/common/tests/browser/Makefile.in index 71e1cc57ad..f5d780204e 100644 --- a/suite/common/tests/browser/Makefile.in +++ b/suite/common/tests/browser/Makefile.in @@ -103,6 +103,7 @@ _BROWSER_FILES = \ browser_607016.js \ browser_615394-SSWindowState_events.js \ browser_625257.js \ + browser_665702-state_session.js \ browser_694378.js \ browser_isempty.js \ browser_markPageAsFollowedLink.js \ diff --git a/suite/common/tests/browser/browser_665702-state_session.js b/suite/common/tests/browser/browser_665702-state_session.js new file mode 100644 index 0000000000..e467337313 --- /dev/null +++ b/suite/common/tests/browser/browser_665702-state_session.js @@ -0,0 +1,25 @@ +/* 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"]; + info("keys "+JSON.stringify(keys.sort())+" expectedKeys "+JSON.stringify(expectedKeys.sort())); + ok(compareArray(keys.sort(), expectedKeys.sort()), + "session object from getBrowserState has correct keys"); +}