test: ensure legacy callback functions work (#16436)
* test: test legacy callback functions * add TODO removal comments * fix callback spec
This commit is contained in:
parent
720197f9c8
commit
f105c84349
6 changed files with 114 additions and 9 deletions
|
@ -33,7 +33,7 @@ Object.assign(app, {
|
|||
}
|
||||
})
|
||||
|
||||
app.getFileIcon = deprecate.promisify(app.getFileIcon, 2)
|
||||
app.getFileIcon = deprecate.promisify(app.getFileIcon, 3)
|
||||
|
||||
const nativeAppMetrics = app.getAppMetrics
|
||||
app.getAppMetrics = () => {
|
||||
|
|
|
@ -20,6 +20,6 @@ Object.setPrototypeOf(Session.prototype, EventEmitter.prototype)
|
|||
Object.setPrototypeOf(Cookies.prototype, EventEmitter.prototype)
|
||||
|
||||
Session.prototype._init = function () {
|
||||
this.protocol.isProtocolHandled = deprecate.promisify(this.protocol.isProtocolHandled, 1)
|
||||
this.protocol.isProtocolHandled = deprecate.promisify(this.protocol.isProtocolHandled, 2)
|
||||
app.emit('session-created', this)
|
||||
}
|
||||
|
|
|
@ -334,7 +334,7 @@ WebContents.prototype._init = function () {
|
|||
// render-view-deleted event, so ignore the listeners warning.
|
||||
this.setMaxListeners(0)
|
||||
|
||||
this.capturePage = deprecate.promisify(this.capturePage, 1)
|
||||
this.capturePage = deprecate.promisify(this.capturePage, 2)
|
||||
|
||||
// Dispatch IPC messages to the ipc module.
|
||||
this.on('ipc-message', function (event, [channel, ...args]) {
|
||||
|
|
|
@ -836,7 +836,7 @@ describe('app module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('getFileIcon() API', () => {
|
||||
describe('getFileIcon() API', (done) => {
|
||||
const iconPath = path.join(__dirname, 'fixtures/assets/icon.ico')
|
||||
const sizes = {
|
||||
small: 16,
|
||||
|
@ -858,6 +858,14 @@ describe('app module', () => {
|
|||
expect(icon.isEmpty()).to.be.false()
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('fetches a non-empty icon (callback)', () => {
|
||||
app.getFileIcon(iconPath, (icon) => {
|
||||
expect(icon.isEmpty()).to.be.false()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('fetches normal icon size by default', async () => {
|
||||
const icon = await app.getFileIcon(iconPath)
|
||||
const size = icon.getSize()
|
||||
|
@ -866,6 +874,17 @@ describe('app module', () => {
|
|||
expect(size.width).to.equal(sizes.normal)
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('fetches normal icon size by default (callback)', () => {
|
||||
app.getFileIcon(iconPath, (icon) => {
|
||||
const size = icon.getSize()
|
||||
|
||||
expect(size.height).to.equal(sizes.normal)
|
||||
expect(size.width).to.equal(sizes.normal)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('size option', () => {
|
||||
it('fetches a small icon', async () => {
|
||||
const icon = await app.getFileIcon(iconPath, { size: 'small' })
|
||||
|
@ -883,6 +902,17 @@ describe('app module', () => {
|
|||
expect(size.width).to.equal(sizes.normal)
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('fetches a normal icon (callback)', () => {
|
||||
app.getFileIcon(iconPath, { size: 'normal' }, (icon) => {
|
||||
const size = icon.getSize()
|
||||
|
||||
expect(size.height).to.equal(sizes.normal)
|
||||
expect(size.width).to.equal(sizes.normal)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('fetches a large icon', async () => {
|
||||
// macOS does not support large icons
|
||||
if (process.platform === 'darwin') return
|
||||
|
|
|
@ -483,7 +483,7 @@ describe('BrowserWindow module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('BrowserWindow.getFocusedWindow()', (done) => {
|
||||
describe('BrowserWindow.getFocusedWindow()', () => {
|
||||
it('returns the opener window when dev tools window is focused', (done) => {
|
||||
w.show()
|
||||
w.webContents.once('devtools-focused', () => {
|
||||
|
@ -494,7 +494,7 @@ describe('BrowserWindow module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('BrowserWindow.capturePage(rect)', () => {
|
||||
describe('BrowserWindow.capturePage(rect)', (done) => {
|
||||
it('returns a Promise with a Buffer', async () => {
|
||||
const image = await w.capturePage({
|
||||
x: 0,
|
||||
|
@ -506,6 +506,19 @@ describe('BrowserWindow module', () => {
|
|||
expect(image.isEmpty()).to.be.true()
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('returns a Promise with a Buffer (callback)', () => {
|
||||
w.capturePage({
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
}, (image) => {
|
||||
expect(image.isEmpty()).to.be.true()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('preserves transparency', async () => {
|
||||
const w = await openTheWindow({
|
||||
show: false,
|
||||
|
@ -525,6 +538,28 @@ describe('BrowserWindow module', () => {
|
|||
// Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha
|
||||
expect(imgBuffer[25]).to.equal(6)
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('preserves transparency (callback)', async () => {
|
||||
const w = await openTheWindow({
|
||||
show: false,
|
||||
width: 400,
|
||||
height: 400,
|
||||
transparent: true
|
||||
})
|
||||
const p = emittedOnce(w, 'ready-to-show')
|
||||
w.loadURL('data:text/html,<html><body background-color: rgba(255,255,255,0)></body></html>')
|
||||
await p
|
||||
w.show()
|
||||
|
||||
w.capturePage((image) => {
|
||||
const imgBuffer = image.toPNG()
|
||||
// Check the 25th byte in the PNG.
|
||||
// Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha
|
||||
expect(imgBuffer[25]).to.equal(6)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('BrowserWindow.setBounds(bounds[, animate])', () => {
|
||||
|
|
|
@ -656,17 +656,33 @@ describe('protocol module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('protocol.isProtocolHandled', () => {
|
||||
describe('protocol.isProtocolHandled', (done) => {
|
||||
it('returns true for about:', async () => {
|
||||
const result = await protocol.isProtocolHandled('about')
|
||||
assert.strictEqual(result, true)
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('returns true for about: (callback)', () => {
|
||||
protocol.isProtocolHandled('about', (result) => {
|
||||
assert.strictEqual(result, true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('returns true for file:', async () => {
|
||||
const result = await protocol.isProtocolHandled('file')
|
||||
assert.strictEqual(result, true)
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('returns true for file: (callback)', () => {
|
||||
protocol.isProtocolHandled('file', (result) => {
|
||||
assert.strictEqual(result, true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('returns true for http:', async () => {
|
||||
const result = await protocol.isProtocolHandled('http')
|
||||
assert.strictEqual(result, true)
|
||||
|
@ -682,7 +698,7 @@ describe('protocol module', () => {
|
|||
assert.strictEqual(result, false)
|
||||
})
|
||||
|
||||
it('returns true for custom protocol', (done) => {
|
||||
it('returns true for custom protocol', () => {
|
||||
const emptyHandler = (request, callback) => callback()
|
||||
protocol.registerStringProtocol(protocolName, emptyHandler, async (error) => {
|
||||
assert.strictEqual(error, null)
|
||||
|
@ -692,7 +708,19 @@ describe('protocol module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
it('returns true for intercepted protocol', (done) => {
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('returns true for custom protocol (callback)', () => {
|
||||
const emptyHandler = (request, callback) => callback()
|
||||
protocol.registerStringProtocol(protocolName, emptyHandler, (error) => {
|
||||
assert.strictEqual(error, null)
|
||||
protocol.isProtocolHandled(protocolName, (result) => {
|
||||
assert.strictEqual(result, true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('returns true for intercepted protocol', () => {
|
||||
const emptyHandler = (request, callback) => callback()
|
||||
protocol.interceptStringProtocol('http', emptyHandler, async (error) => {
|
||||
assert.strictEqual(error, null)
|
||||
|
@ -701,6 +729,18 @@ describe('protocol module', () => {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when promisification is complete
|
||||
it('returns true for intercepted protocol (callback)', () => {
|
||||
const emptyHandler = (request, callback) => callback()
|
||||
protocol.interceptStringProtocol('http', emptyHandler, (error) => {
|
||||
assert.strictEqual(error, null)
|
||||
protocol.isProtocolHandled('http', (result) => {
|
||||
assert.strictEqual(result, true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('protocol.intercept(Any)Protocol', () => {
|
||||
|
|
Loading…
Reference in a new issue