test: move WebContentsView spec (#19990)
This commit is contained in:
parent
c03288f458
commit
c819fbe852
3 changed files with 14 additions and 18 deletions
3
spec-main/ambient.d.ts
vendored
3
spec-main/ambient.d.ts
vendored
|
@ -28,6 +28,9 @@ declare namespace Electron {
|
||||||
setContentView(view: View): void
|
setContentView(view: View): void
|
||||||
}
|
}
|
||||||
class View {}
|
class View {}
|
||||||
|
class WebContentsView {
|
||||||
|
constructor(webContents: WebContents)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'dbus-native';
|
declare module 'dbus-native';
|
||||||
|
|
|
@ -1,30 +1,23 @@
|
||||||
'use strict'
|
import { expect } from 'chai'
|
||||||
|
import * as ChildProcess from 'child_process'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { emittedOnce } from './events-helpers'
|
||||||
|
import { closeWindow } from './window-helpers'
|
||||||
|
|
||||||
const chai = require('chai')
|
import { webContents, TopLevelWindow, WebContentsView } from 'electron'
|
||||||
const ChildProcess = require('child_process')
|
|
||||||
const dirtyChai = require('dirty-chai')
|
|
||||||
const path = require('path')
|
|
||||||
const { emittedOnce } = require('./events-helpers')
|
|
||||||
const { closeWindow } = require('./window-helpers')
|
|
||||||
|
|
||||||
const { remote } = require('electron')
|
|
||||||
const { webContents, TopLevelWindow, WebContentsView } = remote
|
|
||||||
|
|
||||||
const { expect } = chai
|
|
||||||
chai.use(dirtyChai)
|
|
||||||
|
|
||||||
describe('WebContentsView', () => {
|
describe('WebContentsView', () => {
|
||||||
let w = null
|
let w: TopLevelWindow
|
||||||
afterEach(() => closeWindow(w).then(() => { w = null }))
|
afterEach(() => closeWindow(w as any).then(() => { w = null as unknown as TopLevelWindow }))
|
||||||
|
|
||||||
it('can be used as content view', () => {
|
it('can be used as content view', () => {
|
||||||
const web = webContents.create({})
|
const web = (webContents as any).create({})
|
||||||
w = new TopLevelWindow({ show: false })
|
w = new TopLevelWindow({ show: false })
|
||||||
w.setContentView(new WebContentsView(web))
|
w.setContentView(new WebContentsView(web))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('prevents adding same WebContents', () => {
|
it('prevents adding same WebContents', () => {
|
||||||
const web = webContents.create({})
|
const web = (webContents as any).create({})
|
||||||
w = new TopLevelWindow({ show: false })
|
w = new TopLevelWindow({ show: false })
|
||||||
w.setContentView(new WebContentsView(web))
|
w.setContentView(new WebContentsView(web))
|
||||||
expect(() => {
|
expect(() => {
|
||||||
|
@ -35,7 +28,7 @@ describe('WebContentsView', () => {
|
||||||
describe('new WebContentsView()', () => {
|
describe('new WebContentsView()', () => {
|
||||||
it('does not crash on exit', async () => {
|
it('does not crash on exit', async () => {
|
||||||
const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontentsview.js')
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontentsview.js')
|
||||||
const electronPath = remote.getGlobal('process').execPath
|
const electronPath = process.execPath
|
||||||
const appProcess = ChildProcess.spawn(electronPath, [appPath])
|
const appProcess = ChildProcess.spawn(electronPath, [appPath])
|
||||||
const [code] = await emittedOnce(appProcess, 'close')
|
const [code] = await emittedOnce(appProcess, 'close')
|
||||||
expect(code).to.equal(0)
|
expect(code).to.equal(0)
|
Loading…
Add table
Add a link
Reference in a new issue