chore: make WebContentsView take webPreferences as parameter (#22997)

* chore: add WebContentsView.webContents helper

* chore: no need to handle webContents option

* chore: Create WebContentsView in C++

* chore: make WebContentsView accept web_preferences

* fix: nativeWindowOpen still passes WebContents to BrowserWindow

* chore: no more need of WebContentsViewRelay

* test: WebContentsView now takes options

* fix: avoid creating 2 constructors
This commit is contained in:
Cheng Zhao 2020-04-09 16:01:16 +09:00 committed by GitHub
parent de893360f7
commit ca947307db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 92 deletions

View file

@ -4,25 +4,15 @@ import * as path from 'path';
import { emittedOnce } from './events-helpers';
import { closeWindow } from './window-helpers';
import { webContents, TopLevelWindow, WebContentsView } from 'electron/main';
import { TopLevelWindow, WebContentsView } from 'electron/main';
describe('WebContentsView', () => {
let w: TopLevelWindow;
afterEach(() => closeWindow(w as any).then(() => { w = null as unknown as TopLevelWindow; }));
it('can be used as content view', () => {
const web = (webContents as any).create({});
w = new TopLevelWindow({ show: false });
w.setContentView(new WebContentsView(web));
});
it('prevents adding same WebContents', () => {
const web = (webContents as any).create({});
w = new TopLevelWindow({ show: false });
w.setContentView(new WebContentsView(web));
expect(() => {
w.setContentView(new WebContentsView(web));
}).to.throw('The WebContents has already been added to a View');
w.setContentView(new WebContentsView({}));
});
describe('new WebContentsView()', () => {
@ -50,9 +40,8 @@ describe('WebContentsView', () => {
}
it('doesn\'t crash when GCed during allocation', (done) => {
const web = (webContents as any).create({});
// eslint-disable-next-line no-new
new WebContentsView(web);
new WebContentsView({});
setTimeout(() => {
// NB. the crash we're testing for is the lack of a current `v8::Context`
// when emitting an event in WebContents's destructor. V8 is inconsistent