2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// For these tests we use a fake DBus daemon to verify powerMonitor module
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// interaction with the system bus. This requires python-dbusmock installed and
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// running (with the DBUS_SYSTEM_BUS_ADDRESS environment variable set).
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-27 15:49:02 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// script/spec-runner.js will take care of spawning the fake DBus daemon and setting
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// DBUS_SYSTEM_BUS_ADDRESS when python-dbusmock is installed.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// See https://pypi.python.org/pypi/python-dbusmock for more information about
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// python-dbusmock.
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const chai = require('chai')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const dirtyChai = require('dirty-chai')
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const dbus = require('dbus-native')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const Promise = require('bluebird')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const { expect } = chai
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								chai.use(dirtyChai)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const skip = process.platform !== 'linux' || !process.env.DBUS_SYSTEM_BUS_ADDRESS
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 00:32:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								describe('powerMonitor', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  let logindMock, dbusMockPowerMonitor, getCalls, emitSignal, reset
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if (!skip) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    before(async () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      const systemBus = dbus.systemBus()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      const loginService = systemBus.getService('org.freedesktop.login1')
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      const getInterface = Promise.promisify(loginService.getInterface, { context: loginService })
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      logindMock = await getInterface('/org/freedesktop/login1', 'org.freedesktop.DBus.Mock')
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      getCalls = Promise.promisify(logindMock.GetCalls, { context: logindMock })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      emitSignal = Promise.promisify(logindMock.EmitSignal, { context: logindMock })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      reset = Promise.promisify(logindMock.Reset, { context: logindMock })
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 00:32:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    after(async () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      await reset()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  (skip ? describe.skip : describe)('when powerMonitor module is loaded with dbus mock', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    function onceMethodCalled (done) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      function cb () {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        logindMock.removeListener('MethodCalled', cb)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      done()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      return cb
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    before(done => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      logindMock.on('MethodCalled', onceMethodCalled(done))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      // lazy load powerMonitor after we listen to MethodCalled mock signal
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      dbusMockPowerMonitor = require('electron').remote.powerMonitor
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it('should call Inhibit to delay suspend', async () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      const calls = await getCalls()
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      expect(calls).to.be.an('array').that.has.lengthOf(1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      expect(calls[0].slice(1)).to.deep.equal([
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        'Inhibit', [
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          [[{ type: 's', child: [] }], ['sleep']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          [[{ type: 's', child: [] }], ['electron']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          [[{ type: 's', child: [] }], ['Application cleanup before suspend']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          [[{ type: 's', child: [] }], ['delay']]
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      ])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('when PrepareForSleep(true) signal is sent by logind', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('should emit "suspend" event', (done) => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dbusMockPowerMonitor.once('suspend', () => done())
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        emitSignal('org.freedesktop.login1.Manager', 'PrepareForSleep',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          'b', [['b', true]])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      describe('when PrepareForSleep(false) signal is sent by logind', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should emit "resume" event', done => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          dbusMockPowerMonitor.once('resume', () => done())
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          emitSignal('org.freedesktop.login1.Manager', 'PrepareForSleep',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            'b', [['b', false]])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        it('should have called Inhibit again', async () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const calls = await getCalls()
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          expect(calls).to.be.an('array').that.has.lengthOf(2)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(calls[1].slice(1)).to.deep.equal([
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            'Inhibit', [
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              [[{ type: 's', child: [] }], ['sleep']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              [[{ type: 's', child: [] }], ['electron']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              [[{ type: 's', child: [] }], ['Application cleanup before suspend']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              [[{ type: 's', child: [] }], ['delay']]
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          ])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-12 14:06:45 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('when a listener is added to shutdown event', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      before(async () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const calls = await getCalls()
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(calls).to.be.an('array').that.has.lengthOf(2)
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dbusMockPowerMonitor.once('shutdown', () => { })
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-12 14:06:45 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('should call Inhibit to delay shutdown', async () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const calls = await getCalls()
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(calls).to.be.an('array').that.has.lengthOf(3)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(calls[2].slice(1)).to.deep.equal([
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-12 14:06:45 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          'Inhibit', [
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            [[{ type: 's', child: [] }], ['shutdown']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [[{ type: 's', child: [] }], ['electron']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [[{ type: 's', child: [] }], ['Ensure a clean shutdown']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [[{ type: 's', child: [] }], ['delay']]
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-12 14:06:45 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      describe('when PrepareForShutdown(true) signal is sent by logind', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should emit "shutdown" event', done => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          dbusMockPowerMonitor.once('shutdown', () => { done() })
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-12 14:06:45 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          emitSignal('org.freedesktop.login1.Manager', 'PrepareForShutdown',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            'b', [['b', true]])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  })
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  describe('when powerMonitor module is loaded', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let powerMonitor
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    before(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      powerMonitor = require('electron').remote.powerMonitor
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-27 12:54:01 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // TODO(nitsakh): Remove in 7.0
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    describe('powerMonitor.querySystemIdleState', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it('notify current system idle state', done => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 00:32:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // this function is not mocked out, so we can test the result's
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // form and type but not its value.
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        powerMonitor.querySystemIdleState(1, idleState => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 00:32:19 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          expect(idleState).to.be.a('string')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const validIdleStates = [ 'active', 'idle', 'locked', 'unknown' ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(validIdleStates).to.include(idleState)
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          done()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('does not accept non positive integer threshold', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          powerMonitor.querySystemIdleState(-1, (idleState) => {})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }).to.throw()
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          powerMonitor.querySystemIdleState(NaN, (idleState) => {})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }).to.throw()
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          powerMonitor.querySystemIdleState('a', (idleState) => {})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }).to.throw()
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-27 12:54:01 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // TODO(nitsakh): Remove in 7.0
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    describe('powerMonitor.querySystemIdleTime', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-31 13:52:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it('notify current system idle time', done => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        powerMonitor.querySystemIdleTime(idleTime => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(idleTime).to.be.at.least(0)
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          done()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-27 12:54:01 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  })
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-04 16:52:07 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								})
							 |