diff --git a/js/state/frameStateUtil.js b/js/state/frameStateUtil.js index b305b0762b3..c716b3aed04 100644 --- a/js/state/frameStateUtil.js +++ b/js/state/frameStateUtil.js @@ -308,7 +308,7 @@ function getFramePropsIndex (frames, frameProps) { function getFrameByLastAccessedTime (frames) { const frameProps = frames.toJS() .reduce((pre, cur) => { - return (cur.pinnedLocation === undefined && + return ([undefined, null].includes(cur.pinnedLocation) && cur.lastAccessedTime && cur.lastAccessedTime > pre.lastAccessedTime ) ? cur : pre @@ -768,5 +768,6 @@ module.exports = { frameStatePathForFrame, tabStatePath, tabStatePathForFrame, - getLastCommittedURL + getLastCommittedURL, + getFrameByLastAccessedTime } diff --git a/test/unit/state/frameStateUtilTest.js b/test/unit/state/frameStateUtilTest.js index 6ef666d78c3..dbc70f315c4 100644 --- a/test/unit/state/frameStateUtilTest.js +++ b/test/unit/state/frameStateUtilTest.js @@ -354,4 +354,42 @@ describe('frameStateUtil', function () { }) }) }) + + describe('getFrameByLastAccessedTime', function () { + let framesWithLastAccessedTime, framesWithoutLastAccessedTime, framesWithNullifiedLastAccessedTime + + beforeEach(function () { + framesWithLastAccessedTime = Immutable.fromJS([ + { key: 2, lastAccessedTime: null }, + { key: 3, lastAccessedTime: 1488184050731 }, + { key: 4, lastAccessedTime: 1488184050711 }, + { key: 5 } + ]) + framesWithoutLastAccessedTime = Immutable.fromJS([ + { key: 2 }, + { key: 3 }, + { key: 4 } + ]) + framesWithNullifiedLastAccessedTime = Immutable.fromJS([ + { key: 2, lastAccessedTime: null }, + { key: 3, lastAccessedTime: null }, + { key: 4, lastAccessedTime: null } + ]) + }) + + it('gets correct frame by last accessed time', function () { + const result = frameStateUtil.getFrameByLastAccessedTime(framesWithLastAccessedTime) + assert.equal(1, result) + }) + + it('returns -1 for frames without last accessed time', function () { + const result = frameStateUtil.getFrameByLastAccessedTime(framesWithoutLastAccessedTime) + assert.equal(-1, result) + }) + + it('returns -1 for frames with nullified last accessed time', function () { + const result = frameStateUtil.getFrameByLastAccessedTime(framesWithNullifiedLastAccessedTime) + assert.equal(-1, result) + }) + }) })