v0.27.2 5960dd8

webview_runjavascript_test.go RawHistoryFolder

1package webkit
2
3import (
4	"errors"
5	"testing"
6	"time"
7
8	"github.com/stretchr/testify/assert"
9)
10
11func TestClassifyRunJSEvaluateError(t *testing.T) {
12	t.Run("non-fatal canceled", func(t *testing.T) {
13		nonFatal, signature := classifyRunJSEvaluateError(errors.New("Operation was canceled"))
14		assert.True(t, nonFatal)
15		assert.Equal(t, "evaluate_error:operation was canceled", signature)
16	})
17
18	t.Run("non-fatal context destroyed", func(t *testing.T) {
19		nonFatal, signature := classifyRunJSEvaluateError(errors.New("JavaScript execution context was destroyed"))
20		assert.True(t, nonFatal)
21		assert.Equal(t, "evaluate_error:javascript execution context was destroyed", signature)
22	})
23
24	t.Run("fatal unknown", func(t *testing.T) {
25		nonFatal, signature := classifyRunJSEvaluateError(errors.New("segmentation fault in JS runtime"))
26		assert.False(t, nonFatal)
27		assert.Equal(t, "evaluate_error:segmentation fault in js runtime", signature)
28	})
29}
30
31func TestNormalizeRunJSErrorSignature(t *testing.T) {
32	assert.Equal(t, "empty", normalizeRunJSErrorSignature(" \n\t "))
33	assert.Equal(t, "foo bar baz", normalizeRunJSErrorSignature(" Foo   BAR\tbaz "))
34}
35
36func TestWebViewRunJSDomain(t *testing.T) {
37	wv := &WebView{uri: "https://Sub.Example.com/path?q=1"}
38	assert.Equal(t, "sub.example.com", wv.runJSDomain())
39
40	wv = &WebView{uri: "not a uri"}
41	assert.Equal(t, "unknown", wv.runJSDomain())
42}
43
44func TestShouldLogRunJSError_NonFatalAggregation(t *testing.T) {
45	wv := &WebView{}
46	now := time.Now()
47
48	shouldLog, count := wv.shouldLogRunJSError("example.com", "sig", true, now)
49	assert.True(t, shouldLog)
50	assert.Equal(t, uint64(1), count)
51
52	shouldLog, count = wv.shouldLogRunJSError("example.com", "sig", true, now.Add(10*time.Second))
53	assert.False(t, shouldLog)
54	assert.Equal(t, uint64(2), count)
55
56	shouldLog, count = wv.shouldLogRunJSError("example.com", "sig", true, now.Add(31*time.Second))
57	assert.True(t, shouldLog)
58	assert.Equal(t, uint64(3), count)
59}
60
61func TestShouldLogRunJSError_NonFatalLogsEveryN(t *testing.T) {
62	wv := &WebView{}
63	base := time.Now()
64	for i := 1; i < runJSAggregateLogEvery; i++ {
65		shouldLog, _ := wv.shouldLogRunJSError("example.com", "sig", true, base)
66		if i == 1 {
67			assert.True(t, shouldLog)
68			continue
69		}
70		assert.False(t, shouldLog)
71	}
72
73	shouldLog, count := wv.shouldLogRunJSError("example.com", "sig", true, base)
74	assert.True(t, shouldLog)
75	assert.Equal(t, uint64(runJSAggregateLogEvery), count)
76}
77
78func TestShouldLogRunJSError_FatalAlwaysLogs(t *testing.T) {
79	wv := &WebView{}
80	base := time.Now()
81
82	shouldLog, count := wv.shouldLogRunJSError("example.com", "fatal-sig", false, base)
83	assert.True(t, shouldLog)
84	assert.Equal(t, uint64(1), count)
85
86	shouldLog, count = wv.shouldLogRunJSError("example.com", "fatal-sig", false, base)
87	assert.True(t, shouldLog)
88	assert.Equal(t, uint64(2), count)
89}

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