fix(popup): tear down unresolved staged views
- commit
- 9a38c58ced29178afbbce1e1aece5b35a1683556
- author
- brice · · 2026-07-25 08:19 UTC
- committer
- brice · · 2026-07-26 16:42 UTC
- parent
- 2b549d6
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
6 files · +111 -6
M internal/ui/app.go +3 -0
| @@ -2956,6 +2956,9 @@ func (a *App) onShutdown(ctx context.Context) { | |||
| 2956 | 2956 | for _, tabID := range tabIDs { | |
| 2957 | 2957 | a.releaseFloatingSessionsForTab(ctx, tabID) | |
| 2958 | 2958 | } | |
| 2959 | + | if a.contentCoord != nil { | |
| 2960 | + | a.contentCoord.ShutdownPopups() | |
| 2961 | + | } | |
| 2959 | 2962 | if len(a.nativePopupWindows) > 0 { | |
| 2960 | 2963 | popupIDs := make([]port.WebViewID, 0, len(a.nativePopupWindows)) | |
| 2961 | 2964 | for popupID := range a.nativePopupWindows { | |
| @@ -2956,6 +2956,9 @@ func (a *App) onShutdown(ctx context.Context) { | |||||
| 2956 | for _, tabID := range tabIDs { | 2956 | for _, tabID := range tabIDs { | ||
| 2957 | a.releaseFloatingSessionsForTab(ctx, tabID) | 2957 | a.releaseFloatingSessionsForTab(ctx, tabID) | ||
| 2958 | } | 2958 | } | ||
| 2959 | + | if a.contentCoord != nil { | |||
| 2960 | + | a.contentCoord.ShutdownPopups() | |||
| 2961 | + | } | |||
| 2959 | if len(a.nativePopupWindows) > 0 { | 2962 | if len(a.nativePopupWindows) > 0 { | ||
| 2960 | popupIDs := make([]port.WebViewID, 0, len(a.nativePopupWindows)) | 2963 | popupIDs := make([]port.WebViewID, 0, len(a.nativePopupWindows)) | ||
| 2961 | for popupID := range a.nativePopupWindows { | 2964 | for popupID := range a.nativePopupWindows { | ||
M internal/ui/coordinator/content/lifecycle.go +1 -0
| @@ -48,6 +48,7 @@ func (c *Coordinator) EnsureWebView(ctx context.Context, paneID entity.PaneID) ( | |||
| 48 | 48 | // ReleaseWebView returns the WebView for a pane to the pool. | |
| 49 | 49 | func (c *Coordinator) ReleaseWebView(ctx context.Context, paneID entity.PaneID) { | |
| 50 | 50 | log := logging.FromContext(ctx) | |
| 51 | + | c.ensurePopupManager().cancelDeferredPopupsForParent(paneID) | |
| 51 | 52 | ||
| 52 | 53 | // deleteWebViewLocked clears reveal state before returning, even when a | |
| 53 | 54 | // previous cleanup already removed this pane's mapping. | |
| @@ -48,6 +48,7 @@ func (c *Coordinator) EnsureWebView(ctx context.Context, paneID entity.PaneID) ( | |||||
| 48 | // ReleaseWebView returns the WebView for a pane to the pool. | 48 | // ReleaseWebView returns the WebView for a pane to the pool. | ||
| 49 | func (c *Coordinator) ReleaseWebView(ctx context.Context, paneID entity.PaneID) { | 49 | func (c *Coordinator) ReleaseWebView(ctx context.Context, paneID entity.PaneID) { | ||
| 50 | log := logging.FromContext(ctx) | 50 | log := logging.FromContext(ctx) | ||
| 51 | + | c.ensurePopupManager().cancelDeferredPopupsForParent(paneID) | |||
| 51 | 52 | ||||
| 52 | // deleteWebViewLocked clears reveal state before returning, even when a | 53 | // deleteWebViewLocked clears reveal state before returning, even when a | ||
| 53 | // previous cleanup already removed this pane's mapping. | 54 | // previous cleanup already removed this pane's mapping. | ||
M internal/ui/coordinator/content/popup.go +8 -1
| @@ -202,7 +202,14 @@ func (c *Coordinator) SetOnStagePopup(fn func(context.Context, StagePopupInput) | |||
| 202 | 202 | } | |
| 203 | 203 | ||
| 204 | 204 | func (c *Coordinator) ClearPopupNamedContextsForWindow(windowID string) { | |
| 205 | - | c.ensurePopupManager().clearReusableNamedPopupsForWindow(windowID) | |
| 205 | + | pm := c.ensurePopupManager() | |
| 206 | + | pm.cancelDeferredPopupsForWindow(windowID) | |
| 207 | + | pm.clearReusableNamedPopupsForWindow(windowID) | |
| 208 | + | } | |
| 209 | + | ||
| 210 | + | // ShutdownPopups releases unresolved staged popups before the browser engine exits. | |
| 211 | + | func (c *Coordinator) ShutdownPopups() { | |
| 212 | + | c.ensurePopupManager().cancelAllDeferredPopups() | |
| 206 | 213 | } | |
| 207 | 214 | ||
| 208 | 215 | // SetOnInsertPopup sets the callback to insert popups into the workspace. | |
| @@ -202,7 +202,14 @@ func (c *Coordinator) SetOnStagePopup(fn func(context.Context, StagePopupInput) | |||||
| 202 | } | 202 | } | ||
| 203 | 203 | ||||
| 204 | func (c *Coordinator) ClearPopupNamedContextsForWindow(windowID string) { | 204 | func (c *Coordinator) ClearPopupNamedContextsForWindow(windowID string) { | ||
| 205 | - | c.ensurePopupManager().clearReusableNamedPopupsForWindow(windowID) | 205 | + | pm := c.ensurePopupManager() |
| 206 | + | pm.cancelDeferredPopupsForWindow(windowID) | |||
| 207 | + | pm.clearReusableNamedPopupsForWindow(windowID) | |||
| 208 | + | } | |||
| 209 | + | ||||
| 210 | + | // ShutdownPopups releases unresolved staged popups before the browser engine exits. | |||
| 211 | + | func (c *Coordinator) ShutdownPopups() { | |||
| 212 | + | c.ensurePopupManager().cancelAllDeferredPopups() | |||
| 206 | } | 213 | } | ||
| 207 | 214 | ||||
| 208 | // SetOnInsertPopup sets the callback to insert popups into the workspace. | 215 | // SetOnInsertPopup sets the callback to insert popups into the workspace. | ||
M internal/ui/coordinator/content/popup_deferred.go +48 -1
| @@ -43,13 +43,17 @@ func (pm *popupManager) awaitPopupFeatures( | |||
| 43 | 43 | } | |
| 44 | 44 | pm.setBrowsingContextDecision(popupWV, decision) | |
| 45 | 45 | paneID, _ := pm.createPopupPane(popupWV.ID(), parentPaneID, req.TargetURI) | |
| 46 | + | ownerWindowID := "" | |
| 47 | + | if pm.windowIDForPane != nil { | |
| 48 | + | ownerWindowID, _ = pm.windowIDForPane(parentPaneID) | |
| 49 | + | } | |
| 46 | 50 | pending := &deferredPendingPopup{ | |
| 47 | 51 | PendingPopup: &PendingPopup{ | |
| 48 | 52 | PaneID: paneID, WebView: popupWV, ParentPaneID: parentPaneID, | |
| 49 | 53 | ParentWebViewID: parentWebViewID, TargetURI: req.TargetURI, FrameName: req.FrameName, | |
| 50 | 54 | IsUserGesture: req.IsUserGesture, PopupType: DetectPopupType(req.FrameName), CreatedAt: time.Now(), | |
| 51 | 55 | }, | |
| 52 | - | Request: req, Decision: decision, StagingHost: staging, | |
| 56 | + | Request: req, Decision: decision, StagingHost: staging, OwnerWindowID: ownerWindowID, | |
| 53 | 57 | } | |
| 54 | 58 | pm.storeDeferredPopup(popupWV.ID(), pending) | |
| 55 | 59 | callbackCtx := logging.WithContext(context.Background(), *log) | |
| @@ -67,6 +71,10 @@ func (pm *popupManager) cleanupDeferredPending(pending *deferredPendingPopup) { | |||
| 67 | 71 | return | |
| 68 | 72 | } | |
| 69 | 73 | pending.cleanupOnce.Do(func() { | |
| 74 | + | if lifecycle, ok := pending.WebView.(port.PopupLifecycleCapable); ok { | |
| 75 | + | lifecycle.SetOnReadyToShow(nil) | |
| 76 | + | lifecycle.SetOnClose(nil) | |
| 77 | + | } | |
| 70 | 78 | if pending.StagingHost != nil { | |
| 71 | 79 | pending.StagingHost.Destroy() | |
| 72 | 80 | } | |
| @@ -76,6 +84,45 @@ func (pm *popupManager) cleanupDeferredPending(pending *deferredPendingPopup) { | |||
| 76 | 84 | }) | |
| 77 | 85 | } | |
| 78 | 86 | ||
| 87 | + | func (pm *popupManager) cancelDeferredPopupsMatching(match func(*deferredPendingPopup) bool) { | |
| 88 | + | if pm == nil || match == nil { | |
| 89 | + | return | |
| 90 | + | } | |
| 91 | + | pm.mu.Lock() | |
| 92 | + | cancelled := make([]*deferredPendingPopup, 0) | |
| 93 | + | for popupID, pending := range pm.deferredPopups { | |
| 94 | + | if pending == nil || !match(pending) { | |
| 95 | + | continue | |
| 96 | + | } | |
| 97 | + | delete(pm.deferredPopups, popupID) | |
| 98 | + | delete(pm.pendingPopups, popupID) | |
| 99 | + | cancelled = append(cancelled, pending) | |
| 100 | + | } | |
| 101 | + | pm.mu.Unlock() | |
| 102 | + | for _, pending := range cancelled { | |
| 103 | + | pm.cleanupDeferredPending(pending) | |
| 104 | + | } | |
| 105 | + | } | |
| 106 | + | ||
| 107 | + | func (pm *popupManager) cancelDeferredPopupsForParent(parentPaneID entity.PaneID) { | |
| 108 | + | pm.cancelDeferredPopupsMatching(func(pending *deferredPendingPopup) bool { | |
| 109 | + | return pending.ParentPaneID == parentPaneID | |
| 110 | + | }) | |
| 111 | + | } | |
| 112 | + | ||
| 113 | + | func (pm *popupManager) cancelDeferredPopupsForWindow(windowID string) { | |
| 114 | + | if pm == nil || windowID == "" { | |
| 115 | + | return | |
| 116 | + | } | |
| 117 | + | pm.cancelDeferredPopupsMatching(func(pending *deferredPendingPopup) bool { | |
| 118 | + | return pending.OwnerWindowID == windowID | |
| 119 | + | }) | |
| 120 | + | } | |
| 121 | + | ||
| 122 | + | func (pm *popupManager) cancelAllDeferredPopups() { | |
| 123 | + | pm.cancelDeferredPopupsMatching(func(*deferredPendingPopup) bool { return true }) | |
| 124 | + | } | |
| 125 | + | ||
| 79 | 126 | func (pm *popupManager) failPendingPopup( | |
| 80 | 127 | ctx context.Context, | |
| 81 | 128 | popupID port.WebViewID, | |
| @@ -43,13 +43,17 @@ func (pm *popupManager) awaitPopupFeatures( | |||||
| 43 | } | 43 | } | ||
| 44 | pm.setBrowsingContextDecision(popupWV, decision) | 44 | pm.setBrowsingContextDecision(popupWV, decision) | ||
| 45 | paneID, _ := pm.createPopupPane(popupWV.ID(), parentPaneID, req.TargetURI) | 45 | paneID, _ := pm.createPopupPane(popupWV.ID(), parentPaneID, req.TargetURI) | ||
| 46 | + | ownerWindowID := "" | |||
| 47 | + | if pm.windowIDForPane != nil { | |||
| 48 | + | ownerWindowID, _ = pm.windowIDForPane(parentPaneID) | |||
| 49 | + | } | |||
| 46 | pending := &deferredPendingPopup{ | 50 | pending := &deferredPendingPopup{ | ||
| 47 | PendingPopup: &PendingPopup{ | 51 | PendingPopup: &PendingPopup{ | ||
| 48 | PaneID: paneID, WebView: popupWV, ParentPaneID: parentPaneID, | 52 | PaneID: paneID, WebView: popupWV, ParentPaneID: parentPaneID, | ||
| 49 | ParentWebViewID: parentWebViewID, TargetURI: req.TargetURI, FrameName: req.FrameName, | 53 | ParentWebViewID: parentWebViewID, TargetURI: req.TargetURI, FrameName: req.FrameName, | ||
| 50 | IsUserGesture: req.IsUserGesture, PopupType: DetectPopupType(req.FrameName), CreatedAt: time.Now(), | 54 | IsUserGesture: req.IsUserGesture, PopupType: DetectPopupType(req.FrameName), CreatedAt: time.Now(), | ||
| 51 | }, | 55 | }, | ||
| 52 | - | Request: req, Decision: decision, StagingHost: staging, | 56 | + | Request: req, Decision: decision, StagingHost: staging, OwnerWindowID: ownerWindowID, |
| 53 | } | 57 | } | ||
| 54 | pm.storeDeferredPopup(popupWV.ID(), pending) | 58 | pm.storeDeferredPopup(popupWV.ID(), pending) | ||
| 55 | callbackCtx := logging.WithContext(context.Background(), *log) | 59 | callbackCtx := logging.WithContext(context.Background(), *log) | ||
| @@ -67,6 +71,10 @@ func (pm *popupManager) cleanupDeferredPending(pending *deferredPendingPopup) { | |||||
| 67 | return | 71 | return | ||
| 68 | } | 72 | } | ||
| 69 | pending.cleanupOnce.Do(func() { | 73 | pending.cleanupOnce.Do(func() { | ||
| 74 | + | if lifecycle, ok := pending.WebView.(port.PopupLifecycleCapable); ok { | |||
| 75 | + | lifecycle.SetOnReadyToShow(nil) | |||
| 76 | + | lifecycle.SetOnClose(nil) | |||
| 77 | + | } | |||
| 70 | if pending.StagingHost != nil { | 78 | if pending.StagingHost != nil { | ||
| 71 | pending.StagingHost.Destroy() | 79 | pending.StagingHost.Destroy() | ||
| 72 | } | 80 | } | ||
| @@ -76,6 +84,45 @@ func (pm *popupManager) cleanupDeferredPending(pending *deferredPendingPopup) { | |||||
| 76 | }) | 84 | }) | ||
| 77 | } | 85 | } | ||
| 78 | 86 | ||||
| 87 | + | func (pm *popupManager) cancelDeferredPopupsMatching(match func(*deferredPendingPopup) bool) { | |||
| 88 | + | if pm == nil || match == nil { | |||
| 89 | + | return | |||
| 90 | + | } | |||
| 91 | + | pm.mu.Lock() | |||
| 92 | + | cancelled := make([]*deferredPendingPopup, 0) | |||
| 93 | + | for popupID, pending := range pm.deferredPopups { | |||
| 94 | + | if pending == nil || !match(pending) { | |||
| 95 | + | continue | |||
| 96 | + | } | |||
| 97 | + | delete(pm.deferredPopups, popupID) | |||
| 98 | + | delete(pm.pendingPopups, popupID) | |||
| 99 | + | cancelled = append(cancelled, pending) | |||
| 100 | + | } | |||
| 101 | + | pm.mu.Unlock() | |||
| 102 | + | for _, pending := range cancelled { | |||
| 103 | + | pm.cleanupDeferredPending(pending) | |||
| 104 | + | } | |||
| 105 | + | } | |||
| 106 | + | ||||
| 107 | + | func (pm *popupManager) cancelDeferredPopupsForParent(parentPaneID entity.PaneID) { | |||
| 108 | + | pm.cancelDeferredPopupsMatching(func(pending *deferredPendingPopup) bool { | |||
| 109 | + | return pending.ParentPaneID == parentPaneID | |||
| 110 | + | }) | |||
| 111 | + | } | |||
| 112 | + | ||||
| 113 | + | func (pm *popupManager) cancelDeferredPopupsForWindow(windowID string) { | |||
| 114 | + | if pm == nil || windowID == "" { | |||
| 115 | + | return | |||
| 116 | + | } | |||
| 117 | + | pm.cancelDeferredPopupsMatching(func(pending *deferredPendingPopup) bool { | |||
| 118 | + | return pending.OwnerWindowID == windowID | |||
| 119 | + | }) | |||
| 120 | + | } | |||
| 121 | + | ||||
| 122 | + | func (pm *popupManager) cancelAllDeferredPopups() { | |||
| 123 | + | pm.cancelDeferredPopupsMatching(func(*deferredPendingPopup) bool { return true }) | |||
| 124 | + | } | |||
| 125 | + | ||||
| 79 | func (pm *popupManager) failPendingPopup( | 126 | func (pm *popupManager) failPendingPopup( | ||
| 80 | ctx context.Context, | 127 | ctx context.Context, | ||
| 81 | popupID port.WebViewID, | 128 | popupID port.WebViewID, | ||
M internal/ui/coordinator/content/popup_manager.go +5 -4
| @@ -39,10 +39,11 @@ type popupManager struct { | |||
| 39 | 39 | ||
| 40 | 40 | type deferredPendingPopup struct { | |
| 41 | 41 | *PendingPopup | |
| 42 | - | Request port.PopupRequest | |
| 43 | - | Decision dto.HostDecision | |
| 44 | - | StagingHost PopupStagingHost | |
| 45 | - | cleanupOnce sync.Once | |
| 42 | + | Request port.PopupRequest | |
| 43 | + | Decision dto.HostDecision | |
| 44 | + | StagingHost PopupStagingHost | |
| 45 | + | OwnerWindowID string | |
| 46 | + | cleanupOnce sync.Once | |
| 46 | 47 | } | |
| 47 | 48 | ||
| 48 | 49 | type popupOAuthState struct { | |
| @@ -39,10 +39,11 @@ type popupManager struct { | |||||
| 39 | 39 | ||||
| 40 | type deferredPendingPopup struct { | 40 | type deferredPendingPopup struct { | ||
| 41 | *PendingPopup | 41 | *PendingPopup | ||
| 42 | - | Request port.PopupRequest | 42 | + | Request port.PopupRequest |
| 43 | - | Decision dto.HostDecision | 43 | + | Decision dto.HostDecision |
| 44 | - | StagingHost PopupStagingHost | 44 | + | StagingHost PopupStagingHost |
| 45 | - | cleanupOnce sync.Once | 45 | + | OwnerWindowID string |
| 46 | + | cleanupOnce sync.Once | |||
| 46 | } | 47 | } | ||
| 47 | 48 | ||||
| 48 | type popupOAuthState struct { | 49 | type popupOAuthState struct { | ||
M internal/ui/coordinator/content/popup_test.go +46 -0
| @@ -1417,6 +1417,52 @@ func TestPopupDeferredStagingFailureDestroysCallerOwnedWebViewOnce(t *testing.T) | |||
| 1417 | 1417 | assert.Nil(t, c.handlePopupCreate(context.Background(), "floating", parent, port.PopupRequest{Engine: dto.BrowserEngineWebKit, TargetURI: "https://example.com/open", PopupFeatures: dto.PopupFeatures{State: dto.PopupFeaturesUnknown}})) | |
| 1418 | 1418 | } | |
| 1419 | 1419 | ||
| 1420 | + | func TestPopupDeferredExplicitTeardownCleansUpWithoutLifecycleSignals(t *testing.T) { | |
| 1421 | + | for _, tc := range []struct { | |
| 1422 | + | name string | |
| 1423 | + | prepare func(*Coordinator) | |
| 1424 | + | trigger func(*Coordinator) | |
| 1425 | + | }{ | |
| 1426 | + | {name: "parent release", trigger: func(c *Coordinator) { c.ReleaseWebView(context.Background(), "floating") }}, | |
| 1427 | + | {name: "owner window teardown", prepare: func(c *Coordinator) { | |
| 1428 | + | c.SetPopupWindowIDResolver(func(entity.PaneID) (string, bool) { return "owner", true }) | |
| 1429 | + | }, trigger: func(c *Coordinator) { c.ClearPopupNamedContextsForWindow("owner") }}, | |
| 1430 | + | {name: "coordinator shutdown", trigger: func(c *Coordinator) { c.ShutdownPopups() }}, | |
| 1431 | + | } { | |
| 1432 | + | t.Run(tc.name, func(t *testing.T) { | |
| 1433 | + | parent := mocks.NewMockWebView(t) | |
| 1434 | + | parent.EXPECT().ID().Return(port.WebViewID(101)).Once() | |
| 1435 | + | popup := &deferredPopupWebViewStub{MockWebView: mocks.NewMockWebView(t), features: dto.PopupFeatures{State: dto.PopupFeaturesNone}} | |
| 1436 | + | popup.EXPECT().ID().Return(port.WebViewID(207)).Maybe() | |
| 1437 | + | popup.EXPECT().Destroy().Once() | |
| 1438 | + | factory := mocks.NewMockWebViewFactory(t) | |
| 1439 | + | factory.EXPECT().CreateRelated(mock.Anything, port.WebViewID(101)).Return(popup, nil).Once() | |
| 1440 | + | staging := &popupStagingHostStub{} | |
| 1441 | + | c := &Coordinator{popups: newPopupManager()} | |
| 1442 | + | c.SetPopupConfig(factory, &entity.BrowsingContextConfig{OpenInNewPane: false}, nil) | |
| 1443 | + | c.SetPopupSourceHostResolver(func(entity.PaneID) dto.SourceHostKind { return dto.SourceHostFloating }) | |
| 1444 | + | c.SetOnStagePopup(func(context.Context, StagePopupInput) (PopupStagingHost, error) { return staging, nil }) | |
| 1445 | + | if tc.prepare != nil { | |
| 1446 | + | tc.prepare(c) | |
| 1447 | + | } | |
| 1448 | + | ||
| 1449 | + | require.Same(t, popup, c.handlePopupCreate(context.Background(), "floating", parent, port.PopupRequest{ | |
| 1450 | + | Engine: dto.BrowserEngineWebKit, TargetURI: "https://example.com/open", | |
| 1451 | + | PopupFeatures: dto.PopupFeatures{State: dto.PopupFeaturesUnknown}, | |
| 1452 | + | })) | |
| 1453 | + | require.Len(t, c.popups.deferredPopups, 1) | |
| 1454 | + | tc.trigger(c) | |
| 1455 | + | tc.trigger(c) | |
| 1456 | + | ||
| 1457 | + | assert.Empty(t, c.popups.deferredPopups) | |
| 1458 | + | assert.Empty(t, c.popups.pendingPopups) | |
| 1459 | + | assert.Equal(t, 1, staging.destroyCalls) | |
| 1460 | + | assert.Nil(t, popup.onReady) | |
| 1461 | + | assert.Nil(t, popup.onClose) | |
| 1462 | + | }) | |
| 1463 | + | } | |
| 1464 | + | } | |
| 1465 | + | ||
| 1420 | 1466 | func TestPopupDeferredUnknownAndCloseCleanupExactlyOnce(t *testing.T) { | |
| 1421 | 1467 | for _, tc := range []struct { | |
| 1422 | 1468 | name string | |
| @@ -1417,6 +1417,52 @@ func TestPopupDeferredStagingFailureDestroysCallerOwnedWebViewOnce(t *testing.T) | |||||
| 1417 | assert.Nil(t, c.handlePopupCreate(context.Background(), "floating", parent, port.PopupRequest{Engine: dto.BrowserEngineWebKit, TargetURI: "https://example.com/open", PopupFeatures: dto.PopupFeatures{State: dto.PopupFeaturesUnknown}})) | 1417 | assert.Nil(t, c.handlePopupCreate(context.Background(), "floating", parent, port.PopupRequest{Engine: dto.BrowserEngineWebKit, TargetURI: "https://example.com/open", PopupFeatures: dto.PopupFeatures{State: dto.PopupFeaturesUnknown}})) | ||
| 1418 | } | 1418 | } | ||
| 1419 | 1419 | ||||
| 1420 | + | func TestPopupDeferredExplicitTeardownCleansUpWithoutLifecycleSignals(t *testing.T) { | |||
| 1421 | + | for _, tc := range []struct { | |||
| 1422 | + | name string | |||
| 1423 | + | prepare func(*Coordinator) | |||
| 1424 | + | trigger func(*Coordinator) | |||
| 1425 | + | }{ | |||
| 1426 | + | {name: "parent release", trigger: func(c *Coordinator) { c.ReleaseWebView(context.Background(), "floating") }}, | |||
| 1427 | + | {name: "owner window teardown", prepare: func(c *Coordinator) { | |||
| 1428 | + | c.SetPopupWindowIDResolver(func(entity.PaneID) (string, bool) { return "owner", true }) | |||
| 1429 | + | }, trigger: func(c *Coordinator) { c.ClearPopupNamedContextsForWindow("owner") }}, | |||
| 1430 | + | {name: "coordinator shutdown", trigger: func(c *Coordinator) { c.ShutdownPopups() }}, | |||
| 1431 | + | } { | |||
| 1432 | + | t.Run(tc.name, func(t *testing.T) { | |||
| 1433 | + | parent := mocks.NewMockWebView(t) | |||
| 1434 | + | parent.EXPECT().ID().Return(port.WebViewID(101)).Once() | |||
| 1435 | + | popup := &deferredPopupWebViewStub{MockWebView: mocks.NewMockWebView(t), features: dto.PopupFeatures{State: dto.PopupFeaturesNone}} | |||
| 1436 | + | popup.EXPECT().ID().Return(port.WebViewID(207)).Maybe() | |||
| 1437 | + | popup.EXPECT().Destroy().Once() | |||
| 1438 | + | factory := mocks.NewMockWebViewFactory(t) | |||
| 1439 | + | factory.EXPECT().CreateRelated(mock.Anything, port.WebViewID(101)).Return(popup, nil).Once() | |||
| 1440 | + | staging := &popupStagingHostStub{} | |||
| 1441 | + | c := &Coordinator{popups: newPopupManager()} | |||
| 1442 | + | c.SetPopupConfig(factory, &entity.BrowsingContextConfig{OpenInNewPane: false}, nil) | |||
| 1443 | + | c.SetPopupSourceHostResolver(func(entity.PaneID) dto.SourceHostKind { return dto.SourceHostFloating }) | |||
| 1444 | + | c.SetOnStagePopup(func(context.Context, StagePopupInput) (PopupStagingHost, error) { return staging, nil }) | |||
| 1445 | + | if tc.prepare != nil { | |||
| 1446 | + | tc.prepare(c) | |||
| 1447 | + | } | |||
| 1448 | + | ||||
| 1449 | + | require.Same(t, popup, c.handlePopupCreate(context.Background(), "floating", parent, port.PopupRequest{ | |||
| 1450 | + | Engine: dto.BrowserEngineWebKit, TargetURI: "https://example.com/open", | |||
| 1451 | + | PopupFeatures: dto.PopupFeatures{State: dto.PopupFeaturesUnknown}, | |||
| 1452 | + | })) | |||
| 1453 | + | require.Len(t, c.popups.deferredPopups, 1) | |||
| 1454 | + | tc.trigger(c) | |||
| 1455 | + | tc.trigger(c) | |||
| 1456 | + | ||||
| 1457 | + | assert.Empty(t, c.popups.deferredPopups) | |||
| 1458 | + | assert.Empty(t, c.popups.pendingPopups) | |||
| 1459 | + | assert.Equal(t, 1, staging.destroyCalls) | |||
| 1460 | + | assert.Nil(t, popup.onReady) | |||
| 1461 | + | assert.Nil(t, popup.onClose) | |||
| 1462 | + | }) | |||
| 1463 | + | } | |||
| 1464 | + | } | |||
| 1465 | + | ||||
| 1420 | func TestPopupDeferredUnknownAndCloseCleanupExactlyOnce(t *testing.T) { | 1466 | func TestPopupDeferredUnknownAndCloseCleanupExactlyOnce(t *testing.T) { | ||
| 1421 | for _, tc := range []struct { | 1467 | for _, tc := range []struct { | ||
| 1422 | name string | 1468 | name string | ||