Add unit-tests for PDFPageProxy.stats (PR 9245 follow-up)
				
					
				
			This wasn't included in PR 9245, since all the API options were still global at that time. Writing the unit-tests also uncovered an issue with `getOperatorList` not starting the "Page Request" timer.
This commit is contained in:
		
							parent
							
								
									e8b5088370
								
							
						
					
					
						commit
						74e9999044
					
				@ -1037,6 +1037,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
 | 
			
		||||
          lastChunk: false,
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        this._stats.time('Page Request');
 | 
			
		||||
        this.transport.messageHandler.send('RenderPageRequest', {
 | 
			
		||||
          pageIndex: this.pageIndex,
 | 
			
		||||
          intent: renderingIntent,
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import {
 | 
			
		||||
  OPS, PasswordException, PasswordResponses, StreamType, stringToBytes
 | 
			
		||||
} from '../../src/shared/util';
 | 
			
		||||
import {
 | 
			
		||||
  DOMCanvasFactory, RenderingCancelledException
 | 
			
		||||
  DOMCanvasFactory, RenderingCancelledException, StatTimer
 | 
			
		||||
} from '../../src/display/dom_utils';
 | 
			
		||||
import {
 | 
			
		||||
  getDocument, PDFDataRangeTransport, PDFDocumentProxy, PDFPageProxy, PDFWorker
 | 
			
		||||
@ -831,7 +831,7 @@ describe('api', function() {
 | 
			
		||||
        done.fail(reason);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
    it('gets stats', function(done) {
 | 
			
		||||
    it('gets document stats', function(done) {
 | 
			
		||||
      var promise = doc.getStats();
 | 
			
		||||
      promise.then(function (stats) {
 | 
			
		||||
        expect(stats).toEqual({ streamTypes: [], fontTypes: [], });
 | 
			
		||||
@ -1141,7 +1141,7 @@ describe('api', function() {
 | 
			
		||||
        done.fail(reason);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
    it('gets stats after parsing page', function (done) {
 | 
			
		||||
    it('gets document stats after parsing page', function(done) {
 | 
			
		||||
      var promise = page.getOperatorList().then(function () {
 | 
			
		||||
        return pdfDocument.getStats();
 | 
			
		||||
      });
 | 
			
		||||
@ -1160,6 +1160,77 @@ describe('api', function() {
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('gets page stats after parsing page, without `pdfBug` set',
 | 
			
		||||
        function(done) {
 | 
			
		||||
      page.getOperatorList().then((opList) => {
 | 
			
		||||
        return page.stats;
 | 
			
		||||
      }).then((stats) => {
 | 
			
		||||
        expect(stats).toEqual(null);
 | 
			
		||||
        done();
 | 
			
		||||
      }, done.fail);
 | 
			
		||||
    });
 | 
			
		||||
    it('gets page stats after parsing page, with `pdfBug` set', function(done) {
 | 
			
		||||
      let loadingTask = getDocument(
 | 
			
		||||
        buildGetDocumentParams(basicApiFileName, { pdfBug: true, }));
 | 
			
		||||
 | 
			
		||||
      loadingTask.promise.then((pdfDoc) => {
 | 
			
		||||
        return pdfDoc.getPage(1).then((pdfPage) => {
 | 
			
		||||
          return pdfPage.getOperatorList().then((opList) => {
 | 
			
		||||
            return pdfPage.stats;
 | 
			
		||||
          });
 | 
			
		||||
        });
 | 
			
		||||
      }).then((stats) => {
 | 
			
		||||
        expect(stats instanceof StatTimer).toEqual(true);
 | 
			
		||||
        expect(stats.times.length).toEqual(1);
 | 
			
		||||
 | 
			
		||||
        let [statEntry] = stats.times;
 | 
			
		||||
        expect(statEntry.name).toEqual('Page Request');
 | 
			
		||||
        expect(statEntry.end - statEntry.start).toBeGreaterThan(0);
 | 
			
		||||
 | 
			
		||||
        loadingTask.destroy().then(done);
 | 
			
		||||
      }, done.fail);
 | 
			
		||||
    });
 | 
			
		||||
    it('gets page stats after rendering page, with `pdfBug` set',
 | 
			
		||||
        function(done) {
 | 
			
		||||
      if (isNodeJS()) {
 | 
			
		||||
        pending('TODO: Support Canvas testing in Node.js.');
 | 
			
		||||
      }
 | 
			
		||||
      let loadingTask = getDocument(
 | 
			
		||||
        buildGetDocumentParams(basicApiFileName, { pdfBug: true, }));
 | 
			
		||||
      let canvasAndCtx;
 | 
			
		||||
 | 
			
		||||
      loadingTask.promise.then((pdfDoc) => {
 | 
			
		||||
        return pdfDoc.getPage(1).then((pdfPage) => {
 | 
			
		||||
          let viewport = pdfPage.getViewport(1);
 | 
			
		||||
          canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
 | 
			
		||||
 | 
			
		||||
          let renderTask = pdfPage.render({
 | 
			
		||||
            canvasContext: canvasAndCtx.context,
 | 
			
		||||
            viewport,
 | 
			
		||||
          });
 | 
			
		||||
          return renderTask.promise.then(() => {
 | 
			
		||||
            return pdfPage.stats;
 | 
			
		||||
          });
 | 
			
		||||
        });
 | 
			
		||||
      }).then((stats) => {
 | 
			
		||||
        expect(stats instanceof StatTimer).toEqual(true);
 | 
			
		||||
        expect(stats.times.length).toEqual(3);
 | 
			
		||||
 | 
			
		||||
        let [statEntryOne, statEntryTwo, statEntryThree] = stats.times;
 | 
			
		||||
        expect(statEntryOne.name).toEqual('Page Request');
 | 
			
		||||
        expect(statEntryOne.end - statEntryOne.start).toBeGreaterThan(0);
 | 
			
		||||
 | 
			
		||||
        expect(statEntryTwo.name).toEqual('Rendering');
 | 
			
		||||
        expect(statEntryTwo.end - statEntryTwo.start).toBeGreaterThan(0);
 | 
			
		||||
 | 
			
		||||
        expect(statEntryThree.name).toEqual('Overall');
 | 
			
		||||
        expect(statEntryThree.end - statEntryThree.start).toBeGreaterThan(0);
 | 
			
		||||
 | 
			
		||||
        CanvasFactory.destroy(canvasAndCtx);
 | 
			
		||||
        loadingTask.destroy().then(done);
 | 
			
		||||
      }, done.fail);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('cancels rendering of page', function(done) {
 | 
			
		||||
      if (isNodeJS()) {
 | 
			
		||||
        pending('TODO: Support Canvas testing in Node.js.');
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user