-
Notifications
You must be signed in to change notification settings - Fork 12
/
gowebview_windows_test.go
106 lines (89 loc) · 1.83 KB
/
gowebview_windows_test.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package gowebview
import (
"crypto/rand"
"encoding/hex"
"fmt"
"github.com/inkeliz/gowebview/internal/network"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
"time"
)
func TestNew(t *testing.T) {
path, err := ioutil.TempDir("", "")
fmt.Println("TMP FOLDER:", path)
if err != nil {
t.Fatal(err)
}
w, err := New(&Config{
WindowConfig: &WindowConfig{
Path: path,
},
TransportConfig: &TransportConfig{
Proxy: &HTTPProxy{
IP: "",
Port: "",
},
},
URL: "",
Debug: false,
})
if err != nil {
t.Fatal(err)
}
defer w.Destroy()
w.SetSize(&Point{
X: 400,
Y: 400,
}, HintMin)
w.SetTitle("Hello World")
w.SetURL(`https://google.com`)
w.Run()
}
func TestNewLocalHost(t *testing.T) {
if err := network.DisablePrivateConnections(); err != nil {
t.Fatal(err)
}
ip := `127.0.0.1:9831`
mux := http.NewServeMux()
mux.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("Testing Localhost connection"))
})
go func(ip string, mux *http.ServeMux) {
if err := http.ListenAndServe(ip, mux); err != nil {
t.Error(err)
}
}(ip, mux)
time.Sleep(1 * time.Second)
w, err := New(&Config{
TransportConfig: &TransportConfig{IgnoreNetworkIsolation: true},
})
if err != nil {
t.Fatal(err)
}
defer w.Destroy()
w.SetTitle("Hello World")
w.SetSize(&Point{X: 1500, Y: 800}, HintMin)
w.SetURL(`http://` + ip)
w.Run()
}
func TestNewConfig(t *testing.T) {
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
t.Fatal(err)
}
path := filepath.Join(os.TempDir(), hex.EncodeToString(b))
w, err := New(&Config{
WindowConfig: &WindowConfig{ Size: &Point{X: 800, Y: 800}, Path: path, Visibility: VisibilityMinimized},
})
if err != nil {
t.Fatal(err)
}
defer func(w WebView) {
w.Destroy()
}(w)
w.SetURL(`https://google.com`)
w.Run()
}