feat: add read-only CDP target viewing
This commit is contained in:
@@ -248,6 +248,24 @@ func TestInstanceStatusRefresherAssociatesExternalWithoutLifecycleControl(t *tes
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstanceTabsInspectorReadsOnlyVerifiedRuntimeRows(t *testing.T) {
|
||||
remote := &fakeRemoteDebugInspector{targets: []browser.RemoteDebugTarget{{ID: "page-1", Type: "page", Title: "运营后台", URL: "https://example.com/orders"}}}
|
||||
inspector := instanceTabsInspector{remoteDebug: remote}
|
||||
targets, err := inspector.Inspect(context.Background(), ui.InstanceRow{ID: "chrome-a", Browser: "Chrome", Status: "运行中", RemoteDebugPort: 9666})
|
||||
if err != nil || len(targets) != 1 || targets[0].ID != "page-1" || targets[0].URL != "https://example.com/orders" {
|
||||
t.Fatalf("Inspect() = %#v, %v", targets, err)
|
||||
}
|
||||
if remote.targetCalls != 1 || remote.targetKind != domain.BrowserChrome || remote.targetPort != 9666 {
|
||||
t.Fatalf("target inspector invocation = %#v", remote)
|
||||
}
|
||||
if _, err := inspector.Inspect(context.Background(), ui.InstanceRow{ID: "stopped", Browser: "Chrome", Status: "已退出", RemoteDebugPort: 9666}); err == nil {
|
||||
t.Fatal("Inspect() accepted a non-running instance")
|
||||
}
|
||||
if remote.targetCalls != 1 {
|
||||
t.Fatalf("non-running instance reached CDP target inspector %d times", remote.targetCalls)
|
||||
}
|
||||
}
|
||||
|
||||
type fakeExecutableResolver struct {
|
||||
path string
|
||||
kind domain.BrowserKind
|
||||
@@ -371,6 +389,11 @@ type fakeRemoteDebugInspector struct {
|
||||
port int
|
||||
allocatedPorts []int
|
||||
allocationStarts []int
|
||||
targets []browser.RemoteDebugTarget
|
||||
targetErr error
|
||||
targetKind domain.BrowserKind
|
||||
targetPort int
|
||||
targetCalls int
|
||||
}
|
||||
|
||||
func (i *fakeRemoteDebugInspector) InspectRemoteDebugEndpoint(context.Context, domain.BrowserKind, string) (browser.RemoteDebugEndpoint, error) {
|
||||
@@ -401,3 +424,10 @@ func (i *fakeRemoteDebugInspector) FindAvailableRemoteDebugPort(_ context.Contex
|
||||
}
|
||||
return start, nil
|
||||
}
|
||||
|
||||
func (i *fakeRemoteDebugInspector) ListRemoteDebugTargets(_ context.Context, kind domain.BrowserKind, port int) ([]browser.RemoteDebugTarget, error) {
|
||||
i.targetCalls++
|
||||
i.targetKind = kind
|
||||
i.targetPort = port
|
||||
return append([]browser.RemoteDebugTarget(nil), i.targets...), i.targetErr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user