Skip to content

Commit

Permalink
chore: add helper to wait for a window to load in a remote-safe way (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Feb 8, 2019
1 parent 1632c4b commit 833daaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions spec/chromium-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions spec/window-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 833daaa

Please sign in to comment.