1package cef
2
3import (
4 "context"
5 "errors"
6 "path/filepath"
7 "testing"
8
9 "github.com/bnema/dumber/internal/application/port"
10 "github.com/bnema/dumber/internal/logging"
11)
12
13func TestCEF2GTKProfilePathUsesSessionLogDirectory(t *testing.T) {
14 t.Setenv(cef2gtkProfileEnv, "1")
15 logDir := t.TempDir()
16 ctx := logging.WithSessionMetadata(context.Background(), "20260430_120000_abcd", filepath.Join(logDir, "session_20260430_120000_abcd.log"))
17 eng := &Engine{ctx: ctx, profileLogDir: filepath.Join(t.TempDir(), "fallback")}
18
19 got := eng.cef2gtkProfilePath()
20 want := filepath.Join(logDir, "session_20260430_120000_abcd_cef2gtk_profile.jsonl")
21 if got != want {
22 t.Fatalf("path = %q, want %q", got, want)
23 }
24}
25
26func TestCEF2GTKProfilePathUsesEngineProfileLogDirFallback(t *testing.T) {
27 profileLogDir := t.TempDir()
28 eng := &Engine{ctx: context.Background(), profileLogDir: profileLogDir}
29
30 got := eng.cef2gtkProfilePath()
31 want := filepath.Join(profileLogDir, "cef2gtk_profile.jsonl")
32 if got != want {
33 t.Fatalf("path = %q, want fallback output", got)
34 }
35}
36
37func TestCEF2GTKProfilePathAllowsExplicitOutput(t *testing.T) {
38 explicit := filepath.Join(t.TempDir(), "profile.jsonl")
39 t.Setenv(cef2gtkProfileOutputEnv, explicit)
40 eng := &Engine{ctx: context.Background()}
41
42 if got := eng.cef2gtkProfilePath(); got != explicit {
43 t.Fatalf("path = %q, want explicit output", got)
44 }
45}
46
47func TestCEF2GTKProfileOptionsDisabledByDefault(t *testing.T) {
48 eng := &Engine{ctx: context.Background()}
49 wv := &WebView{id: port.WebViewID(7)}
50
51 if opts := eng.cef2gtkProfileOptions(wv); opts.Enabled {
52 t.Fatal("profile options enabled without env")
53 }
54}
55
56func TestLockedProfileWriterWriteReturnsErrorWhenClosed(t *testing.T) {
57 var nilWriter *lockedProfileWriter
58 if _, err := nilWriter.Write([]byte("x")); !errors.Is(err, errProfileWriterClosed) {
59 t.Fatalf("nil writer error = %v, want %v", err, errProfileWriterClosed)
60 }
61
62 writer := &lockedProfileWriter{}
63 if _, err := writer.Write([]byte("x")); !errors.Is(err, errProfileWriterClosed) {
64 t.Fatalf("closed writer error = %v, want %v", err, errProfileWriterClosed)
65 }
66}