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 #10380 from brave/10374
Browse files Browse the repository at this point in the history
Store changes for all immutable sets
  • Loading branch information
bbondy committed Aug 10, 2017
1 parent 1194c1c commit beac410
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ module.exports.saveAppState = (immutablePayload, isShutdown) => {

try {
immutablePayload = module.exports.cleanAppData(immutablePayload, isShutdown)
immutablePayload.set('cleanedOnShutdown', isShutdown)
immutablePayload = immutablePayload.set('cleanedOnShutdown', isShutdown)
} catch (e) {
immutablePayload.set('cleanedOnShutdown', false)
immutablePayload = immutablePayload.set('cleanedOnShutdown', false)
}
immutablePayload.set('lastAppVersion', app.getVersion())
immutablePayload = immutablePayload.set('lastAppVersion', app.getVersion())

if (isShutdown) {
module.exports.cleanSessionDataOnShutdown()
Expand Down Expand Up @@ -173,7 +173,7 @@ module.exports.cleanPerWindowData = (immutablePerWindowData, isShutdown) => {
// If a blob is present for the thumbnail, create the object URL
if (immutableFrame.get('thumbnailBlob')) {
try {
immutableFrame.set('thumbnailUrl', window.URL.createObjectURL(immutableFrame.get('thumbnailBlob')))
immutableFrame = immutableFrame.set('thumbnailUrl', window.URL.createObjectURL(immutableFrame.get('thumbnailBlob')))
} catch (e) {
immutableFrame = immutableFrame.delete('thumbnailUrl')
}
Expand Down Expand Up @@ -252,7 +252,7 @@ module.exports.cleanPerWindowData = (immutablePerWindowData, isShutdown) => {
}
if (immutablePerWindowData.get('frames')) {
// Don't restore pinned locations because they will be auto created by the app state change event
immutablePerWindowData.set('frames',
immutablePerWindowData = immutablePerWindowData.set('frames',
immutablePerWindowData.get('frames')
.filter((frame) => !frame.get('pinnedLocation')))
immutablePerWindowData =
Expand Down
4 changes: 2 additions & 2 deletions app/sessionStoreShutdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ const saveAppState = (forceSave = false) => {
// In this case on win32, the process doesn't try to auto restart, so avoid the user
// having to open the app twice. Maybe squirrel detects the app is already shutting down.
if (platformUtil.isWindows()) {
immutableAppState.setIn(['updates', 'status'], updateStatus.UPDATE_APPLYING_RESTART)
immutableAppState = immutableAppState.setIn(['updates', 'status'], updateStatus.UPDATE_APPLYING_RESTART)
} else {
immutableAppState.setIn(['updates', 'status'], updateStatus.UPDATE_APPLYING_NO_RESTART)
immutableAppState = immutableAppState.setIn(['updates', 'status'], updateStatus.UPDATE_APPLYING_NO_RESTART)
}
}

Expand Down
55 changes: 52 additions & 3 deletions test/unit/app/sessionStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,61 @@ describe('sessionStore unit tests', function () {
cleanSessionDataOnShutdownStub.restore()
})

it('calls cleanAppData', function () {
it('calls cleanAppData', function (cb) {
cleanAppDataStub.reset()
return sessionStore.saveAppState(Immutable.Map())
.then(function (result) {
assert.equal(cleanAppDataStub.calledOnce, true)
cb()
}, function (err) {
assert(!err)
})
})

describe('with isShutdown', function () {
it('calls cleanSessionDataOnShutdown if true', function () {
before(function () {
this.writeImportantSpy = sinon.spy(muon.file, 'writeImportant')
})
after(function () {
this.writeImportantSpy.restore()
})
it('calls cleanSessionDataOnShutdown if true', function (cb) {
cleanSessionDataOnShutdownStub.reset()
return sessionStore.saveAppState(Immutable.Map(), true)
.then(() => {
assert.equal(cleanSessionDataOnShutdownStub.calledOnce, true)
cb()
}, function (err) {
assert(!err)
})
})

it('does not call cleanSessionDataOnShutdown if false', function () {
it('does not call cleanSessionDataOnShutdown if false', function (cb) {
cleanSessionDataOnShutdownStub.reset()
return sessionStore.saveAppState(Immutable.Map(), false)
.then(() => {
assert.equal(cleanSessionDataOnShutdownStub.notCalled, true)
cb()
}, function (err) {
assert(!err)
})
})

it('sets cleanedOnShutdown for saveAppState', function (cb) {
sessionStore.saveAppState(Immutable.Map(), true)
.then(() => {
assert.equal(JSON.parse(this.writeImportantSpy.getCall(0).args[1]).cleanedOnShutdown, true)
cb()
}, function (err) {
assert(!err)
})
})

it('sets lastAppVersion for saveAppState', function (cb) {
sessionStore.saveAppState(Immutable.Map(), true)
.then(() => {
assert.equal(JSON.parse(this.writeImportantSpy.getCall(0).args[1]).lastAppVersion, '0.14.0')
cb()
}, function (err) {
assert(!err)
})
Expand All @@ -156,6 +185,26 @@ describe('sessionStore unit tests', function () {
})

describe('cleanPerWindowData', function () {
it('clears pinned frames', function () {
const data = Immutable.fromJS({frames: [
{
location: 'https://brave.com/cezar/master/ken/fight',
pinnedLocation: 'https://brave.com/cezar/master/ken/fight'
}, {
key: 1,
location: 'https://brave.com/cezar/monkey/fights/dragon',
src: 'https://brave.com/cezar/monkey/fights/dragon',
unloaded: true
}
]})
const result = sessionStore.cleanPerWindowData(data, true)
assert.deepEqual(result.get('frames').toJS(), [{
key: 1,
location: 'https://brave.com/cezar/monkey/fights/dragon',
src: 'https://brave.com/cezar/monkey/fights/dragon',
unloaded: true
}])
})
})

describe('cleanAppData', function () {
Expand Down

0 comments on commit beac410

Please sign in to comment.