//go:build browser package slidestest import ( "encoding/json" "strings" "testing" ) // Every change a person makes while a resync is pending is kept, in // Chromium and WebKit, through the real editor (fixtures/engines/ // diverged.mjs; Paul: a lost edit is worse than a flash). The first save is // refused and the rebuild held while the person types on the refused text, // pastes elsewhere, deletes across the server's words, the refused text // and their own new words, and types elsewhere; or types on the refused // text, pastes elsewhere and types more after what they typed; or types // on the refused text, undoes it and types elsewhere; or types // into a paragraph the refused Enter made (which cannot be kept), then // elsewhere, then into it again. Afterwards the page holds everything but what the refusal // itself took, one undo takes back the last change as it was made, and // the server holds what the page shows. func TestEnginesEveryChangeWhileARefusalIsPendingIsKept(t *testing.T) { out, fr, err := runEnginesRig(t, "diverged.mjs") if err != nil { t.Fatalf("a change made while the resync was pending was lost: %v\n%s", err, out) } n := 0 for _, line := range strings.Split(out, "\n") { rest, ok := strings.CutPrefix(line, "RESULT ") if !ok { continue } var r struct { Label, Deck string Want []string } if err := json.Unmarshal([]byte(rest), &r); err != nil { t.Fatal(err) } n++ if got := serverParagraphs(t, fr, r.Deck); strings.Join(got, "\n") != strings.Join(r.Want, "\n") { t.Errorf("%s: the server holds %q, the page %q", r.Label, got, r.Want) } } if n != 8 { t.Errorf("%d cases reported, want 8 (four in each engine)", n) } }