Skip to content

Commit

Permalink
Fix: Only check flash for SWF files (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjin authored Mar 28, 2018
1 parent 85f6d7e commit 85b8ee4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist
src/i18n/json
jsconfig.json
functional-tests/output
yarn-error.log
5 changes: 3 additions & 2 deletions src/lib/viewers/swf/SWFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ class SWFLoader extends AssetLoader {
* @inheritdoc
*/
determineViewer(file, disabledViewers = []) {
if (!Browser.hasFlash()) {
const viewer = super.determineViewer(file, disabledViewers);
if (viewer && !Browser.hasFlash()) {
throw new PreviewError(ERROR_CODE.FLASH_NOT_ENABLED, __('error_flash_not_enabled'));
}

return super.determineViewer(file, disabledViewers);
return viewer;
}
}

Expand Down
27 changes: 24 additions & 3 deletions src/lib/viewers/swf/__tests__/SWFLoader-test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
/* eslint-disable no-unused-expressions */
import SWFLoader from '../SWFLoader';
import AssetLoader from '../../AssetLoader';
import Browser from '../../../Browser';
import PreviewError from '../../../PreviewError';

const sandbox = sinon.sandbox.create();
let file;

describe('lib/viewers/SWFLoader', () => {
afterEach(() => {
sandbox.verifyAndRestore();
});

describe('determineViewer()', () => {
beforeEach(() => {
file = {
extension: 'swf',
representations: {
entries: [
{
representation: 'ORIGINAL'
}
]
}
};
});

it('should throw a preview error if flash is not supported', () => {
sandbox.stub(Browser, 'hasFlash').returns(false);
expect(() => SWFLoader.determineViewer()).to.throw(PreviewError);
expect(() => SWFLoader.determineViewer(file)).to.throw(PreviewError);
});

it('should call the superclass determineViewer if flash is suported', () => {
sandbox.stub(Browser, 'hasFlash').returns(true);
const stub = sandbox.stub(AssetLoader.prototype, 'determineViewer');
SWFLoader.determineViewer();
expect(stub).to.have.been.called; // eslint-disable-line no-unused-expressions
SWFLoader.determineViewer(file);
expect(stub).to.be.called;
});

it('should not check Flash if file is not SWF', () => {
sandbox.stub(Browser, 'hasFlash');
file.extension = 'jpg';
expect(Browser.hasFlash).to.not.be.called;
});
});
});

0 comments on commit 85b8ee4

Please sign in to comment.