editable_focus_token_test.go RawHistoryFolder

1package webkit
2
3import (
4	"errors"
5	"sync"
6	"testing"
7
8	"github.com/stretchr/testify/require"
9)
10
11func TestNewEditableFocusBridgeToken_UsesRandomHex(t *testing.T) {
12	old := editableFocusTokenRand
13	t.Cleanup(func() { editableFocusTokenRand = old })
14	editableFocusTokenRand = func(b []byte) (int, error) {
15		for i := range b {
16			b[i] = byte(i + 1)
17		}
18		return len(b), nil
19	}
20
21	token := newEditableFocusBridgeToken()
22	require.Equal(t, "0102030405060708090a0b0c0d0e0f10", token)
23}
24
25func TestNewEditableFocusBridgeToken_RandFailureReturnsEmpty(t *testing.T) {
26	old := editableFocusTokenRand
27	t.Cleanup(func() { editableFocusTokenRand = old })
28	editableFocusTokenRand = func([]byte) (int, error) {
29		return 0, errors.New("entropy exhausted")
30	}
31
32	token := newEditableFocusBridgeToken()
33	require.Empty(t, token)
34}
35
36func TestEditableFocusBridgeToken_ConcurrentAccess(t *testing.T) {
37	t.Parallel()
38	wv := &WebView{}
39	wv.setEditableFocusBridgeToken("initial-token")
40
41	var wg sync.WaitGroup
42	for range 32 {
43		wg.Add(2)
44		go func() {
45			defer wg.Done()
46			for range 200 {
47				_ = wv.EditableFocusBridgeToken()
48				_ = wv.matchesEditableFocusBridgeToken("initial-token")
49			}
50		}()
51		go func() {
52			defer wg.Done()
53			for i := range 200 {
54				wv.setEditableFocusBridgeToken(newEditableFocusBridgeToken())
55				if i%17 == 0 {
56					wv.setEditableFocusBridgeToken("initial-token")
57				}
58			}
59		}()
60	}
61	wg.Wait()
62}
63
64func TestMatchesEditableFocusBridgeToken_RejectsEmpty(t *testing.T) {
65	wv := &WebView{}
66	wv.setEditableFocusBridgeToken("")
67	require.False(t, wv.matchesEditableFocusBridgeToken(""))
68	require.False(t, wv.matchesEditableFocusBridgeToken("anything"))
69
70	wv.setEditableFocusBridgeToken("secret")
71	require.True(t, wv.matchesEditableFocusBridgeToken("secret"))
72	require.False(t, wv.matchesEditableFocusBridgeToken("other"))
73	require.False(t, wv.matchesEditableFocusBridgeToken(""))
74}

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