package cef import ( "testing" purecef "github.com/bnema/purego-cef/cef" "github.com/stretchr/testify/require" ) func TestCef2gtkAdapterPageZoomCompensationDefaultsToOne(t *testing.T) { var nilAdapter *Cef2gtkAdapter require.InDelta(t, 1.0, nilAdapter.PageZoomCompensation(), 1e-9) adapter := &Cef2gtkAdapter{} require.InDelta(t, 1.0, adapter.PageZoomCompensation(), 1e-9) adapter.destroyed.Store(true) require.InDelta(t, 1.0, adapter.PageZoomCompensation(), 1e-9) } func TestDestroy_WithHostDefersBridgeDestroyUntilBeforeClose(t *testing.T) { bridge := &Cef2gtkAdapter{} host := &stubBrowserHost{} wv := &WebView{ viewBridge: bridge, host: host, } wv.Destroy() require.True(t, wv.IsDestroyed()) require.True(t, host.closeBrowserCalled) require.False(t, bridge.IsDestroyed(), "Destroy should request CEF close before destroying the GTK bridge") wv.destroyViewBridgeOnGTKSync() require.True(t, bridge.IsDestroyed()) } func TestDestroy_WithoutHostDestroysBridgeImmediately(t *testing.T) { bridge := &Cef2gtkAdapter{} wv := &WebView{viewBridge: bridge} wv.Destroy() require.True(t, bridge.IsDestroyed()) } func TestHandleInputAttachFailureClosesBrowserForAnyAttachError(t *testing.T) { host := &stubBrowserHost{} wv := &WebView{} wv.handleInputAttachFailure(assertAnError{}, host) require.True(t, host.closeBrowserCalled) } type assertAnError struct{} func (assertAnError) Error() string { return "attach failed" } // stubBrowserHost intentionally only stubs CloseBrowser. The embedded // purecef.BrowserHost may be nil; calling any other BrowserHost method will // panic and should be avoided in these lifecycle tests. type stubBrowserHost struct { purecef.BrowserHost closeBrowserCalled bool } func (s *stubBrowserHost) CloseBrowser(int32) { s.closeBrowserCalled = true }