diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index 4431fe1c6415..b669f4963ec1 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -234,6 +234,7 @@ class NativeWindowMac : public NativeWindow, // The views::View that fills the client area. std::unique_ptr root_view_; + bool fullscreen_before_kiosk_ = false; bool is_kiosk_ = false; bool zoom_to_page_width_ = false; absl::optional traffic_light_position_; diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 5f29d5765e7e..17f19c326589 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1029,10 +1029,13 @@ void NativeWindowMac::SetKiosk(bool kiosk) { NSApplicationPresentationDisableHideApplication; [NSApp setPresentationOptions:options]; is_kiosk_ = true; - SetFullScreen(true); + fullscreen_before_kiosk_ = IsFullscreen(); + if (!fullscreen_before_kiosk_) + SetFullScreen(true); } else if (!kiosk && is_kiosk_) { is_kiosk_ = false; - SetFullScreen(false); + if (!fullscreen_before_kiosk_) + SetFullScreen(false); // Set presentation options *after* asynchronously exiting // fullscreen to ensure they take effect. diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 9d0ade2a9b15..c8ab6b9bd668 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -5521,19 +5521,32 @@ describe('BrowserWindow module', () => { it('should not be changed by setKiosk method', async () => { const w = new BrowserWindow(); + + const enterFullScreen = once(w, 'enter-full-screen'); + w.setKiosk(true); + await enterFullScreen; + expect(w.isFullScreen()).to.be.true('isFullScreen'); + + const leaveFullScreen = once(w, 'leave-full-screen'); + w.setKiosk(false); + await leaveFullScreen; + expect(w.isFullScreen()).to.be.false('isFullScreen'); + }); + + it('should stay fullscreen if fullscreen before kiosk', async () => { + const w = new BrowserWindow(); + const enterFullScreen = once(w, 'enter-full-screen'); w.setFullScreen(true); await enterFullScreen; expect(w.isFullScreen()).to.be.true('isFullScreen'); - await setTimeout(); + w.setKiosk(true); - await setTimeout(); + w.setKiosk(false); + // Wait enough time for a fullscreen change to take effect. + await setTimeout(2000); expect(w.isFullScreen()).to.be.true('isFullScreen'); - const leaveFullScreen = once(w, 'leave-full-screen'); - w.setFullScreen(false); - await leaveFullScreen; - expect(w.isFullScreen()).to.be.false('isFullScreen'); }); it('multiple windows inherit correct fullscreen state', async () => {