feat: Add new powerMonitor synchronous API (#17144)

`powerMonitor.querySystemIdleState` and `powerMonitor.querySystemIdleTime` had async backing APIs in chromium (https://chromium-review.googlesource.com/c/chromium/src/+/1379183). However, that has changed in ch73. So, this PR deprecates the old async APIs and adds new sync APIs.
This commit is contained in:
Nitish Sakhawalkar 2019-02-27 12:54:01 -08:00 committed by John Kleinschmidt
commit bfa07ec4be
7 changed files with 96 additions and 25 deletions

View file

@ -128,6 +128,7 @@ describe('powerMonitor', () => {
powerMonitor = require('electron').remote.powerMonitor
})
// TODO(nitsakh): Remove in 7.0
describe('powerMonitor.querySystemIdleState', () => {
it('notify current system idle state', done => {
// this function is not mocked out, so we can test the result's
@ -155,6 +156,7 @@ describe('powerMonitor', () => {
})
})
// TODO(nitsakh): Remove in 7.0
describe('powerMonitor.querySystemIdleTime', () => {
it('notify current system idle time', done => {
powerMonitor.querySystemIdleTime(idleTime => {
@ -163,5 +165,37 @@ describe('powerMonitor', () => {
})
})
})
describe('powerMonitor.getSystemIdleState', () => {
it('gets current system idle state', () => {
// this function is not mocked out, so we can test the result's
// form and type but not its value.
const idleState = powerMonitor.getSystemIdleState(1)
expect(idleState).to.be.a('string')
const validIdleStates = [ 'active', 'idle', 'locked', 'unknown' ]
expect(validIdleStates).to.include(idleState)
})
it('does not accept non positive integer threshold', () => {
expect(() => {
powerMonitor.getSystemIdleState(-1)
}).to.throw(/must be greater than 0/)
expect(() => {
powerMonitor.getSystemIdleState(NaN)
}).to.throw(/conversion failure/)
expect(() => {
powerMonitor.getSystemIdleState('a')
}).to.throw(/conversion failure/)
})
})
describe('powerMonitor.getSystemIdleTime', () => {
it('notify current system idle time', () => {
const idleTime = powerMonitor.getSystemIdleTime()
expect(idleTime).to.be.at.least(0)
})
})
})
})