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 #9995 from brave/session-store-shutdown
Browse files Browse the repository at this point in the history
Fix conflict with platformUtil merge and session store merge
  • Loading branch information
bsclifton authored Jul 14, 2017
2 parents 8b27a11 + dd1a688 commit fde2175
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 36 deletions.
5 changes: 3 additions & 2 deletions app/sessionStoreShutdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const appConfig = require('../js/constants/appConfig')
const async = require('async')
const messages = require('../js/constants/messages')
const appActions = require('../js/actions/appActions')
const platformUtil = require('./common/lib/platformUtil')

// Used to collect the per window state when shutting down the application
let perWindowState
Expand Down Expand Up @@ -99,7 +100,7 @@ const saveAppState = (forceSave = false) => {
appState.updates.status === updateStatus.UPDATE_AVAILABLE_DEFERRED)) {
// 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 (process.platform === 'win32') {
if (platformUtil.isWindows()) {
appState.updates.status = updateStatus.UPDATE_APPLYING_RESTART
} else {
appState.updates.status = updateStatus.UPDATE_APPLYING_NO_RESTART
Expand Down Expand Up @@ -227,7 +228,7 @@ process.on(messages.UNDO_CLOSED_WINDOW, () => {
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
if (!platformUtil.isDarwin()) {
isAllWindowsClosed = true
app.quit()
}
Expand Down
51 changes: 17 additions & 34 deletions test/unit/app/sessionStoreShutdownTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const sinon = require('sinon')
const Immutable = require('immutable')
const messages = require('../../../js/constants/messages')

let isWindows = false
let isDarwin = false

require('../braveUnit')

const makeSender = (fakeWindow) => ({
Expand Down Expand Up @@ -43,6 +46,10 @@ describe('sessionStoreShutdown unit tests', function () {
}
}
}

const platformUtil = require('../../../app/common/lib/platformUtil')
this.isWindowsStub = sinon.stub(platformUtil, 'isWindows', () => isWindows)
this.isDarwinStub = sinon.stub(platformUtil, 'isDarwin', () => isDarwin)
mockery.registerMock('electron', fakeElectron)
mockery.registerMock('ad-block', fakeAdBlock)
mockery.registerMock('leveldown', {})
Expand All @@ -55,6 +62,8 @@ describe('sessionStoreShutdown unit tests', function () {

after(function () {
this.clock.restore()
this.isWindowsStub.restore()
this.isDarwinStub.restore()
mockery.disable()
})

Expand All @@ -65,36 +74,27 @@ describe('sessionStoreShutdown unit tests', function () {
describe('windows all closed', function () {
before(function () {
this.appQuitSpy = sinon.spy(fakeElectron.app, 'quit')
this.oldPlatform = process.platform
sessionStoreShutdown.reset()
})
afterEach(function () {
this.appQuitSpy.reset()
})
after(function () {
Object.defineProperty(process, 'platform', {
value: this.oldPlatform
})
this.appQuitSpy.restore()
})
it('does not quit on macOS', function () {
Object.defineProperty(process, 'platform', {
value: 'darwin'
})
isDarwin = true
fakeElectron.app.emit('window-all-closed')
assert.equal(this.appQuitSpy.notCalled, true)
isDarwin = false
})
it('quits on windows', function () {
Object.defineProperty(process, 'platform', {
value: 'win32'
})
isWindows = true
fakeElectron.app.emit('window-all-closed')
assert.equal(this.appQuitSpy.calledOnce, true)
isWindows = false
})
it('quits on linux', function () {
Object.defineProperty(process, 'platform', {
value: 'linux'
})
fakeElectron.app.emit('window-all-closed')
assert.equal(this.appQuitSpy.calledOnce, true)
})
Expand Down Expand Up @@ -173,17 +173,12 @@ describe('sessionStoreShutdown unit tests', function () {
this.clock.tick(1)
})
it('remembers last closed window with no windows (Win32)', function (cb) {
const oldPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'win32'
})
isWindows = true
const windowState = { a: 1 }
fakeElectron.ipcMain.send(messages.LAST_WINDOW_STATE, {}, windowState)
fakeElectron.app.emit('window-all-closed')
const saveAppStateStub = sinon.stub(sessionStore, 'saveAppState', (state) => {
Object.defineProperty(process, 'platform', {
value: oldPlatform
})
isWindows = false
assert.equal(saveAppStateStub.calledOnce, true)
saveAppStateStub.restore()
assert.equal(state.perWindowState.length, 1)
Expand All @@ -195,17 +190,10 @@ describe('sessionStoreShutdown unit tests', function () {
this.clock.tick(1)
})
it('remembers last closed window with no windows (Linux)', function (cb) {
const oldPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'linux'
})
const windowState = { a: 1 }
fakeElectron.ipcMain.send(messages.LAST_WINDOW_STATE, {}, windowState)
fakeElectron.app.emit('window-all-closed')
const saveAppStateStub = sinon.stub(sessionStore, 'saveAppState', (state) => {
Object.defineProperty(process, 'platform', {
value: oldPlatform
})
assert.equal(saveAppStateStub.calledOnce, true)
saveAppStateStub.restore()
assert.equal(state.perWindowState.length, 1)
Expand All @@ -217,17 +205,12 @@ describe('sessionStoreShutdown unit tests', function () {
this.clock.tick(1)
})
it('remembers last closed window with no windows (macOS)', function (cb) {
const oldPlatform = process.platform
Object.defineProperty(process, 'platform', {
value: 'darwin'
})
isDarwin = true
const windowState = { a: 1 }
fakeElectron.ipcMain.send(messages.LAST_WINDOW_STATE, {}, windowState)
fakeElectron.app.emit('window-all-closed')
const saveAppStateStub = sinon.stub(sessionStore, 'saveAppState', (state) => {
Object.defineProperty(process, 'platform', {
value: oldPlatform
})
isDarwin = false
assert.equal(saveAppStateStub.calledOnce, true)
saveAppStateStub.restore()
assert.equal(state.perWindowState.length, 0)
Expand Down

0 comments on commit fde2175

Please sign in to comment.