webview_popup_test.go RawHistoryFolder

1package webkit
2
3import (
4	"testing"
5
6	"github.com/bnema/dumber/internal/application/dto"
7	"github.com/bnema/dumber/internal/application/port"
8	purewebkit "github.com/bnema/puregotk/v4/webkit"
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/require"
11)
12
13func TestResolvePopupFeatures(t *testing.T) {
14	t.Parallel()
15
16	tests := []struct {
17		name                string
18		x, y, width, height int
19		toolbar, location   bool
20		resizable           bool
21		wantState           dto.PopupFeatureState
22		wantPopup           bool
23	}{
24		{name: "default properties are featureless", toolbar: true, location: true, resizable: true, wantState: dto.PopupFeaturesNone},
25		{name: "geometry is popup like", width: 640, height: 480, toolbar: true, location: true, resizable: true, wantState: dto.PopupFeaturesSpecified, wantPopup: true},
26		{name: "hidden toolbar is popup like", toolbar: false, location: true, resizable: true, wantState: dto.PopupFeaturesSpecified, wantPopup: true},
27		{name: "hidden location bar is popup like", toolbar: true, location: false, resizable: true, wantState: dto.PopupFeaturesSpecified, wantPopup: true},
28		{name: "disabled resizing is popup like", toolbar: true, location: true, resizable: false, wantState: dto.PopupFeaturesSpecified, wantPopup: true},
29	}
30
31	for _, tt := range tests {
32		t.Run(tt.name, func(t *testing.T) {
33			t.Parallel()
34			got := popupFeaturesFromWindowProperties(tt.x, tt.y, tt.width, tt.height, tt.toolbar, tt.location, tt.resizable)
35			assert.Equal(t, tt.wantState, got.State)
36			assert.Equal(t, tt.width > 0, got.WidthSet)
37			assert.Equal(t, tt.height > 0, got.HeightSet)
38			assert.True(t, got.ToolbarVisibilitySet)
39			assert.True(t, got.LocationbarVisibilitySet)
40			assert.True(t, got.ResizableSet)
41			assert.Equal(t, tt.wantPopup && (!tt.toolbar || !tt.location || !tt.resizable), got.IsPopup)
42		})
43	}
44}
45
46func TestMapPopupRequestClassifiesLinkBlankAsFeatureless(t *testing.T) {
47	t.Parallel()
48
49	blank := mapPopupRequest(PopupRequest{
50		TargetURI: "https://example.com/new", FrameName: " _BLANK ", ParentID: 7,
51		NavigationType: purewebkit.NavigationTypeLinkClickedValue,
52	})
53	assert.Equal(t, dto.BrowserEngineWebKit, blank.Engine)
54	assert.Equal(t, dto.WindowDispositionNewTab, blank.TargetDisposition)
55	assert.Equal(t, dto.PopupFeaturesNone, blank.PopupFeatures.State)
56}
57
58func TestMapPopupRequestDefersScriptBlankFeatures(t *testing.T) {
59	t.Parallel()
60
61	script := mapPopupRequest(PopupRequest{
62		TargetURI: "https://example.com/popup", FrameName: "_blank", ParentID: 7,
63		NavigationType: purewebkit.NavigationTypeOtherValue,
64	})
65	assert.Equal(t, dto.BrowserEngineWebKit, script.Engine)
66	assert.Equal(t, dto.WindowDispositionNewPopup, script.TargetDisposition)
67	assert.Equal(t, dto.PopupFeaturesUnknown, script.PopupFeatures.State)
68}
69
70func TestPopupCreateCallbackPreservesNilNamedReuseResult(t *testing.T) {
71	wv := &WebView{}
72	wv.SetCallbacks(&port.WebViewCallbacks{OnCreate: func(req port.PopupRequest) port.WebView {
73		require.Equal(t, dto.BrowserEngineWebKit, req.Engine)
74		require.Equal(t, "shared", req.FrameName)
75		return nil // Existing named context was navigated; block WebKit creation.
76	}})
77
78	result := wv.OnCreate(PopupRequest{
79		TargetURI: "https://example.com/reused", FrameName: "shared", ParentID: 7,
80		NavigationType: purewebkit.NavigationTypeOtherValue,
81	})
82
83	require.Nil(t, result)
84}
85
86func TestResolvePopupFeaturesNilWebViewIsUnknown(t *testing.T) {
87	t.Parallel()
88	var wv *WebView
89	assert.Equal(t, dto.PopupFeaturesUnknown, wv.ResolvePopupFeatures().State)
90}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close