| 1 | //go:build browser |
| 2 | |
| 3 | // A reload is the same tab, not a colleague arriving. |
| 4 | package slidestest |
| 5 | |
| 6 | import ( |
| 7 | "testing" |
| 8 | "time" |
| 9 | |
| 10 | "github.com/chromedp/chromedp" |
| 11 | ) |
| 12 | |
| 13 | // TestBrowserReloadIsNotSomebodyElse (polish audit, slides-52): a |
| 14 | // reload keeps this tab's presence client id, so the tab that comes |
| 15 | // back does not find its own previous self in the set and draw it as a |
| 16 | // colleague for the forty-five seconds the server takes to expire it. |
| 17 | // A second tab afterwards still shows up, so the pass is not a |
| 18 | // presence stream that never arrived. |
| 19 | func TestBrowserReloadIsNotSomebodyElse(t *testing.T) { |
| 20 | rig, _, deck := openEditor(t) |
| 21 | rig.Run( |
| 22 | // Let the first beat land, so the server holds this tab. |
| 23 | chromedp.Sleep(1500*time.Millisecond), |
| 24 | chromedp.Reload(), |
| 25 | chromedp.WaitVisible(`[slides-editor]`, chromedp.ByQuery), |
| 26 | waitFor(editorBound), |
| 27 | // The stream's connect event carries the whole set, the old |
| 28 | // entry included if it is somebody else's id. |
| 29 | chromedp.Sleep(3*time.Second), |
| 30 | ) |
| 31 | var ghosts string |
| 32 | rig.Run(chromedp.Evaluate(`[...document.querySelectorAll('[slides-presence-avatar], [slides-presence-chip]')].map(e => e.getAttribute('aria-label') || e.textContent).join(' | ')`, &ghosts)) |
| 33 | if ghosts != "" { |
| 34 | t.Errorf("after a reload the editor shows this tab as somebody else: %s", ghosts) |
| 35 | } |
| 36 | rig.Screen(`[slides-editor]`, "reloaded, alone") |
| 37 | |
| 38 | // Two tabs are still two people. |
| 39 | tab2, cancel := chromedp.NewContext(rig.Context()) |
| 40 | defer cancel() |
| 41 | runOn(t, tab2, |
| 42 | chromedp.Navigate(rig.Origin+deck+"/edit"), |
| 43 | chromedp.WaitVisible(`[slides-editor]`, chromedp.ByQuery), |
| 44 | waitFor(editorBound), |
| 45 | ) |
| 46 | rig.Run(waitFor(`document.querySelector('[slides-presence-avatar]') !== null`)) |
| 47 | } |
| 48 | |