@@ -6222,6 +6222,44 @@ small scripts as well as for`);
62226222
62236223 await loadingTask . destroy ( ) ;
62246224 } ) ;
6225+
6226+ it ( "fills missing pageIndices with the first free slots" , async function ( ) {
6227+ let loadingTask = getDocument (
6228+ buildGetDocumentParams ( "tracemonkey.pdf" )
6229+ ) ;
6230+ let pdfDoc = await loadingTask . promise ;
6231+ const data = await pdfDoc . extractPages ( [
6232+ { document : null , includePages : [ 1 , 3 , 5 ] , pageIndices : [ 1 ] } ,
6233+ ] ) ;
6234+ await loadingTask . destroy ( ) ;
6235+
6236+ loadingTask = getDocument ( data ) ;
6237+ pdfDoc = await loadingTask . promise ;
6238+
6239+ expect ( pdfDoc . numPages ) . toEqual ( 3 ) ;
6240+
6241+ // Page 4 in the original document should occupy the first free slot.
6242+ let pdfPage = await pdfDoc . getPage ( 1 ) ;
6243+ let { items : textItems } = await pdfPage . getTextContent ( ) ;
6244+ expect ( mergeText ( textItems ) . includes ( "3. Trace Trees" ) ) . toBeTrue ( ) ;
6245+
6246+ // Page 2 in the original document keeps its explicit destination slot.
6247+ pdfPage = await pdfDoc . getPage ( 2 ) ;
6248+ ( { items : textItems } = await pdfPage . getTextContent ( ) ) ;
6249+ expect (
6250+ mergeText ( textItems ) . includes ( "2. Overview: Example Tracing Run" )
6251+ ) . toBeTrue ( ) ;
6252+
6253+ // Page 6 in the original document should occupy the remaining free
6254+ // slot.
6255+ pdfPage = await pdfDoc . getPage ( 3 ) ;
6256+ ( { items : textItems } = await pdfPage . getTextContent ( ) ) ;
6257+ expect (
6258+ mergeText ( textItems ) . includes ( "4. Nested Trace Tree Formation" )
6259+ ) . toBeTrue ( ) ;
6260+
6261+ await loadingTask . destroy ( ) ;
6262+ } ) ;
62256263 } ) ;
62266264
62276265 describe ( "AcroForm" , function ( ) {
0 commit comments