//go:build browser // A reload is the same tab, not a colleague arriving. package slidestest import ( "testing" "time" "github.com/chromedp/chromedp" ) // TestBrowserReloadIsNotSomebodyElse (polish audit, slides-52): a // reload keeps this tab's presence client id, so the tab that comes // back does not find its own previous self in the set and draw it as a // colleague for the forty-five seconds the server takes to expire it. // A second tab afterwards still shows up, so the pass is not a // presence stream that never arrived. func TestBrowserReloadIsNotSomebodyElse(t *testing.T) { rig, _, deck := openEditor(t) rig.Run( // Let the first beat land, so the server holds this tab. chromedp.Sleep(1500*time.Millisecond), chromedp.Reload(), chromedp.WaitVisible(`[slides-editor]`, chromedp.ByQuery), waitFor(editorBound), // The stream's connect event carries the whole set, the old // entry included if it is somebody else's id. chromedp.Sleep(3*time.Second), ) var ghosts string rig.Run(chromedp.Evaluate(`[...document.querySelectorAll('[slides-presence-avatar], [slides-presence-chip]')].map(e => e.getAttribute('aria-label') || e.textContent).join(' | ')`, &ghosts)) if ghosts != "" { t.Errorf("after a reload the editor shows this tab as somebody else: %s", ghosts) } rig.Screen(`[slides-editor]`, "reloaded, alone") // Two tabs are still two people. tab2, cancel := chromedp.NewContext(rig.Context()) defer cancel() runOn(t, tab2, chromedp.Navigate(rig.Origin+deck+"/edit"), chromedp.WaitVisible(`[slides-editor]`, chromedp.ByQuery), waitFor(editorBound), ) rig.Run(waitFor(`document.querySelector('[slides-presence-avatar]') !== null`)) }