Repository navigation
Expand file tree
/
Copy pathdebugger_bindings_test.go
More file actions
65 lines (62 loc) · 2.23 KB
/
Copy pathdebugger_bindings_test.go
File metadata and controls
65 lines (62 loc) · 2.23 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
package browser
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
func TestDebuggerBindingsPersistAcrossDocumentsAndRemoveOnlySubscription(t *testing.T) {
parallelBrowserTest(t)
historyTestPages(t, func(t *testing.T, page *Page) {
ctx := context.Background()
d := NewDebugger(page)
defer d.Close()
var received []string
d.BindingCalled = func(realmID, name, payload string) { received = append(received, name+":"+payload) }
if err := d.AddBinding(ctx, "automationBinding", "", "", false); err != nil {
t.Fatal(err)
}
debuggerEval(t, d, `automationBinding('first')`, DebuggerOptions{})
fixture := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`<script>automationBinding('second')</script>`))
}))
defer fixture.Close()
if err := page.Navigate(ctx, fixture.URL); err != nil {
t.Fatal(err)
}
if len(received) != 2 || received[0] != "automationBinding:first" || received[1] != "automationBinding:second" {
t.Fatal(received)
}
d.RemoveBinding("automationBinding")
if got := debuggerEval(t, d, `automationBinding('ignored');typeof automationBinding`, DebuggerOptions{}); got["value"] != "function" {
t.Fatal(got)
}
if len(received) != 2 {
t.Fatal(received)
}
})
}
func TestDebuggerBindingExecutionContextNameMatchesFutureWorld(t *testing.T) {
parallelBrowserTest(t)
historyTestPages(t, func(t *testing.T, page *Page) {
ctx := context.Background()
d := NewDebugger(page)
defer d.Close()
var received []string
d.BindingCalled = func(realmID, name, payload string) { received = append(received, payload) }
if err := d.AddBinding(ctx, "worldBinding", "", "utility", true); err != nil {
t.Fatal(err)
}
if got := debuggerEval(t, d, `typeof worldBinding`, DebuggerOptions{}); got["value"] != "undefined" {
t.Fatal(got)
}
world, err := page.IsolatedWorld(ctx, page.Top.ID, "utility")
if err != nil {
t.Fatal(err)
}
result, err := d.Evaluate(ctx, page.Top.ID, world, `worldBinding('utility');typeof worldBinding`, DebuggerOptions{})
if err != nil || result["result"].(map[string]any)["value"] != "function" || len(received) != 1 || received[0] != "utility" {
t.Fatalf("binding %#v %#v %v", result, received, err)
}
})
}