Skip to content

Commit

Permalink
test: add focus and blur WebContents event tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Oct 20, 2020
1 parent 2ece0a6 commit 8859d94
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions spec-main/api-web-contents-spec.ts
Expand Up @@ -766,10 +766,10 @@ describe('webContents module', () => {
});
});

describe('focus()', () => {
describe('when the web contents is hidden', () => {
describe.only('focus APIs', () => {
describe('focus()', () => {
afterEach(closeAllWindows);
it('does not blur the focused window', async () => {
it('does not blur the focused window when the web contents is hidden', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
w.show();
await w.loadURL('about:blank');
Expand All @@ -784,6 +784,37 @@ describe('webContents module', () => {
expect(childFocused).to.be.false();
});
});

const waitForDevTools = async (w: BrowserWindow) => {
const opened = emittedOnce(w.webContents, 'devtools-opened');
w.webContents.openDevTools();
await opened;
};

describe('focus event', () => {
afterEach(closeAllWindows);
it('is triggered when web contents is focused', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
await waitForDevTools(w);
w.webContents.devToolsWebContents!.focus();
const focusPromise = emittedOnce(w.webContents, 'focus');
w.webContents.focus();
await expect(focusPromise).to.eventually.be.fulfilled();
});
});

describe('blur event', () => {
afterEach(closeAllWindows);
it('is triggered when web contents is blurred', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
const blurPromise = emittedOnce(w.webContents, 'blur');
await waitForDevTools(w);
w.webContents.devToolsWebContents!.focus();
await expect(blurPromise).to.eventually.be.fulfilled();
});
});
});

describe('getOSProcessId()', () => {
Expand Down

0 comments on commit 8859d94

Please sign in to comment.