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

Fix conflict with platformUtil merge and session store merge #9995

Merged
merged 1 commit into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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