Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: display error when previewing flash and not enabled #733

Merged
merged 7 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
14 changes: 14 additions & 0 deletions src/lib/viewers/swf/SWFLoader.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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();
26 changes: 26 additions & 0 deletions src/lib/viewers/swf/__tests__/SWFLoader-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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; // eslint-disable-line no-unused-expressions
});
});
});