refactor: printing implementation (#15143)
* refactor: basic printing * move build files to chromium_src/BUILD.gn * remove dependency on chrome prerender sources * spec: move printing specs behind feature flag * build: register pdf compositor service
This commit is contained in:
parent
53642b2b17
commit
82322968a3
23 changed files with 780 additions and 1073 deletions
|
@ -10,6 +10,7 @@ const { emittedOnce } = require('./events-helpers')
|
|||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
|
||||
const features = process.atomBinding('features')
|
||||
const { ipcRenderer, remote, clipboard } = require('electron')
|
||||
const { BrowserWindow, webContents, ipcMain, session } = remote
|
||||
const { expect } = chai
|
||||
|
@ -943,4 +944,61 @@ describe('webContents module', () => {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPrinterList()', () => {
|
||||
before(function () {
|
||||
if (!features.isPrintingEnabled()) {
|
||||
return closeWindow(w).then(() => {
|
||||
w = null
|
||||
this.skip()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('can get printer list', (done) => {
|
||||
w.destroy()
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
sandbox: true
|
||||
}
|
||||
})
|
||||
w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E')
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
const printers = w.webContents.getPrinters()
|
||||
assert.strictEqual(Array.isArray(printers), true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('printToPDF()', () => {
|
||||
before(function () {
|
||||
if (!features.isPrintingEnabled()) {
|
||||
return closeWindow(w).then(() => {
|
||||
w = null
|
||||
this.skip()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('can print to PDF', (done) => {
|
||||
w.destroy()
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
sandbox: true
|
||||
}
|
||||
})
|
||||
w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E')
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
w.webContents.printToPDF({}, function (error, data) {
|
||||
assert.strictEqual(error, null)
|
||||
assert.strictEqual(data instanceof Buffer, true)
|
||||
assert.notStrictEqual(data.length, 0)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue