@@ -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+ } ) ;
0 commit comments