Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Other: Remove env.isEdge. Closes ckeditor/ckeditor5#6202.
Browse files Browse the repository at this point in the history
Remove some special cases for Edge, as since it's Chromium-based now, it behaves closer to others.
  • Loading branch information
tomalec committed Apr 17, 2020
1 parent 1b8369f commit d222fdf
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 91 deletions.
4 changes: 1 addition & 3 deletions src/imageupload/imageuploadprogress.js
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
4 changes: 0 additions & 4 deletions 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 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 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
4 changes: 0 additions & 4 deletions tests/imagecaption/imagecaptionediting.js
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
6 changes: 0 additions & 6 deletions tests/imagestyle/imagestyleediting.js
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
3 changes: 0 additions & 3 deletions tests/imagetextalternative/ui/textalternativeformview.js
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 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
28 changes: 4 additions & 24 deletions 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,15 +805,8 @@ 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 );

// Prevent popping up alert window.
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 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 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 d222fdf

Please sign in to comment.