From 87d67a9365e5af6a1bd2b8f449b01ea41c5b4844 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Mon, 14 Sep 2020 13:49:57 -0700 Subject: [PATCH] refactor: use owner window for BrowserWindow.fromWebContents (#25408) --- spec-main/api-browser-window-spec.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 99edf2f6729a..2a3fe6d8f546 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -1579,6 +1579,30 @@ describe('BrowserWindow module', () => { contents.destroy(); } }); + + it('returns the correct window for a BrowserView webcontents', async () => { + const w = new BrowserWindow({ show: false }); + const bv = new BrowserView(); + w.setBrowserView(bv); + defer(() => { + w.removeBrowserView(bv); + (bv.webContents as any).destroy(); + }); + await bv.webContents.loadURL('about:blank'); + expect(BrowserWindow.fromWebContents(bv.webContents)!.id).to.equal(w.id); + }); + + it('returns the correct window for a WebView webcontents', async () => { + const w = new BrowserWindow({ show: false, webPreferences: { webviewTag: true } }); + w.loadURL('data:text/html,'); + // NOTE(nornagon): Waiting for 'did-attach-webview' is a workaround for + // https://github.com/electron/electron/issues/25413, and is not integral + // to the test. + const p = emittedOnce(w.webContents, 'did-attach-webview'); + const [, webviewContents] = await emittedOnce(app, 'web-contents-created'); + expect(BrowserWindow.fromWebContents(webviewContents)!.id).to.equal(w.id); + await p; + }); }); describe('BrowserWindow.openDevTools()', () => {