@@ -402,4 +402,68 @@ describe('session module', function () {
402402 } )
403403 } )
404404 } )
405+
406+ describe ( 'ses.getblobData(identifier, callback)' , function ( ) {
407+ it ( 'returns blob data for public url' , function ( done ) {
408+ let data = JSON . stringify ( {
409+ type : 'blob' ,
410+ value : 'hello'
411+ } )
412+ let blob = new Blob ( [ data ] , { type : 'application/json' } )
413+ let blobURL = URL . createObjectURL ( blob )
414+ session . defaultSession . getBlobData ( blobURL , function ( result ) {
415+ assert . equal ( result . toString ( ) , data )
416+ done ( )
417+ } )
418+ } )
419+
420+ it ( 'returns blob data for uuid' , function ( done ) {
421+ const scheme = 'temp'
422+ const protocol = session . defaultSession . protocol
423+ const url = scheme + '://host'
424+ before ( function ( ) {
425+ if ( w != null ) w . destroy ( )
426+ w = new BrowserWindow ( { show : false } )
427+ } )
428+
429+ after ( function ( done ) {
430+ protocol . unregisterProtocol ( scheme , ( ) => {
431+ closeWindow ( w ) . then ( ( ) => {
432+ w = null
433+ done ( )
434+ } )
435+ } )
436+ } )
437+
438+ const postData = JSON . stringify ( {
439+ type : 'blob' ,
440+ value : 'hello'
441+ } )
442+ const content = `<html>
443+ <script>
444+ const {webFrame} = require('electron')
445+ webFrame.registerURLSchemeAsPrivileged('${ scheme } ')
446+ let fd = new FormData();
447+ fd.append('file', new Blob(['${ postData } '], {type:'application/json'}));
448+ fetch('${ url } ', {method:'POST', body: fd });
449+ </script>
450+ </html>`
451+
452+ protocol . registerStringProtocol ( scheme , function ( request , callback ) {
453+ if ( request . method === 'GET' ) {
454+ callback ( { data : content , mimeType : 'text/html' } )
455+ } else if ( request . method === 'POST' ) {
456+ let uuid = request . uploadData [ 1 ] . blobUUID
457+ assert ( uuid )
458+ session . defaultSession . getBlobData ( uuid , function ( result ) {
459+ assert . equal ( result . toString ( ) , postData )
460+ done ( )
461+ } )
462+ }
463+ } , function ( error ) {
464+ if ( error ) return done ( error )
465+ w . loadURL ( url )
466+ } )
467+ } )
468+ } )
405469} )
0 commit comments