diff --git a/tests/download_test.go b/tests/download_test.go index 3a97b5ec..5c5eb840 100644 --- a/tests/download_test.go +++ b/tests/download_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" + "github.com/playwright-community/playwright-go" "github.com/stretchr/testify/require" ) @@ -48,6 +49,48 @@ func TestDownloadBasic(t *testing.T) { require.NoFileExists(t, file) } +// Regression test for https://github.com/playwright-community/playwright-go/issues/579 +// Verifies that ExpectDownload works under a mobile emulation context (IsMobile + HasTouch), +// e.g. when emulating an iPad. The download event must fire on the page channel even when +// the context has touch + isMobile enabled. +func TestDownloadInMobileContext(t *testing.T) { + BeforeEach(t) + + server.SetRoute("/downloadMobile", func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/octet-stream") + w.Header().Add("Content-Disposition", "attachment; filename=mobile.txt") + if _, err := w.Write([]byte("mobile-payload")); err != nil { + log.Printf("could not write: %v", err) + } + }) + + device := pw.Devices["iPad Mini"] + mobileCtx, err := browser.NewContext(playwright.BrowserNewContextOptions{ + Viewport: device.Viewport, + UserAgent: playwright.String(device.UserAgent), + DeviceScaleFactor: playwright.Float(device.DeviceScaleFactor), + IsMobile: playwright.Bool(device.IsMobile), + HasTouch: playwright.Bool(device.HasTouch), + }) + require.NoError(t, err) + defer mobileCtx.Close() + + mobilePage, err := mobileCtx.NewPage() + require.NoError(t, err) + + require.NoError(t, mobilePage.SetContent( + fmt.Sprintf(`download`, server.PREFIX), + )) + + download, err := mobilePage.ExpectDownload(func() error { + return mobilePage.Locator("a").Click() + }) + require.NoError(t, err) + require.Equal(t, mobilePage, download.Page()) + require.Equal(t, fmt.Sprintf("%s/downloadMobile", server.PREFIX), download.URL()) + require.Equal(t, "mobile.txt", download.SuggestedFilename()) +} + func TestDownloadCancel(t *testing.T) { BeforeEach(t)