Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #11169 from syuan100/fix/10768
Browse files Browse the repository at this point in the history
Remove perWindowState from immutableData if there are no frames in it
  • Loading branch information
bsclifton authored Nov 20, 2017
2 parents 080820a + 63c3284 commit 5ec0b99
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
14 changes: 13 additions & 1 deletion app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const autofill = require('./autofill')
const {navigatableTypes} = require('../js/lib/appUrlUtil')
const Channel = require('./channel')
const BuildConfig = require('./buildConfig')
const {isImmutable, makeImmutable, deleteImmutablePaths} = require('./common/state/immutableUtil')
const {isImmutable, isMap, makeImmutable, deleteImmutablePaths} = require('./common/state/immutableUtil')
const {getSetting} = require('../js/settings')
const platformUtil = require('./common/lib/platformUtil')
const historyUtil = require('./common/lib/historyUtil')
Expand Down Expand Up @@ -430,6 +430,18 @@ module.exports.cleanAppData = (immutableData, isShutdown) => {
immutableData = immutableData.deleteIn(['ledger', 'locations'])
}

// Remove windowState from perWindowState if there are no frames
// ex: if window only had a single private tab, let's remove it (they aren't saved)
if (perWindowStateList) {
perWindowStateList.forEach((immutablePerWindowState, i) => {
if (isMap(immutablePerWindowState) && immutablePerWindowState.has('frames')) {
if (!immutablePerWindowState.get('frames').size) {
immutableData = immutableData.deleteIn(['perWindowState', i])
}
}
})
}

return immutableData
}

Expand Down
24 changes: 22 additions & 2 deletions test/unit/app/sessionStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,35 @@ describe('sessionStore unit tests', function () {
})

describe('if perWindowState is present', function () {
let cleanPerWindowDataStub
before(function () {
cleanPerWindowDataStub = sinon.stub(sessionStore, 'cleanPerWindowData', (state) => state)
})
after(function () {
cleanPerWindowDataStub.restore()
})
it('calls cleanPerWindowData for each item', function () {
const cleanPerWindowDataStub = sinon.stub(sessionStore, 'cleanPerWindowData')
const data = Immutable.fromJS({
perWindowState: ['window1', 'window2']
})
sessionStore.cleanAppData(data, 'IS_SHUTDOWN_VALUE')
assert.equal(cleanPerWindowDataStub.withArgs('window1', 'IS_SHUTDOWN_VALUE').calledOnce, true)
assert.equal(cleanPerWindowDataStub.withArgs('window2', 'IS_SHUTDOWN_VALUE').calledOnce, true)
cleanPerWindowDataStub.restore()
})

it('removes state for windows which have no frames', function () {
let data = Immutable.fromJS({
perWindowState: [{
id: 1,
frames: []
}, {
id: 2,
frames: [1, 2, 3]
}]
})
const result = sessionStore.cleanAppData(data)
assert.equal(result.get('perWindowState').size, 1)
assert.equal(result.getIn(['perWindowState', 0, 'id']), 2)
})
})

Expand Down

0 comments on commit 5ec0b99

Please sign in to comment.