fix: do not call close on sheets themselves (#22410)
This commit is contained in:
parent
ed33a72c23
commit
2c974915a3
2 changed files with 53 additions and 7 deletions
|
@ -588,7 +588,14 @@ void NativeWindowMac::SetContentView(views::View* view) {
|
||||||
void NativeWindowMac::Close() {
|
void NativeWindowMac::Close() {
|
||||||
// When this is a sheet showing, performClose won't work.
|
// When this is a sheet showing, performClose won't work.
|
||||||
if (is_modal() && parent() && IsVisible()) {
|
if (is_modal() && parent() && IsVisible()) {
|
||||||
[parent()->GetNativeWindow().GetNativeNSWindow() endSheet:window_];
|
NSWindow* window = parent()->GetNativeWindow().GetNativeNSWindow();
|
||||||
|
if (NSWindow* sheetParent = [window sheetParent]) {
|
||||||
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||||
|
FROM_HERE, base::BindOnce(base::RetainBlock(^{
|
||||||
|
[sheetParent endSheet:window];
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
// Manually emit close event (not triggered from close fn)
|
// Manually emit close event (not triggered from close fn)
|
||||||
NotifyWindowCloseButtonClicked();
|
NotifyWindowCloseButtonClicked();
|
||||||
CloseImmediately();
|
CloseImmediately();
|
||||||
|
|
|
@ -3105,16 +3105,53 @@ describe('BrowserWindow module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// The isEnabled API is not reliable on macOS.
|
describe('modal option', () => {
|
||||||
ifdescribe(process.platform !== 'darwin')('modal option', () => {
|
it('does not freeze or crash', async () => {
|
||||||
it('disables parent window', () => {
|
const parentWindow = new BrowserWindow()
|
||||||
|
|
||||||
|
const createTwo = async () => {
|
||||||
|
const two = new BrowserWindow({
|
||||||
|
width: 300,
|
||||||
|
height: 200,
|
||||||
|
parent: parentWindow,
|
||||||
|
modal: true,
|
||||||
|
show: false
|
||||||
|
})
|
||||||
|
|
||||||
|
const twoShown = emittedOnce(two, 'show')
|
||||||
|
two.show()
|
||||||
|
await twoShown
|
||||||
|
setTimeout(() => two.close(), 500)
|
||||||
|
|
||||||
|
await emittedOnce(two, 'closed')
|
||||||
|
}
|
||||||
|
|
||||||
|
const one = new BrowserWindow({
|
||||||
|
width: 600,
|
||||||
|
height: 400,
|
||||||
|
parent: parentWindow,
|
||||||
|
modal: true,
|
||||||
|
show: false
|
||||||
|
})
|
||||||
|
|
||||||
|
const oneShown = emittedOnce(one, 'show')
|
||||||
|
one.show()
|
||||||
|
await oneShown
|
||||||
|
setTimeout(() => one.destroy(), 500)
|
||||||
|
|
||||||
|
await emittedOnce(one, 'closed')
|
||||||
|
await createTwo()
|
||||||
|
})
|
||||||
|
|
||||||
|
ifit(process.platform !== 'darwin')('disables parent window', () => {
|
||||||
const w = new BrowserWindow({ show: false })
|
const w = new BrowserWindow({ show: false })
|
||||||
const c = new BrowserWindow({ show: false, parent: w, modal: true })
|
const c = new BrowserWindow({ show: false, parent: w, modal: true })
|
||||||
expect(w.isEnabled()).to.be.true('w.isEnabled')
|
expect(w.isEnabled()).to.be.true('w.isEnabled')
|
||||||
c.show()
|
c.show()
|
||||||
expect(w.isEnabled()).to.be.false('w.isEnabled')
|
expect(w.isEnabled()).to.be.false('w.isEnabled')
|
||||||
})
|
})
|
||||||
it('re-enables an enabled parent window when closed', (done) => {
|
|
||||||
|
ifit(process.platform !== 'darwin')('re-enables an enabled parent window when closed', (done) => {
|
||||||
const w = new BrowserWindow({ show: false })
|
const w = new BrowserWindow({ show: false })
|
||||||
const c = new BrowserWindow({ show: false, parent: w, modal: true })
|
const c = new BrowserWindow({ show: false, parent: w, modal: true })
|
||||||
c.once('closed', () => {
|
c.once('closed', () => {
|
||||||
|
@ -3124,7 +3161,8 @@ describe('BrowserWindow module', () => {
|
||||||
c.show()
|
c.show()
|
||||||
c.close()
|
c.close()
|
||||||
})
|
})
|
||||||
it('does not re-enable a disabled parent window when closed', (done) => {
|
|
||||||
|
ifit(process.platform !== 'darwin')('does not re-enable a disabled parent window when closed', (done) => {
|
||||||
const w = new BrowserWindow({ show: false })
|
const w = new BrowserWindow({ show: false })
|
||||||
const c = new BrowserWindow({ show: false, parent: w, modal: true })
|
const c = new BrowserWindow({ show: false, parent: w, modal: true })
|
||||||
c.once('closed', () => {
|
c.once('closed', () => {
|
||||||
|
@ -3135,7 +3173,8 @@ describe('BrowserWindow module', () => {
|
||||||
c.show()
|
c.show()
|
||||||
c.close()
|
c.close()
|
||||||
})
|
})
|
||||||
it('disables parent window recursively', () => {
|
|
||||||
|
ifit(process.platform !== 'darwin')('disables parent window recursively', () => {
|
||||||
const w = new BrowserWindow({ show: false })
|
const w = new BrowserWindow({ show: false })
|
||||||
const c = new BrowserWindow({ show: false, parent: w, modal: true })
|
const c = new BrowserWindow({ show: false, parent: w, modal: true })
|
||||||
const c2 = new BrowserWindow({ show: false, parent: w, modal: true })
|
const c2 = new BrowserWindow({ show: false, parent: w, modal: true })
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue