diff --git a/tests/library/emulation-focus.spec.ts b/tests/library/emulation-focus.spec.ts index a51ee12bd4fa4..f7fe44e85cd8b 100644 --- a/tests/library/emulation-focus.spec.ts +++ b/tests/library/emulation-focus.spec.ts @@ -247,3 +247,25 @@ browserTest('EM-024 should trigger hover state concurrently', async ({ browserTy for (const page of [page1, page2, page3]) expect(await page.evaluate('window.clicked')).toBe(2); }); + +browserTest('EM-028 should keep mouse drag when interacting with another page/context', { + annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43969' }, +}, async ({ contextFactory }) => { + const page1 = await (await contextFactory()).newPage(); + const page2 = await (await contextFactory()).newPage(); + for (const page of [page1, page2]) { + await page.setContent(` + + + + `); + } + await page1.mouse.move(100, 10); + await page1.mouse.down(); + await page1.mouse.move(150, 10); + await page2.mouse.move(50, 50); + await page1.mouse.move(180, 10); + await page1.mouse.up(); + expect(await page1.evaluate(() => !!window['changed'])).toBe(true); + expect(+await page1.locator('input').inputValue()).toBeGreaterThan(80); +}); diff --git a/tests/page/page-filechooser.spec.ts b/tests/page/page-filechooser.spec.ts index ab6c7faf1dcde..334397833edd2 100644 --- a/tests/page/page-filechooser.spec.ts +++ b/tests/page/page-filechooser.spec.ts @@ -126,20 +126,32 @@ test('FC-007 should work when file input is attached to DOM', async ({ page, ser expect(chooser).toBeTruthy(); }); -test('FC-008 should work when file input is not attached to DOM', async ({ page, asset }) => { - const [, content] = await Promise.all([ - page.waitForEvent('filechooser').then(chooser => chooser.setFiles(asset('file-to-upload.txt'))), - page.evaluate(async () => { - const el = document.createElement('input'); - el.type = 'file'; - el.click(); - await new Promise(x => el.oninput = x); - const reader = new FileReader(); - const promise = new Promise(fulfill => reader.onload = fulfill); - reader.readAsText(el.files[0]); - return promise.then(() => reader.result); - }), +test('FC-008 should work when file input is not attached to DOM', { + annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43994' }, +}, async ({ page, asset }) => { + await page.setContent(``); + await page.evaluate(() => { + document.querySelector('button').onclick = () => { + const input = document.createElement('input'); + input.type = 'file'; + window['events'] = []; + for (const type of ['cancel', 'input', 'change']) + input.addEventListener(type, () => window['events'].push(`${type} ${input.files.length}`)); + input.click(); + }; + }); + const [chooser] = await Promise.all([ + page.waitForEvent('filechooser'), + page.click('button'), ]); + await chooser.setFiles(asset('file-to-upload.txt')); + expect(await page.evaluate(() => window['events'])).toEqual(['input 1', 'change 1']); + const content = await chooser.element().evaluate(input => { + const reader = new FileReader(); + const promise = new Promise(fulfill => reader.onload = fulfill); + reader.readAsText((input as HTMLInputElement).files[0]); + return promise.then(() => reader.result); + }); expect(content).toBe('contents of the file'); }); diff --git a/tests/registry.md b/tests/registry.md index e036dbfe8fcee..a9e039e42ca71 100644 --- a/tests/registry.md +++ b/tests/registry.md @@ -2037,6 +2037,7 @@ subsystem, add a row to the Subsystems table. Then update this file: | `EM-025` | `library/emulation-coop.spec.ts` | emulation with COOP › should preserve context options | | `EM-026` | `library/emulation-coop.spec.ts` | emulation with COOP › should preserve page.emulateMedia | | `EM-027` | `library/emulation-coop.spec.ts` | emulation with COOP › should preserve mobile emulation | +| `EM-028` | `library/emulation-focus.spec.ts` | should keep mouse drag when interacting with another page/context | ### ER — Page errors and crashes