Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"testing"

"github.com/playwright-community/playwright-go"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -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(`<a href="%s/downloadMobile">download</a>`, 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)

Expand Down
Loading