Skip to content

Commit

Permalink
Fix: Correctly revoke objectURL for print blob in office viewer (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Nov 14, 2017
1 parent a786dfe commit bc12c53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/lib/viewers/office/OfficeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class OfficeViewer extends BaseViewer {
if (this.printPopup) {
this.printPopup.destroy();
}

if (this.printURL) {
URL.revokeObjectURL(this.printURL);
}

super.destroy();
}

Expand Down Expand Up @@ -331,8 +336,11 @@ class OfficeViewer extends BaseViewer {

// For other browsers, open and print in a new tab
} else {
const printURL = URL.createObjectURL(this.printBlob);
const printResult = window.open(printURL);
if (!this.printURL) {
this.printURL = URL.createObjectURL(this.printBlob);
}

const printResult = window.open(this.printURL);

// Open print popup if possible
if (printResult && typeof printResult.print === 'function') {
Expand Down Expand Up @@ -360,8 +368,6 @@ class OfficeViewer extends BaseViewer {
} else {
this.emit('printsuccess');
}

URL.revokeObjectURL(printURL);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/lib/viewers/office/__tests__/OfficeViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ describe('lib/viewers/office/OfficeViewer', () => {
office.destroy();
expect(office.printBlob).to.equal(null);
});

it('should revoke the printURL object', () => {
sandbox.stub(URL, 'revokeObjectURL');
office.printURL = 'someblob';
office.destroy();
expect(URL.revokeObjectURL).to.be.calledWith(office.printURL);
});
});

describe('load()', () => {
Expand Down Expand Up @@ -382,7 +389,6 @@ describe('lib/viewers/office/OfficeViewer', () => {
stubs.createObject = sandbox.stub(URL, 'createObjectURL');
stubs.open = sandbox.stub(window, 'open').returns(false);
stubs.browser = sandbox.stub(Browser, 'getName').returns('Chrome');
stubs.revokeObjectURL = sandbox.stub(URL, 'revokeObjectURL');
stubs.printResult = {
print: sandbox.stub(),
addEventListener: sandbox.stub()
Expand Down Expand Up @@ -429,7 +435,6 @@ describe('lib/viewers/office/OfficeViewer', () => {
expect(stubs.open).to.be.called.with;
expect(stubs.browser).to.be.called;
expect(stubs.emit).to.be.called;
expect(stubs.revokeObjectURL).to.be.called;
});

it('should use a timeout in safari', () => {
Expand Down

0 comments on commit bc12c53

Please sign in to comment.