forked from chromedp/chromedp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler_test.go
55 lines (51 loc) · 1.31 KB
/
handler_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
package chromedp
import (
"testing"
"context"
"github.com/knq/chromedp/cdp"
)
func TestTargetHandler_Listen(t *testing.T) {
t.Parallel()
c := testAllocate(t, "input.html")
defer c.Release()
// run task list
err := c.Run(defaultContext, Tasks{
ActionFunc(func(ctxt context.Context, h cdp.Handler) error {
echan := h.Listen(cdp.EventNetworkRequestWillBeSent)
th := h.(*TargetHandler)
if chs, ok := th.lsnr[cdp.EventNetworkRequestWillBeSent]; ok {
if len(chs) != 1 {
t.Fatal("len(chs) != 1")
}
if chs[0] != echan {
t.Fatal("chs[0] != echan ")
}
} else {
t.Fatal("th.lsnr[cdp.EventNetworkRequestWillBeSent] !ok")
}
if len(th.lsnrchs) != 1 {
t.Fatal("len(th.lsnrchs) != 1")
}
if len(th.lsnrchs[echan]) != 1 {
t.Fatal("len(th.lsnrchs[echan]) != 1")
}
if !th.lsnrchs[echan][cdp.EventNetworkRequestWillBeSent] {
t.Fatal("!th.lsnrchs[echan][cdp.EventNetworkRequestWillBeSent]")
}
h.Release(echan)
if _, ok := <-echan; ok {
t.Fatal("<-echan; ok")
}
if chs, ok := th.lsnr[cdp.EventNetworkRequestWillBeSent]; ok && len(chs) > 0 {
t.Fatal("th.lsnr[cdp.EventNetworkRequestWillBeSent]; ok && len(chs) > 0")
}
if len(th.lsnrchs) != 0 {
t.Fatal("len(th.lsnrchs) != 0")
}
return nil
}),
})
if err != nil {
t.Fatal(err)
}
}