mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: add focusOnNavigation flag to WebPreferences (#49511)
* feat: add focusOnNavigation webPreference Co-authored-by: Kyle Cutler <kycutler@microsoft.com> * WebContentsView tests Co-authored-by: Kyle Cutler <kycutler@microsoft.com> * fix Co-authored-by: Kyle Cutler <kycutler@microsoft.com> * fix Co-authored-by: Kyle Cutler <kycutler@microsoft.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Kyle Cutler <kycutler@microsoft.com>
This commit is contained in:
@@ -1610,6 +1610,35 @@ describe('webContents module', () => {
|
||||
await expect(blurPromise).to.eventually.be.fulfilled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('focusOnNavigation webPreference', () => {
|
||||
afterEach(closeAllWindows);
|
||||
|
||||
it('focuses the webContents on navigation by default', async () => {
|
||||
const w = new BrowserWindow({ show: true });
|
||||
await once(w, 'focus');
|
||||
await w.loadURL('about:blank');
|
||||
await moveFocusToDevTools(w);
|
||||
expect(w.webContents.isFocused()).to.be.false();
|
||||
await w.loadURL('data:text/html,<body>test</body>');
|
||||
expect(w.webContents.isFocused()).to.be.true();
|
||||
});
|
||||
|
||||
it('does not focus the webContents on navigation when focusOnNavigation is false', async () => {
|
||||
const w = new BrowserWindow({
|
||||
show: true,
|
||||
webPreferences: {
|
||||
focusOnNavigation: false
|
||||
}
|
||||
});
|
||||
await once(w, 'focus');
|
||||
await w.loadURL('about:blank');
|
||||
await moveFocusToDevTools(w);
|
||||
expect(w.webContents.isFocused()).to.be.false();
|
||||
await w.loadURL('data:text/html,<body>test</body>');
|
||||
expect(w.webContents.isFocused()).to.be.false();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getOSProcessId()', () => {
|
||||
|
||||
@@ -398,4 +398,38 @@ describe('WebContentsView', () => {
|
||||
v.setBorderRadius(100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('focusOnNavigation webPreference', () => {
|
||||
it('focuses the webContents on navigation by default', async () => {
|
||||
const w = new BrowserWindow();
|
||||
await once(w, 'focus');
|
||||
const v = new WebContentsView();
|
||||
w.setContentView(v);
|
||||
await v.webContents.loadURL('about:blank');
|
||||
const devToolsFocused = once(v.webContents, 'devtools-focused');
|
||||
v.webContents.openDevTools({ mode: 'right' });
|
||||
await devToolsFocused;
|
||||
expect(v.webContents.isFocused()).to.be.false();
|
||||
await v.webContents.loadURL('data:text/html,<body>test</body>');
|
||||
expect(v.webContents.isFocused()).to.be.true();
|
||||
});
|
||||
|
||||
it('does not focus the webContents on navigation when focusOnNavigation is false', async () => {
|
||||
const w = new BrowserWindow();
|
||||
await once(w, 'focus');
|
||||
const v = new WebContentsView({
|
||||
webPreferences: {
|
||||
focusOnNavigation: false
|
||||
}
|
||||
});
|
||||
w.setContentView(v);
|
||||
await v.webContents.loadURL('about:blank');
|
||||
const devToolsFocused = once(v.webContents, 'devtools-focused');
|
||||
v.webContents.openDevTools({ mode: 'right' });
|
||||
await devToolsFocused;
|
||||
expect(v.webContents.isFocused()).to.be.false();
|
||||
await v.webContents.loadURL('data:text/html,<body>test</body>');
|
||||
expect(v.webContents.isFocused()).to.be.false();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user