@@ -5180,6 +5180,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
51805180 it ( "should fetch document info and page using ranges" , async function ( ) {
51815181 const initialDataLength = 4000 ;
51825182 const subArrays = [ ] ;
5183+ let initialProgress = null ;
51835184 let fetches = 0 ;
51845185
51855186 const data = await dataPromise ;
@@ -5193,19 +5194,29 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
51935194 const chunk = new Uint8Array ( data . subarray ( begin , end ) ) ;
51945195 subArrays . push ( chunk ) ;
51955196
5196- transport . onDataProgress ( initialDataLength ) ;
51975197 transport . onDataRange ( begin , chunk ) ;
51985198 } ) ;
51995199 } ;
52005200
52015201 const loadingTask = getDocument ( { range : transport } ) ;
5202+ loadingTask . onProgress = evt => {
5203+ initialProgress = evt ;
5204+ loadingTask . onProgress = null ;
5205+ } ;
5206+
52025207 const pdfDocument = await loadingTask . promise ;
52035208 expect ( pdfDocument . numPages ) . toEqual ( 14 ) ;
52045209
52055210 const pdfPage = await pdfDocument . getPage ( 10 ) ;
52065211 expect ( pdfPage . rotate ) . toEqual ( 0 ) ;
52075212 expect ( fetches ) . toBeGreaterThan ( 2 ) ;
52085213
5214+ expect ( initialProgress ) . toEqual ( {
5215+ loaded : initialDataLength ,
5216+ total : data . length ,
5217+ percent : 0 ,
5218+ } ) ;
5219+
52095220 // Check that the TypedArrays were transferred.
52105221 for ( const array of subArrays ) {
52115222 expect ( array . length ) . toEqual ( 0 ) ;
@@ -5217,6 +5228,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
52175228 it ( "should fetch document info and page using range and streaming" , async function ( ) {
52185229 const initialDataLength = 4000 ;
52195230 const subArrays = [ ] ;
5231+ let initialProgress = null ;
52205232 let fetches = 0 ;
52215233
52225234 const data = await dataPromise ;
@@ -5242,13 +5254,24 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
52425254 } ;
52435255
52445256 const loadingTask = getDocument ( { range : transport } ) ;
5257+ loadingTask . onProgress = evt => {
5258+ initialProgress = evt ;
5259+ loadingTask . onProgress = null ;
5260+ } ;
5261+
52455262 const pdfDocument = await loadingTask . promise ;
52465263 expect ( pdfDocument . numPages ) . toEqual ( 14 ) ;
52475264
52485265 const pdfPage = await pdfDocument . getPage ( 10 ) ;
52495266 expect ( pdfPage . rotate ) . toEqual ( 0 ) ;
52505267 expect ( fetches ) . toEqual ( 1 ) ;
52515268
5269+ expect ( initialProgress ) . toEqual ( {
5270+ loaded : initialDataLength ,
5271+ total : data . length ,
5272+ percent : 0 ,
5273+ } ) ;
5274+
52525275 await new Promise ( resolve => {
52535276 waitSome ( resolve ) ;
52545277 } ) ;
@@ -5266,6 +5289,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
52665289 "using complete initialData" ,
52675290 async function ( ) {
52685291 const subArrays = [ ] ;
5292+ let initialProgress = null ;
52695293 let fetches = 0 ;
52705294
52715295 const data = await dataPromise ;
@@ -5285,13 +5309,24 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
52855309 disableRange : true ,
52865310 range : transport ,
52875311 } ) ;
5312+ loadingTask . onProgress = evt => {
5313+ initialProgress = evt ;
5314+ loadingTask . onProgress = null ;
5315+ } ;
5316+
52885317 const pdfDocument = await loadingTask . promise ;
52895318 expect ( pdfDocument . numPages ) . toEqual ( 14 ) ;
52905319
52915320 const pdfPage = await pdfDocument . getPage ( 10 ) ;
52925321 expect ( pdfPage . rotate ) . toEqual ( 0 ) ;
52935322 expect ( fetches ) . toEqual ( 0 ) ;
52945323
5324+ expect ( initialProgress ) . toEqual ( {
5325+ loaded : data . length ,
5326+ total : data . length ,
5327+ percent : 100 ,
5328+ } ) ;
5329+
52955330 // Check that the TypedArrays were transferred.
52965331 for ( const array of subArrays ) {
52975332 expect ( array . length ) . toEqual ( 0 ) ;
0 commit comments