Skip to content

Commit a1a99b0

Browse files
test(webkit): cover uploaded files in IndexedDB (#43723)
Co-authored-by: microsoft-playwright-automation[bot] <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com>
1 parent 987de7c commit a1a99b0

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎tests/page/page-set-input-files.spec.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,35 @@ test('IF-021 should preserve lastModified timestamp', async ({ page, asset }) =>
452452
for (let i = 0; i < timestamps.length; i++)
453453
expect(Math.abs(timestamps[i] - expectedTimestamps[i]), `expected: ${expectedTimestamps}; actual: ${timestamps}`).toBeLessThanOrEqual(1000);
454454
});
455+
456+
test('IF-022 should store an uploaded file in IndexedDB', {
457+
annotation: [
458+
{ type: 'issue', description: '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/microsoft/playwright/issues/42795' },
459+
{ type: 'issue', description: 'https://bugs.webkit.org/show_bug.cgi?id=156347' },
460+
],
461+
}, async ({ page, server, asset, browserName }) => {
462+
test.fixme(browserName === 'webkit', 'WebKit does not support storing files in IndexedDB in private browsing.');
463+
464+
await page.goto(server.PREFIX + '/input/fileupload.html');
465+
const input = page.locator('input[type=file]');
466+
await input.setInputFiles(asset('file-to-upload.txt'));
467+
const storedFile = await input.evaluate(async (input: HTMLInputElement) => {
468+
const db = await new Promise<IDBDatabase>((resolve, reject) => {
469+
const request = indexedDB.open('file-upload');
470+
request.onupgradeneeded = () => request.result.createObjectStore('files');
471+
request.onsuccess = () => resolve(request.result);
472+
request.onerror = () => reject(request.error);
473+
});
474+
const file = await new Promise<File>((resolve, reject) => {
475+
const transaction = db.transaction('files', 'readwrite');
476+
const store = transaction.objectStore('files');
477+
store.put(input.files[0], 'file');
478+
const request = store.get('file');
479+
transaction.oncomplete = () => resolve(request.result);
480+
transaction.onabort = () => reject(transaction.error);
481+
});
482+
db.close();
483+
return { name: file.name, text: await file.text() };
484+
});
485+
expect(storedFile).toEqual({ name: 'file-to-upload.txt', text: 'contents of the file' });
486+
});

‎tests/registry.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,7 @@ subsystem, add a row to the Subsystems table. Then update this file:
32413241
| `IF-019` | `page/page-set-input-files.spec.ts` | input event.composed should be true and cross shadow dom boundary |
32423242
| `IF-020` | `page/page-set-input-files.spec.ts` | input should trigger events when files changed second time |
32433243
| `IF-021` | `page/page-set-input-files.spec.ts` | should preserve lastModified timestamp |
3244+
| `IF-022` | `page/page-set-input-files.spec.ts` | should store an uploaded file in IndexedDB |
32443245

32453246
### IN — Inspector
32463247

0 commit comments

Comments
 (0)