| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "reasonix/internal/browser" |
| 7 | ) |
| 8 | |
| 9 | func browserControlTab() *WorkspaceTab { |
| 10 | return &WorkspaceTab{ID: "tab-control"} |
| 11 | } |
| 12 | |
| 13 | func TestBrowserControlGatesNewSessions(t *testing.T) { |
| 14 | isolateDesktopUserDirs(t) |
| 15 | app := NewApp() |
| 16 | app.hostShell = &hostShellBridge{app: app} |
| 17 | tab := browserControlTab() |
| 18 | |
| 19 | if exec := app.browserExecutorForTab(tab); exec == nil { |
| 20 | t.Fatal("browser control is on by default, so a host session gets an executor") |
| 21 | } |
| 22 | app.setBrowserControlEnabled(false) |
| 23 | if exec := app.browserExecutorForTab(tab); exec != nil { |
| 24 | t.Fatalf("disabled control returned %T, want nil so no browser tool is registered", exec) |
| 25 | } |
| 26 | app.setBrowserControlEnabled(true) |
| 27 | if exec := app.browserExecutorForTab(tab); exec == nil { |
| 28 | t.Fatal("re-enabling control must restore the executor") |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestBrowserControlGateCoversRemoteExecutors(t *testing.T) { |
| 33 | isolateDesktopUserDirs(t) |
| 34 | app := NewApp() |
| 35 | app.hostShell = &hostShellBridge{app: app} |
| 36 | app.setBrowserControlEnabled(false) |
| 37 | if exec := app.browserExecutorForRemoteTab(&remoteTab{id: "remote-1"}, "/workspace"); exec != nil { |
| 38 | t.Fatalf("disabled control returned %T for a remote tab, want nil", exec) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestBrowserControlGateKeepsNonHostModeClosed(t *testing.T) { |
| 43 | isolateDesktopUserDirs(t) |
| 44 | app := NewApp() |
| 45 | app.setBrowserControlEnabled(true) |
| 46 | if exec := app.browserExecutorForTab(browserControlTab()); exec != nil { |
| 47 | t.Fatalf("executor without the Electron shell = %T, want nil", exec) |
| 48 | } |
| 49 | var _ browser.Executor = (*hostBrowserExecutor)(nil) |
| 50 | } |
| 51 |