-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile_integration_test.go
More file actions
66 lines (58 loc) · 1.5 KB
/
Copy pathprofile_integration_test.go
File metadata and controls
66 lines (58 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package browser
import (
"encoding/json"
"strings"
"testing"
)
func TestProfileInjectJS(t *testing.T) {
for _, name := range ListProfiles() {
t.Run(name, func(t *testing.T) {
p, err := LoadProfile(name)
if err != nil {
t.Fatalf("load %q: %v", name, err)
}
js := p.InjectJS()
if js == "" {
t.Fatal("empty InjectJS")
}
prefix := "window.__stealthProfile = "
suffix := "; window.__sp = window.__stealthProfile;"
if !strings.HasPrefix(js, prefix) || !strings.HasSuffix(js, suffix) {
t.Fatalf("unexpected InjectJS format: %s", js[:50])
}
raw := js[len(prefix) : len(js)-len(suffix)]
var check StealthProfile
if err := json.Unmarshal([]byte(raw), &check); err != nil {
t.Fatalf("InjectJS JSON invalid: %v", err)
}
if check.OS == "" {
t.Error("OS empty")
}
if check.GPU.Renderer == "" {
t.Error("GPU renderer empty")
}
if check.Platform == "" {
t.Error("Platform empty")
}
if len(check.UAData.Brands) == 0 {
t.Error("no UA brands")
}
})
}
}
func TestListProfiles(t *testing.T) {
profiles := ListProfiles()
if len(profiles) < 3 {
t.Errorf("expected at least 3 profiles, got %d", len(profiles))
}
}
func TestInteractRequestProfile(t *testing.T) {
raw := `{"url":"https://example.com","profile":"win_chrome145","actions":[]}`
var req InteractRequest
if err := json.Unmarshal([]byte(raw), &req); err != nil {
t.Fatal(err)
}
if req.Profile != "win_chrome145" {
t.Errorf("Profile = %q, want win_chrome145", req.Profile)
}
}