@@ -56,6 +56,9 @@ if (qqtest.canDownloadFileAsBlob) {
5656 request . respond ( 200 , null , JSON . stringify ( { success : true , testParam : "testVal" } ) ) ;
5757 } , 10 ) ;
5858 } ,
59+ onAutoRetry : function ( id , name , attemptNumber ) {
60+ assert . fail ( "This should not be called" ) ;
61+ } ,
5962 onUploadChunkSuccess : function ( id , chunkData , response , xhr ) {
6063 var request = fileTestHelper . getRequests ( ) [ fileTestHelper . getRequests ( ) . length - 1 ] ,
6164 requestParams ;
@@ -197,6 +200,87 @@ if (qqtest.canDownloadFileAsBlob) {
197200 } ) ;
198201 }
199202
203+ function testChunkedEveryFailureAndRecovery ( done ) {
204+ var alreadyFailed = false ,
205+ uploader = new qq . FineUploaderBasic ( {
206+ request : {
207+ endpoint : testUploadEndpoint
208+ } ,
209+ chunking : {
210+ enabled : true ,
211+ partSize : chunkSize
212+ } ,
213+ retry : {
214+ autoAttemptDelay : 0 ,
215+ enableAuto : true
216+ } ,
217+ callbacks : {
218+ onUploadChunk : function ( id , name , chunkData ) {
219+ chunksSent ++ ;
220+
221+ assert . equal ( id , 0 , "Wrong ID passed to onUpoadChunk" ) ;
222+ assert . equal ( name , uploader . getName ( id ) , "Wrong name passed to onUploadChunk" ) ;
223+ assert . equal ( chunkData . partIndex , chunksSent - 1 , "Wrong partIndex passed to onUploadChunk" ) ;
224+ assert . equal ( chunkData . startByte , ( chunksSent - 1 ) * chunkSize + 1 , "Wrong startByte passed to onUploadChunk" ) ;
225+ assert . equal ( chunkData . endByte , chunksSent === expectedChunks ? expectedFileSize : chunkData . startByte + chunkSize - 1 , "Wrong startByte passed to onUploadChunk" ) ;
226+ assert . equal ( chunkData . totalParts , expectedChunks , "Wrong totalParts passed to onUploadChunk" ) ;
227+
228+ setTimeout ( function ( ) {
229+ var request = fileTestHelper . getRequests ( ) [ fileTestHelper . getRequests ( ) . length - 1 ] ;
230+
231+ if ( ! alreadyFailed ) {
232+ alreadyFailed = true ;
233+
234+ chunksSent -- ;
235+ request . respond ( 500 , null , JSON . stringify ( { testParam : "testVal" } ) ) ;
236+ }
237+ else {
238+ alreadyFailed = false ;
239+ request . respond ( 200 , null , JSON . stringify ( { success : true , testParam : "testVal" } ) ) ;
240+ }
241+ } , 10 ) ;
242+ } ,
243+ onAutoRetry : function ( id , name , attemptNumber ) {
244+ assert . equal ( id , 0 , "Wrong ID passed to onAutoRetry" ) ;
245+ assert . equal ( name , uploader . getName ( id ) , "Wrong name passed to onAutoRetry" ) ;
246+ assert . equal ( attemptNumber , 1 , "Wrong auto retry attempt #" ) ;
247+ } ,
248+ onUploadChunkSuccess : function ( id , chunkData , response , xhr ) {
249+ var request = fileTestHelper . getRequests ( ) [ fileTestHelper . getRequests ( ) . length - 1 ] ,
250+ requestParams = request . requestBody . fields ;
251+
252+ chunksSucceeded ++ ;
253+
254+ assert . equal ( requestParams . qquuid , uploader . getUuid ( id ) , "Wrong uuid param" ) ;
255+ assert . equal ( requestParams . qqpartindex , chunksSent - 1 , "Wrong part index param" ) ;
256+ assert . equal ( requestParams . qqpartbyteoffset , ( chunksSent - 1 ) * chunkSize , "Wrong part byte offset param" ) ;
257+ assert . equal ( requestParams . qqtotalfilesize , expectedFileSize , "Wrong total file size param" ) ;
258+ assert . equal ( requestParams . qqtotalparts , expectedChunks , "Wrong total parts param" ) ;
259+ assert . equal ( requestParams . qqfilename , uploader . getName ( id ) , "Wrong filename param" ) ;
260+ assert . equal ( requestParams . qqchunksize , requestParams . qqfile . size , "Wrong chunk size param" ) ;
261+ assert . equal ( id , 0 , "Wrong ID passed to onUpoadChunkSuccess" ) ;
262+
263+ assert . equal ( response . testParam , "testVal" ) ;
264+ } ,
265+ onComplete : function ( id , name , response ) {
266+ assert . equal ( expectedChunks , chunksSent , "Wrong # of chunks sent." ) ;
267+ assert . equal ( expectedChunks , chunksSucceeded , "Wrong # of chunks succeeded" ) ;
268+ assert . equal ( response . testParam , "testVal" ) ;
269+ assert . equal ( response . success , true ) ;
270+
271+ done ( ) ;
272+ }
273+ }
274+ } ) ,
275+ chunksSent = 0 ,
276+ chunksSucceeded = 0 ;
277+
278+ qqtest . downloadFileAsBlob ( "up.jpg" , "image/jpeg" ) . then ( function ( blob ) {
279+ fileTestHelper . mockXhr ( ) ;
280+ uploader . addFiles ( { name : "test" , blob : blob } ) ;
281+ } ) ;
282+ }
283+
200284 it ( "sends proper number of chunks when chunking is enabled, MPE" , function ( done ) {
201285 testChunkedUpload ( {
202286 mpe : true ,
@@ -246,6 +330,10 @@ if (qqtest.canDownloadFileAsBlob) {
246330 testChunkedFailureAndRecovery ( true , done ) ;
247331 } ) ;
248332
333+ it ( "fails every chunk once, then recovers and ensure attemptNumber is 1" , function ( done ) {
334+ testChunkedEveryFailureAndRecovery ( done ) ;
335+ } ) ;
336+
249337 describe ( "resume feature tests" , function ( ) {
250338 var nativeLocalStorageSetItem = window . localStorage . setItem ,
251339 acknowledgeRequests = function ( endpoint ) {
0 commit comments