Skip to content

Commit

Permalink
Merge branch i/6202-remove-env.isEdge to master.
Browse files Browse the repository at this point in the history
Internal: Removed mentions on Edge. See #6202.
  • Loading branch information
Reinmar committed Apr 20, 2020
2 parents ece1403 + 48f2192 commit 88fc45c
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
import uploadingPlaceholder from '../../theme/icons/image_placeholder.svg';
import env from '@ckeditor/ckeditor5-utils/src/env';
import { getViewImgFromWidget } from '../image/utils';

import '../../theme/imageuploadprogress.css';
Expand Down Expand Up @@ -104,8 +103,7 @@ export default class ImageUploadProgress extends Plugin {
return;
}

// Because in Edge there is no way to show fancy animation of completeIcon we need to skip it.
if ( status == 'complete' && fileRepository.loaders.get( uploadId ) && !env.isEdge ) {
if ( status == 'complete' && fileRepository.loaders.get( uploadId ) ) {
_showCompleteIcon( viewFigure, viewWriter, editor.editing.view );
}

Expand Down
22 changes: 2 additions & 20 deletions packages/ckeditor5-image/src/imageupload/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export function fetchLocalImage( image ) {
const mimeType = getImageMimeType( blob, imageSrc );
const ext = mimeType.replace( 'image/', '' );
const filename = `image.${ ext }`;
const file = createFileFromBlob( blob, filename, mimeType );
const file = new File( [ blob ], filename, { type: mimeType } );

file ? resolve( file ) : reject();
resolve( file );
} )
.catch( reject );
} );
Expand Down Expand Up @@ -82,21 +82,3 @@ function getImageMimeType( blob, src ) {
return 'image/jpeg';
}
}

// Creates a `File` instance from the given `Blob` instance using the specified file name.
//
// @param {Blob} blob The `Blob` instance from which the file will be created.
// @param {String} filename The file name used during the file creation.
// @param {String} mimeType The file MIME type.
// @returns {File|null} The `File` instance created from the given blob or `null` if `File API` is not available.
function createFileFromBlob( blob, filename, mimeType ) {
try {
return new File( [ blob ], filename, { type: mimeType } );
} catch ( err ) {
// Edge does not support `File` constructor ATM, see https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9551546/.
// However, the `File` function is present (so cannot be checked with `!window.File` or `typeof File === 'function'`), but
// calling it with `new File( ... )` throws an error. This try-catch prevents that. Also when the function will
// be implemented correctly in Edge the code will start working without any changes (see #247).
return null;
}
}
4 changes: 0 additions & 4 deletions packages/ckeditor5-image/tests/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ImageTextAlternative from '../src/imagetextalternative';
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
import env from '@ckeditor/ckeditor5-utils/src/env';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

describe( 'Image', () => {
Expand All @@ -20,9 +19,6 @@ describe( 'Image', () => {
testUtils.createSinonSandbox();

beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );

editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );

Expand Down
4 changes: 0 additions & 4 deletions packages/ckeditor5-image/tests/image/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest

import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import env from '@ckeditor/ckeditor5-utils/src/env';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

describe( 'Image converters', () => {
Expand All @@ -22,9 +21,6 @@ describe( 'Image converters', () => {
testUtils.createSinonSandbox();

beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );

return VirtualTestEditor.create()
.then( newEditor => {
editor = newEditor;
Expand Down
4 changes: 0 additions & 4 deletions packages/ckeditor5-image/tests/image/imageediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getData as getModelData, setData as setModelData } from '@ckeditor/cked
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
import { isImageWidget } from '../../src/image/utils';
import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
import env from '@ckeditor/ckeditor5-utils/src/env';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

describe( 'ImageEditing', () => {
Expand All @@ -23,9 +22,6 @@ describe( 'ImageEditing', () => {
testUtils.createSinonSandbox();

beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );

return VirtualTestEditor
.create( {
plugins: [ ImageEditing ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';

import env from '@ckeditor/ckeditor5-utils/src/env';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

describe( 'ImageCaptionEditing', () => {
Expand All @@ -22,9 +21,6 @@ describe( 'ImageCaptionEditing', () => {
testUtils.createSinonSandbox();

beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );

return VirtualTestEditor
.create( {
plugins: [ ImageCaptionEditing, ImageEditing, UndoEditing, Paragraph ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ import { getData as getModelData, setData as setModelData } from '@ckeditor/cked
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';

import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import env from '@ckeditor/ckeditor5-utils/src/env';

describe( 'ImageStyleEditing', () => {
let editor, model, document, viewDocument;

testUtils.createSinonSandbox( 'ImageStyleEditing' );

beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );
} );

afterEach( () => {
editor.destroy();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import env from '@ckeditor/ckeditor5-utils/src/env';

describe( 'TextAlternativeFormView', () => {
let view;

testUtils.createSinonSandbox();

beforeEach( () => {
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );

view = new TextAlternativeFormView( { t: () => {} } );
} );

Expand Down
4 changes: 0 additions & 4 deletions packages/ckeditor5-image/tests/imagetoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import View from '@ckeditor/ckeditor5-ui/src/view';
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import env from '@ckeditor/ckeditor5-utils/src/env';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

describe( 'ImageToolbar', () => {
Expand All @@ -23,9 +22,6 @@ describe( 'ImageToolbar', () => {
testUtils.createSinonSandbox();

beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );

editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );

Expand Down
26 changes: 3 additions & 23 deletions packages/ckeditor5-image/tests/imageupload/imageuploadediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ import { UploadAdapterMock, createNativeFileMock, NativeFileReaderMock } from '@
import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { getData as getViewData, stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';

import env from '@ckeditor/ckeditor5-utils/src/env';
import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';

describe( 'ImageUploadEditing', () => {
// eslint-disable-next-line max-len
const base64Sample = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=';
const isEdgeEnv = env.isEdge;

let adapterMocks = [];
let editor, model, view, doc, fileRepository, viewDocument, nativeReaderMock, loader;
Expand All @@ -49,15 +47,6 @@ describe( 'ImageUploadEditing', () => {
}

beforeEach( () => {
if ( isEdgeEnv ) {
sinon.stub( window, 'File' ).callsFake( () => {
return { name: 'file.jpg' };
} );
}

// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
sinon.stub( env, 'isEdge' ).get( () => false );

sinon.stub( window, 'FileReader' ).callsFake( () => {
nativeReaderMock = new NativeFileReaderMock();

Expand Down Expand Up @@ -816,14 +805,7 @@ describe( 'ImageUploadEditing', () => {
} );

it( 'should not upload and remove image when `File` constructor is not supported', done => {
if ( isEdgeEnv ) {
// Since on Edge `File` is already stubbed, restore it to it native form so that exception will be thrown.
sinon.restore();
// Since all stubs were restored, re-stub `scrollToTheSelection`.
sinon.stub( editor.editing.view, 'scrollToTheSelection' ).callsFake( () => {} );
} else {
sinon.stub( window, 'File' ).throws( 'Function expected.' );
}
sinon.stub( window, 'File' ).throws( 'Function expected.' );

const notification = editor.plugins.get( Notification );

Expand Down Expand Up @@ -857,8 +839,7 @@ describe( 'ImageUploadEditing', () => {
);
} );

// Skip this test on Edge as we mock `File` object there so there is no sense in testing it.
( isEdgeEnv ? it.skip : it )( 'should get file extension from base64 string', done => {
it( 'should get file extension from base64 string', done => {
setModelData( model, '<paragraph>[]foo</paragraph>' );

const clipboardHtml = `<img src=${ base64Sample } />`;
Expand All @@ -883,8 +864,7 @@ describe( 'ImageUploadEditing', () => {
} );
} );

// Skip this test on Edge as we mock `File` object there so there is no sense in testing it.
( isEdgeEnv ? it.skip : it )( 'should use fallback file extension', done => {
it( 'should use fallback file extension', done => {
setModelData( model, '<paragraph>[]foo</paragraph>' );

const clipboardHtml = `<img src=${ base64ToBlobUrl( base64Sample ) } />`;
Expand Down
31 changes: 0 additions & 31 deletions packages/ckeditor5-image/tests/imageupload/imageuploadprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import svgPlaceholder from '../../theme/icons/image_placeholder.svg';
import env from '@ckeditor/ckeditor5-utils/src/env';

describe( 'ImageUploadProgress', () => {
const imagePlaceholder = encodeURIComponent( svgPlaceholder );
Expand All @@ -44,9 +43,6 @@ describe( 'ImageUploadProgress', () => {
testUtils.createSinonSandbox();

beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );

testUtils.sinon.stub( window, 'FileReader' ).callsFake( () => {
nativeReaderMock = new NativeFileReaderMock();

Expand Down Expand Up @@ -333,31 +329,4 @@ describe( 'ImageUploadProgress', () => {
'</figure>]'
);
} );

it( 'should not create completeIcon element when browser is Microsoft Edge', done => {
testUtils.sinon.stub( env, 'isEdge' ).get( () => true );

setModelData( model, '<paragraph>[]foo</paragraph>' );
editor.execute( 'imageUpload', { file: createNativeFileMock() } );

model.document.once( 'change', () => {
model.document.once( 'change', () => {
try {
expect( getViewData( view ) ).to.equal(
'[<figure class="ck-widget image">' +
'<img src="image.png"></img>' +
'</figure>]<p>foo</p>'
);

done();
} catch ( err ) {
done( err );
}
}, { priority: 'lowest' } );

loader.file.then( () => adapterMock.mockSuccess( { default: 'image.png' } ) );
} );

loader.file.then( () => nativeReaderMock.mockSuccess( base64Sample ) );
} );
} );
4 changes: 0 additions & 4 deletions packages/ckeditor5-image/tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import global from '@ckeditor/ckeditor5-utils/src/dom/global';
import Image from '../src/image';
import ImageToolbar from '../src/imagetoolbar';
import View from '@ckeditor/ckeditor5-ui/src/view';
import env from '@ckeditor/ckeditor5-utils/src/env';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

describe( 'ImageToolbar integration', () => {
Expand All @@ -21,9 +20,6 @@ describe( 'ImageToolbar integration', () => {
testUtils.createSinonSandbox();

beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );

editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );

Expand Down

0 comments on commit 88fc45c

Please sign in to comment.