From ed3851823ed776ca2642a4b81f3196500e857c7a Mon Sep 17 00:00:00 2001 From: Daniel DeMicco Date: Thu, 22 Mar 2018 14:58:35 -0700 Subject: [PATCH 1/2] Fix: display error when previewing flash and not enabled --- src/i18n/en-US.properties | 2 ++ src/lib/events.js | 3 +- src/lib/viewers/swf/SWFLoader.js | 14 ++++++++++ .../viewers/swf/__tests__/SWFLoader-test.js | 28 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/lib/viewers/swf/__tests__/SWFLoader-test.js diff --git a/src/i18n/en-US.properties b/src/i18n/en-US.properties index 7890dc4c0..c01979c45 100644 --- a/src/i18n/en-US.properties +++ b/src/i18n/en-US.properties @@ -62,6 +62,8 @@ error_try_again_later=We're sorry the preview didn't load. Please try again late error_bad_file=We're sorry the preview didn't load. This file could not be converted. # Preview error message shown when the file cannot be downloaded error_not_downloadable=Oops! It looks like something is wrong with this file. We apologize for the inconvenience and recommend that you upload a new version of this file or roll back to a previous version. Please contact us for more details. +# Preview error message shown when flash is not enabled on their browser +error_flash_not_enabled=We're sorry, the preview didn't load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page. # Media Preview # Label for autoplay in media player diff --git a/src/lib/events.js b/src/lib/events.js index fb6234c9b..e0a61dd47 100644 --- a/src/lib/events.js +++ b/src/lib/events.js @@ -40,7 +40,8 @@ export const ERROR_CODE = { CONVERSION_TRY_AGAIN_LATER: 'error_try_again_later', CONVERSION_UNSUPPORTED_FORMAT: 'error_unsupported_format', VIEWER_LOAD_TIMEOUT: 'error_viewer_load_timeout', - CONTENT_DOWNLOAD: 'error_content_download' + CONTENT_DOWNLOAD: 'error_content_download', + FLASH_NOT_ENABLED: 'error_flash_not_enabled' }; export const PREVIEW_LOAD_EVENT = ''; diff --git a/src/lib/viewers/swf/SWFLoader.js b/src/lib/viewers/swf/SWFLoader.js index 7eb007bca..fdbc7b013 100644 --- a/src/lib/viewers/swf/SWFLoader.js +++ b/src/lib/viewers/swf/SWFLoader.js @@ -1,6 +1,9 @@ import AssetLoader from '../AssetLoader'; import SWFViewer from './SWFViewer'; import { ORIGINAL_REP_NAME } from '../../constants'; +import { ERROR_CODE } from '../../events'; +import Browser from '../../Browser'; +import PreviewError from '../../PreviewError'; // Order of the viewers matters. Prefer original before others. Go from specific to general. const VIEWERS = [ @@ -21,6 +24,17 @@ class SWFLoader extends AssetLoader { super(); this.viewers = VIEWERS; } + + /** + * @inheritdoc + */ + determineViewer(file, disabledViewers = []) { + if (!Browser.hasFlash()) { + throw new PreviewError(ERROR_CODE.FLASH_NOT_ENABLED, __('error_flash_not_enabled')); + } + + return super.determineViewer(file, disabledViewers); + } } export default new SWFLoader(); diff --git a/src/lib/viewers/swf/__tests__/SWFLoader-test.js b/src/lib/viewers/swf/__tests__/SWFLoader-test.js new file mode 100644 index 000000000..d2a51d2f0 --- /dev/null +++ b/src/lib/viewers/swf/__tests__/SWFLoader-test.js @@ -0,0 +1,28 @@ +/* eslint-disable no-unused-expressions */ +/* global swfobject */ +import SWFLoader from '../SWFLoader'; +import AssetLoader from '../../AssetLoader'; +import Browser from '../../../Browser'; +import PreviewError from '../../../PreviewError'; + +const sandbox = sinon.sandbox.create(); + +describe('lib/viewers/SWFLoader', () => { + afterEach(() => { + sandbox.verifyAndRestore(); + }); + + describe('determineViewer()', () => { + it('should throw a preview error if flash is not supported', () => { + sandbox.stub(Browser, 'hasFlash').returns(false); + expect(() => SWFLoader.determineViewer()).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; + }); + }); +}); From 05197fc5488d93ea2dfa3459baae4f223209576f Mon Sep 17 00:00:00 2001 From: Daniel DeMicco Date: Tue, 27 Mar 2018 10:37:10 -0700 Subject: [PATCH 2/2] Chore: fix linting errors --- src/lib/viewers/swf/__tests__/SWFLoader-test.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/viewers/swf/__tests__/SWFLoader-test.js b/src/lib/viewers/swf/__tests__/SWFLoader-test.js index d2a51d2f0..6ba209ae4 100644 --- a/src/lib/viewers/swf/__tests__/SWFLoader-test.js +++ b/src/lib/viewers/swf/__tests__/SWFLoader-test.js @@ -1,5 +1,3 @@ -/* eslint-disable no-unused-expressions */ -/* global swfobject */ import SWFLoader from '../SWFLoader'; import AssetLoader from '../../AssetLoader'; import Browser from '../../../Browser'; @@ -22,7 +20,7 @@ describe('lib/viewers/SWFLoader', () => { sandbox.stub(Browser, 'hasFlash').returns(true); const stub = sandbox.stub(AssetLoader.prototype, 'determineViewer'); SWFLoader.determineViewer(); - expect(stub).to.have.been.called; + expect(stub).to.have.been.called; // eslint-disable-line no-unused-expressions }); }); });