package chrome import ( "context" "testing" "time" ) // TestRunCtx_CallerCancelPropagates confirms that cancelling the caller's // context cancels the chromedp-bound context returned by runCtx. This is the // channel by which step deadlines and Ctrl-C reach in-flight CDP calls. func TestRunCtx_CallerCancelPropagates(t *testing.T) { tabCtx, tabCancel := context.WithCancel(context.Background()) defer tabCancel() d := &Driver{tabCtx: tabCtx} callerCtx, callerCancel := context.WithCancel(context.Background()) derived, cancel := d.runCtx(callerCtx) defer cancel() callerCancel() select { case <-derived.Done(): case <-time.After(time.Second): t.Fatal("derived ctx did not cancel after caller cancellation") } } // TestRunCtx_TabCancelPropagates confirms the inverse: tearing down the tab // also cancels any in-flight derived context. func TestRunCtx_TabCancelPropagates(t *testing.T) { tabCtx, tabCancel := context.WithCancel(context.Background()) d := &Driver{tabCtx: tabCtx} derived, cancel := d.runCtx(context.Background()) defer cancel() tabCancel() select { case <-derived.Done(): case <-time.After(time.Second): t.Fatal("derived ctx did not cancel after tab cancellation") } }