From 833daaa2b2a9378574c81daff401304803f1f375 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 8 Feb 2019 12:26:03 -0800 Subject: [PATCH] chore: add helper to wait for a window to load in a remote-safe way (#16837) --- spec/chromium-spec.js | 6 +++--- spec/window-helpers.js | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 25a82fdd351c..7c5e09d42f50 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -9,7 +9,7 @@ const url = require('url') const ChildProcess = require('child_process') const { ipcRenderer, remote } = require('electron') const { emittedOnce } = require('./events-helpers') -const { closeWindow } = require('./window-helpers') +const { closeWindow, waitForWebContentsToLoad } = require('./window-helpers') const { resolveGetters } = require('./assert-helpers') const { app, BrowserWindow, ipcMain, protocol, session, webContents } = remote const isCI = remote.getGlobal('isCi') @@ -525,7 +525,7 @@ describe('chromium feature', () => { const w = window.open() try { const [, { webContents }] = await browserWindowCreated - await emittedOnce(webContents, 'did-finish-load') + await waitForWebContentsToLoad(webContents) assert.strictEqual(w.location.href, 'about:blank') } finally { w.close() @@ -537,7 +537,7 @@ describe('chromium feature', () => { const w = window.open('') try { const [, { webContents }] = await browserWindowCreated - await emittedOnce(webContents, 'did-finish-load') + await waitForWebContentsToLoad(webContents) assert.strictEqual(w.location.href, 'about:blank') } finally { w.close() diff --git a/spec/window-helpers.js b/spec/window-helpers.js index 115fc2782039..2efba2a55c16 100644 --- a/spec/window-helpers.js +++ b/spec/window-helpers.js @@ -17,3 +17,10 @@ exports.closeWindow = async (window = null, expect(BrowserWindow.getAllWindows()).to.have.lengthOf(1) } } + +exports.waitForWebContentsToLoad = async (webContents) => { + const didFinishLoadPromise = emittedOnce(webContents, 'did-finish-load') + if (webContents.isLoadingMainFrame()) { + await didFinishLoadPromise + } +}