@@ -551,4 +551,47 @@ describe('upload file', function() {
551551 expect ( fileThird . timeRemaining ( ) ) . toBe ( 0 ) ;
552552 expect ( flow . timeRemaining ( ) ) . toBe ( 0 ) ;
553553 } ) ;
554+
555+ it ( 'should allow to hook initFileFn and readFileFn' , function ( ) {
556+ var error = jasmine . createSpy ( 'error' ) ;
557+ var success = jasmine . createSpy ( 'success' ) ;
558+ flow . on ( 'fileError' , error ) ;
559+ flow . on ( 'fileSuccess' , success ) ;
560+
561+ flow . opts . chunkSize = 1 ;
562+
563+ flow . opts . simultaneousUploads = 10 ;
564+
565+ flow . opts . initFileFn = function ( flowObj ) {
566+ // emulate a compresso that starting from a payload of 10 characters
567+ // will output 6 characters.
568+ var fakeFile = {
569+ size : 6
570+ }
571+
572+ flowObj . file = fakeFile ;
573+ flowObj . size = flowObj . file . size ;
574+ }
575+
576+ flow . opts . readFileFn = function ( fileObj , startByte , endByte , fileType , chunk ) {
577+ chunk . readFinished ( 'X' ) ;
578+ }
579+
580+ flow . addFile ( new Blob ( [ '0123456789' ] ) ) ;
581+
582+ flow . upload ( ) ;
583+
584+ expect ( requests . length ) . toBe ( 6 ) ;
585+
586+ for ( var i = 0 ; i < requests . length ; i ++ ) {
587+ requests [ i ] . respond ( 200 ) ;
588+ }
589+
590+ var file = flow . files [ 0 ] ;
591+ expect ( file . progress ( ) ) . toBe ( 1 ) ;
592+ expect ( file . isUploading ( ) ) . toBe ( false ) ;
593+ expect ( file . isComplete ( ) ) . toBe ( true ) ;
594+
595+ expect ( requests . length ) . toBe ( 6 ) ;
596+ } ) ;
554597} ) ;
0 commit comments