From 9900eab74592544c6d0aad53b8db9fdf2c8f3d86 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 18 Oct 2017 15:03:10 +0200 Subject: [PATCH 01/14] Reuse Cloud Services loader for Easy Image. --- plugins/easyimage/plugin.js | 84 ++----------------------------------- 1 file changed, 3 insertions(+), 81 deletions(-) diff --git a/plugins/easyimage/plugin.js b/plugins/easyimage/plugin.js index b4e5490acef..d11dd18d7b8 100644 --- a/plugins/easyimage/plugin.js +++ b/plugins/easyimage/plugin.js @@ -138,6 +138,8 @@ loadMethod: 'loadAndUpload', + loaderType: CKEDITOR.plugins.cloudservices.fileLoader, + additionalRequestParameters: { isEasyImage: true }, @@ -164,86 +166,6 @@ srcset + '" sizes="100vw">' ); } } ); - - editor.on( 'fileUploadRequest', function( evt ) { - var requestData = evt.data.requestData; - - if ( !requestData.isEasyImage ) { - return; - } - - evt.data.requestData.file = evt.data.requestData.upload; - delete evt.data.requestData.upload; - - // This property is used by fileUploadResponse callback to identify EI requests. - evt.data.fileLoader.isEasyImage = true; - - evt.data.fileLoader.xhr.setRequestHeader( 'Authorization', editor.config.easyimage_token ); - } ); - - editor.on( 'fileUploadResponse', function( evt ) { - var fileLoader = evt.data.fileLoader, - xhr = fileLoader.xhr, - response; - - if ( !fileLoader.isEasyImage ) { - return; - } - - evt.stop(); - - try { - response = JSON.parse( xhr.responseText ); - - evt.data.response = response; - } catch ( e ) { - CKEDITOR.warn( 'filetools-response-error', { responseText: xhr.responseText } ); - } - } ); - - // Handle images which are not available in the dataTransfer. - // This means that we need to read them from the elements. - editor.on( 'paste', function( evt ) { - var fileTools = CKEDITOR.fileTools; - - // For performance reason do not parse data if it does not contain img tag and data attribute. - if ( !evt.data.dataValue.match( / Date: Wed, 18 Oct 2017 17:03:09 +0200 Subject: [PATCH 02/14] Corrected Cloud Services loader type name after recent refactoring. --- plugins/easyimage/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/easyimage/plugin.js b/plugins/easyimage/plugin.js index d11dd18d7b8..4551f50e1b7 100644 --- a/plugins/easyimage/plugin.js +++ b/plugins/easyimage/plugin.js @@ -138,7 +138,7 @@ loadMethod: 'loadAndUpload', - loaderType: CKEDITOR.plugins.cloudservices.fileLoader, + loaderType: CKEDITOR.plugins.cloudservices.cloudServicesLoader, additionalRequestParameters: { isEasyImage: true From ba2d929ea6a5d85a76e4a7232f8fd4f86466cae5 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 18 Oct 2017 17:16:58 +0200 Subject: [PATCH 03/14] Further simplify widget definition, update sample. --- plugins/easyimage/plugin.js | 8 -------- plugins/easyimage/samples/easyimage.html | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/plugins/easyimage/plugin.js b/plugins/easyimage/plugin.js index 4551f50e1b7..1c19b54ab0a 100644 --- a/plugins/easyimage/plugin.js +++ b/plugins/easyimage/plugin.js @@ -129,21 +129,13 @@ } function registerUploadWidget( editor ) { - var uploadUrl = CKEDITOR.fileTools.getUploadUrl( editor.config, 'easyimage' ); - CKEDITOR.fileTools.addUploadWidget( editor, 'uploadeasyimage', { supportedTypes: /image\/(jpeg|png|gif|bmp)/, - uploadUrl: uploadUrl, - loadMethod: 'loadAndUpload', loaderType: CKEDITOR.plugins.cloudservices.cloudServicesLoader, - additionalRequestParameters: { - isEasyImage: true - }, - fileToElement: function() { var img = new CKEDITOR.dom.element( 'img' ); img.setAttribute( 'src', loadingImage ); diff --git a/plugins/easyimage/samples/easyimage.html b/plugins/easyimage/samples/easyimage.html index fdd58fbdfdf..19c9ab6f769 100644 --- a/plugins/easyimage/samples/easyimage.html +++ b/plugins/easyimage/samples/easyimage.html @@ -110,8 +110,8 @@

Apollo 11

getToken( function( token ) { CKEDITOR.replace( 'editor', { extraPlugins: 'easyimage', - easyimageUploadUrl: 'https://files.cke-cs.com/upload/', - easyimage_token: token, + cloudServices_url: 'https://files.cke-cs.com/upload/', + cloudServices_token: token, height: 500 } ); } ); From f4052a4d0d366f393f585734ed12cb5720f60bc4 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Thu, 19 Oct 2017 15:14:55 +0200 Subject: [PATCH 04/14] Updated API to recent test suite changes. Restored paste handler for base64 encoded images. --- plugins/easyimage/plugin.js | 44 +++++++++++++++++++++++++ tests/plugins/easyimage/uploadwidget.js | 21 +++++++++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/plugins/easyimage/plugin.js b/plugins/easyimage/plugin.js index 1c19b54ab0a..6bbabc546d4 100644 --- a/plugins/easyimage/plugin.js +++ b/plugins/easyimage/plugin.js @@ -158,6 +158,50 @@ srcset + '" sizes="100vw">' ); } } ); + + // Handle images which are not available in the dataTransfer. + // This means that we need to read them from the elements. + editor.on( 'paste', function( evt ) { + var fileTools = CKEDITOR.fileTools; + + // For performance reason do not parse data if it does not contain img tag and data attribute. + if ( !evt.data.dataValue.match( / Date: Thu, 19 Oct 2017 15:16:51 +0200 Subject: [PATCH 05/14] We no longer need to check for upload url, as Cloud Services will automatically use the one from the config. --- tests/plugins/easyimage/uploadwidget.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index 7a9f0dbc4ac..fb6022d0cc2 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -7,7 +7,7 @@ 'use strict'; ( function() { - var uploadCount, loadAndUploadCount, lastUploadUrl, resumeAfter, tests, + var uploadCount, loadAndUploadCount, resumeAfter, tests, IMG_URL = '%BASE_PATH%_assets/logo.png', DATA_IMG = 'data:', BLOB_IMG = 'blob:'; @@ -74,18 +74,16 @@ resumeAfter = bender.tools.resumeAfter; - CKEDITOR.fileTools.fileLoader.prototype.loadAndUpload = function( url ) { + CKEDITOR.fileTools.fileLoader.prototype.loadAndUpload = function() { loadAndUploadCount++; - lastUploadUrl = url; this.responseData = CKEDITOR.tools.clone( responseData ); }; CKEDITOR.fileTools.fileLoader.prototype.load = function() {}; - CKEDITOR.fileTools.fileLoader.prototype.upload = function( url ) { + CKEDITOR.fileTools.fileLoader.prototype.upload = function() { uploadCount++; - lastUploadUrl = url; this.responseData = CKEDITOR.tools.clone( responseData ); }; @@ -142,7 +140,6 @@ assert.areSame( 1, loadAndUploadCount ); assert.areSame( 0, uploadCount ); - assert.areSame( 'http://foo/upload', lastUploadUrl ); } ); }, @@ -172,7 +169,6 @@ assert.areSame( 0, loadAndUploadCount ); assert.areSame( 1, uploadCount ); - assert.areSame( 'http://foo/upload', lastUploadUrl ); } ); } ); }, From e17fd70561db4f0afe45a0e093fc03bad844c31a Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Mon, 23 Oct 2017 12:37:24 +0200 Subject: [PATCH 06/14] Extracted common config. --- tests/plugins/easyimage/uploadwidget.js | 26 +++++++++---------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index fb6022d0cc2..be0bc96a98b 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -10,36 +10,28 @@ var uploadCount, loadAndUploadCount, resumeAfter, tests, IMG_URL = '%BASE_PATH%_assets/logo.png', DATA_IMG = 'data:', - BLOB_IMG = 'blob:'; + BLOB_IMG = 'blob:', + commonConfig = { + cloudServices_url: 'http://foo/upload', + // Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits). + pasteFilter: null + }; bender.editors = { classic: { name: 'classic', - config: { - cloudServices_url: 'http://foo/upload', - // Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits). - pasteFilter: null - } + config: commonConfig }, divarea: { name: 'divarea', - config: { - extraPlugins: 'divarea', - cloudServices_url: 'http://foo/upload', - // Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits). - pasteFilter: null - } + config: CKEDITOR.tools.extend( { extraPlugins: 'divarea' }, commonConfig ) }, inline: { name: 'inline', creator: 'inline', - config: { - cloudServices_url: 'http://foo/upload', - // Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits). - pasteFilter: null - } + config: commonConfig } }; From 318e3865acc7cc2d6f7e2e0cff5e7f642693e929 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Mon, 23 Oct 2017 14:03:25 +0200 Subject: [PATCH 07/14] Added some comments about easy image uploading unit tests. --- tests/plugins/easyimage/uploadwidget.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index be0bc96a98b..c0e2e5e0ba6 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -4,9 +4,9 @@ /* bender-include: %BASE_PATH%/plugins/uploadfile/_helpers/waitForImage.js */ /* global pasteFiles, waitForImage */ -'use strict'; - ( function() { + 'use strict'; + var uploadCount, loadAndUploadCount, resumeAfter, tests, IMG_URL = '%BASE_PATH%_assets/logo.png', DATA_IMG = 'data:', @@ -50,6 +50,8 @@ CKEDITOR.on( 'instanceCreated', function() { if ( !CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore ) { + // Because of #1068 we can't provide loaderType directly. Instead we just replace cloudServicesLoader + // with our loader stub that is going to be customized in init method. sinon.stub( CKEDITOR.plugins.cloudservices, 'cloudServicesLoader', CKEDITOR.fileTools.fileLoader ); } } ); @@ -66,6 +68,8 @@ resumeAfter = bender.tools.resumeAfter; + // This tests suite could be made much prettier, it would require #1068 to be resolved. Then you + // could just use LoaderStub type with stubbed methods, rather than overwrite base FileLoader type. CKEDITOR.fileTools.fileLoader.prototype.loadAndUpload = function() { loadAndUploadCount++; @@ -80,7 +84,8 @@ this.responseData = CKEDITOR.tools.clone( responseData ); }; - // Further hacking, now stub can be safely removed, as it's used only in plugin.init, which has already been called. + // Now stub can be safely removed, as it's used only in plugin.init, which has already been called, + // this workaround could be removed once #1068 is fixed. if ( CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore ) { CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore(); } From fb87b7f7e310c9f25f6363b2ca7f196779824004 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Mon, 23 Oct 2017 14:17:37 +0200 Subject: [PATCH 08/14] Simplified tests, by fixing #1068 issue in listener for easyimage (only). --- plugins/easyimage/plugin.js | 3 ++- tests/plugins/easyimage/uploadwidget.js | 23 ++++------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/plugins/easyimage/plugin.js b/plugins/easyimage/plugin.js index 6bbabc546d4..b52363b0e12 100644 --- a/plugins/easyimage/plugin.js +++ b/plugins/easyimage/plugin.js @@ -172,6 +172,7 @@ var data = evt.data, // Prevent XSS attacks. tempDoc = document.implementation.createHTMLDocument( '' ), + widgetDef = editor.widgets.registered.uploadeasyimage, temp = new CKEDITOR.dom.element( tempDoc.body ), imgs, img, i; @@ -191,7 +192,7 @@ // We are not uploading images in non-editable blocs and fake objects (http://dev.ckeditor.com/ticket/13003). if ( isDataInSrc && isRealObject && !img.data( 'cke-upload-id' ) && !img.isReadOnly( 1 ) ) { - var loader = editor.uploadRepository.create( img.getAttribute( 'src' ) ); + var loader = editor.uploadRepository.create( img.getAttribute( 'src' ), undefined, widgetDef.loaderType ); loader.upload(); fileTools.markElement( img, 'uploadeasyimage', loader.id ); diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index c0e2e5e0ba6..4a04d17b027 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -48,14 +48,6 @@ } } - CKEDITOR.on( 'instanceCreated', function() { - if ( !CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore ) { - // Because of #1068 we can't provide loaderType directly. Instead we just replace cloudServicesLoader - // with our loader stub that is going to be customized in init method. - sinon.stub( CKEDITOR.plugins.cloudservices, 'cloudServicesLoader', CKEDITOR.fileTools.fileLoader ); - } - } ); - tests = { init: function() { var responseData = { @@ -68,27 +60,20 @@ resumeAfter = bender.tools.resumeAfter; - // This tests suite could be made much prettier, it would require #1068 to be resolved. Then you - // could just use LoaderStub type with stubbed methods, rather than overwrite base FileLoader type. - CKEDITOR.fileTools.fileLoader.prototype.loadAndUpload = function() { + // Approach taken from tests/plugins/uploadwidget/uploadwidget.js test. + CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.loadAndUpload = function() { loadAndUploadCount++; this.responseData = CKEDITOR.tools.clone( responseData ); }; - CKEDITOR.fileTools.fileLoader.prototype.load = function() {}; + CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.load = function() {}; - CKEDITOR.fileTools.fileLoader.prototype.upload = function() { + CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.upload = function() { uploadCount++; this.responseData = CKEDITOR.tools.clone( responseData ); }; - - // Now stub can be safely removed, as it's used only in plugin.init, which has already been called, - // this workaround could be removed once #1068 is fixed. - if ( CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore ) { - CKEDITOR.plugins.cloudservices.cloudServicesLoader.restore(); - } }, setUp: function() { From 84cf8c49322c2fba34f00f020922026af56f1d0b Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Mon, 23 Oct 2017 14:36:01 +0200 Subject: [PATCH 09/14] Changed easyimage not to call load method (as it does it handles it manually better than default FileLoader type). --- plugins/easyimage/plugin.js | 3 ++- tests/plugins/easyimage/uploadwidget.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/easyimage/plugin.js b/plugins/easyimage/plugin.js index b52363b0e12..2d31ec65873 100644 --- a/plugins/easyimage/plugin.js +++ b/plugins/easyimage/plugin.js @@ -132,7 +132,8 @@ CKEDITOR.fileTools.addUploadWidget( editor, 'uploadeasyimage', { supportedTypes: /image\/(jpeg|png|gif|bmp)/, - loadMethod: 'loadAndUpload', + // Easy image uses only upload method, as is manually handled in onUploading function. + loadMethod: 'upload', loaderType: CKEDITOR.plugins.cloudservices.cloudServicesLoader, diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index 4a04d17b027..7c21c2e6fb7 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -120,8 +120,8 @@ assert.sameData( '

', editor.getData() ); assert.areSame( 1, editor.editable().find( 'img[data-widget="image"]' ).count() ); - assert.areSame( 1, loadAndUploadCount ); - assert.areSame( 0, uploadCount ); + assert.areSame( 0, loadAndUploadCount ); + assert.areSame( 1, uploadCount ); } ); }, From b128dd79df311beba722740b6a8ce00d09e8532d Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Mon, 23 Oct 2017 18:08:23 +0200 Subject: [PATCH 10/14] Allow upload URL to be configurable. Now it can be configured using widgetDefinition.uploadUrl (on uploadeasyimage widget). So one can use simply `widgetDefinition` event on editor to customize the upload URL if there's a need to. --- plugins/easyimage/plugin.js | 2 +- tests/plugins/easyimage/uploadwidget.js | 33 ++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/plugins/easyimage/plugin.js b/plugins/easyimage/plugin.js index 2d31ec65873..64912415033 100644 --- a/plugins/easyimage/plugin.js +++ b/plugins/easyimage/plugin.js @@ -194,7 +194,7 @@ // We are not uploading images in non-editable blocs and fake objects (http://dev.ckeditor.com/ticket/13003). if ( isDataInSrc && isRealObject && !img.data( 'cke-upload-id' ) && !img.isReadOnly( 1 ) ) { var loader = editor.uploadRepository.create( img.getAttribute( 'src' ), undefined, widgetDef.loaderType ); - loader.upload(); + loader.upload( widgetDef.uploadUrl, widgetDef.additionalRequestParameters ); fileTools.markElement( img, 'uploadeasyimage', loader.id ); diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index 7c21c2e6fb7..0d34a21f56f 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -69,11 +69,10 @@ CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.load = function() {}; - CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.upload = function() { + sinon.stub( CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype, 'upload', function() { uploadCount++; - this.responseData = CKEDITOR.tools.clone( responseData ); - }; + } ); }, setUp: function() { @@ -94,6 +93,10 @@ if ( CKEDITOR.fileTools.bindNotifications.reset ) { CKEDITOR.fileTools.bindNotifications.reset(); } + + if ( CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.upload.reset ) { + CKEDITOR.plugins.cloudservices.cloudServicesLoader.prototype.upload.reset(); + } }, 'test classic with easyimage (integration test)': function( editor ) { @@ -426,6 +429,30 @@ } ); } ); + wait(); + }, + + 'test cloudservices URL can be customized': function( editor ) { + var originalUploadUrl = editor.widgets.registered.uploadeasyimage.uploadUrl, + loader; + + // Upload widget might have an uploadUrl changed in definition, allowing for upload URL customization. + editor.widgets.registered.uploadeasyimage.uploadUrl = 'https://customDomain.localhost/endpoint'; + + resumeAfter( editor, 'paste', function() { + // Restore original value. + editor.widgets.registered.uploadeasyimage.uploadUrl = originalUploadUrl; + + loader = editor.uploadRepository.loaders[ 0 ]; + + sinon.assert.calledWith( loader.upload, 'https://customDomain.localhost/endpoint' ); + assert.isTrue( true ); + } ); + + editor.fire( 'paste', { + dataValue: '' + } ); + wait(); } }; From 77dd5c9609672843acbb07b427a9266e56ec9847 Mon Sep 17 00:00:00 2001 From: Tomasz Jakut Date: Tue, 24 Oct 2017 11:13:58 +0200 Subject: [PATCH 11/14] Fix codestyle issue. --- tests/plugins/easyimage/uploadwidget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index 0d34a21f56f..c11bcad431a 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -53,11 +53,11 @@ var responseData = { response: { 100: IMG_URL, - 200: IMG_URL, - default: IMG_URL + 200: IMG_URL } }; + responseData.response[ 'default' ] = IMG_URL; resumeAfter = bender.tools.resumeAfter; // Approach taken from tests/plugins/uploadwidget/uploadwidget.js test. From 8d29a11cfa171aa1c279bad483bc2ab3e6324690 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Tue, 24 Oct 2017 17:27:05 +0200 Subject: [PATCH 12/14] Fixed an issue where Firefox would cause multiple img load events for a single image. --- tests/plugins/uploadfile/_helpers/waitForImage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/uploadfile/_helpers/waitForImage.js b/tests/plugins/uploadfile/_helpers/waitForImage.js index e6b566222b6..1a8dbc55c6a 100644 --- a/tests/plugins/uploadfile/_helpers/waitForImage.js +++ b/tests/plugins/uploadfile/_helpers/waitForImage.js @@ -5,7 +5,7 @@ function waitForImage( image, callback ) { if ( CKEDITOR.env.ie ) { wait( callback, 100 ); } else { - image.on( 'load', function() { + image.once( 'load', function() { resume( callback ); } ); wait(); From a574cd9bf0a5d2c4d31ea06da4f5547de4feaeab Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Tue, 24 Oct 2017 17:37:03 +0200 Subject: [PATCH 13/14] Added test cases for Easy Image loader / HTTP request params customization. --- tests/plugins/easyimage/uploadwidget.js | 45 ++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index c11bcad431a..f3034d38e1f 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -432,20 +432,24 @@ wait(); }, - 'test cloudservices URL can be customized': function( editor ) { - var originalUploadUrl = editor.widgets.registered.uploadeasyimage.uploadUrl, + 'test cloudservices URL/request params can be customized': function( editor ) { + var uploadEasyImageDef = editor.widgets.registered.uploadeasyimage, + originalUploadUrl = uploadEasyImageDef.uploadUrl, + originalAdditionalParams = uploadEasyImageDef.additionalRequestParameters, loader; // Upload widget might have an uploadUrl changed in definition, allowing for upload URL customization. - editor.widgets.registered.uploadeasyimage.uploadUrl = 'https://customDomain.localhost/endpoint'; + uploadEasyImageDef.uploadUrl = 'https://customDomain.localhost/endpoint'; + uploadEasyImageDef.additionalRequestParameters = { a: 1 }; resumeAfter( editor, 'paste', function() { // Restore original value. - editor.widgets.registered.uploadeasyimage.uploadUrl = originalUploadUrl; + uploadEasyImageDef.uploadUrl = originalUploadUrl; + uploadEasyImageDef.additionalRequestParameters = originalAdditionalParams; loader = editor.uploadRepository.loaders[ 0 ]; - sinon.assert.calledWith( loader.upload, 'https://customDomain.localhost/endpoint' ); + sinon.assert.calledWith( loader.upload, 'https://customDomain.localhost/endpoint', { a: 1 } ); assert.isTrue( true ); } ); @@ -453,6 +457,37 @@ dataValue: '' } ); + wait(); + }, + + 'test loader type can be customized': function( editor ) { + var uploadEasyImageDef = editor.widgets.registered.uploadeasyimage, + originalType = uploadEasyImageDef.loaderType, + CloudServicesLoader = CKEDITOR.plugins.cloudservices.cloudServicesLoader, + loader; + + function LoaderSubclass( editor, fileOrData, fileName, token ) { + CloudServicesLoader.call( this, editor, fileOrData, fileName, token ); + } + + LoaderSubclass.prototype = CKEDITOR.tools.extend( {}, CloudServicesLoader.prototype ); + + // Upload widget might have an uploadUrl changed in definition, allowing for upload URL customization. + uploadEasyImageDef.loaderType = LoaderSubclass; + + resumeAfter( editor, 'paste', function() { + // Restore original value. + uploadEasyImageDef.loaderType = originalType; + + loader = editor.uploadRepository.loaders[ 0 ]; + + assert.isInstanceOf( LoaderSubclass, loader, 'Loader type' ); + } ); + + editor.fire( 'paste', { + dataValue: '' + } ); + wait(); } }; From 34befd8a2cf0a2a2d9cab0acc4fd5b990eeb5286 Mon Sep 17 00:00:00 2001 From: Tomasz Jakut Date: Wed, 25 Oct 2017 11:18:37 +0200 Subject: [PATCH 14/14] Fix incorrect comment. --- tests/plugins/easyimage/uploadwidget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/easyimage/uploadwidget.js b/tests/plugins/easyimage/uploadwidget.js index f3034d38e1f..90de5cfa138 100644 --- a/tests/plugins/easyimage/uploadwidget.js +++ b/tests/plugins/easyimage/uploadwidget.js @@ -472,7 +472,7 @@ LoaderSubclass.prototype = CKEDITOR.tools.extend( {}, CloudServicesLoader.prototype ); - // Upload widget might have an uploadUrl changed in definition, allowing for upload URL customization. + // Upload widget might have a loaderType changed in definition, allowing for loader type customization. uploadEasyImageDef.loaderType = LoaderSubclass; resumeAfter( editor, 'paste', function() {