diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 5d2a3cc4d7429..be54b7c95eb28 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -34,7 +34,12 @@ OC.FileUpload = function(uploader, data) { this.uploader = uploader; this.data = data; - var path = OC.joinPaths(this.uploader.fileList.getCurrentDirectory(), this.getFile().name); + var path = ''; + if (this.uploader.fileList) { + path = OC.joinPaths(this.uploader.fileList.getCurrentDirectory(), this.getFile().name); + } else { + path = this.getFile().name; + } this.id = 'web-file-upload-' + md5(path) + '-' + (new Date()).getTime(); }; OC.FileUpload.CONFLICT_MODE_DETECT = 0; @@ -364,6 +369,9 @@ OC.Uploader.prototype = _.extend({ * also see article @link http://blog.new-bamboo.co.uk/2012/01/10/ridiculously-simple-ajax-uploads-with-formdata */ _supportAjaxUploadWithProgress: function() { + if (window.TESTING) { + return true; + } return supportFileAPI() && supportAjaxUploadProgressEvents() && supportFormData(); // Is the File API supported? @@ -719,7 +727,6 @@ OC.Uploader.prototype = _.extend({ dropZone: options.dropZone, // restrict dropZone to content div autoUpload: false, sequentialUploads: true, - maxChunkSize: 10000000, //singleFileUploads is on by default, so the data.files array will always have length 1 /** * on first add of every selection @@ -920,7 +927,10 @@ OC.Uploader.prototype = _.extend({ // HTTP connection problem or other error OC.Notification.showTemporary(data.errorThrown, {timeout: 10}); } - upload.deleteUpload(); + + if (upload) { + upload.deleteUpload(); + } }, /** * called for every successful upload diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 2d6bca80f1ab1..d4a223058b45f 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -2724,16 +2724,16 @@ // add target dir data.targetDir = dir; } else { - // we are dropping somewhere inside the file list, which will - // upload the file to the current directory - data.targetDir = self.getCurrentDirectory(); - // cancel uploads to current dir if no permission var isCreatable = (self.getDirectoryPermissions() & OC.PERMISSION_CREATE) !== 0; if (!isCreatable) { self._showPermissionDeniedNotification(); return false; } + + // we are dropping somewhere inside the file list, which will + // upload the file to the current directory + data.targetDir = self.getCurrentDirectory(); } }); uploader.on('add', function(e, data) { diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js index bfaf0a9fe57b0..19f8cde7e4423 100644 --- a/apps/files/tests/js/fileUploadSpec.js +++ b/apps/files/tests/js/fileUploadSpec.js @@ -48,7 +48,7 @@ describe('OC.Upload tests', function() { $dummyUploader = $('#file_upload_start'); uploader = new OC.Uploader($dummyUploader); failStub = sinon.stub(); - $dummyUploader.on('fileuploadfail', failStub); + uploader.on('fail', failStub); }); afterEach(function() { $dummyUploader = undefined; diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index 55ab2c535af13..2064f570ca2e6 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -2564,15 +2564,12 @@ describe('OCA.Files.FileList tests', function() { * that were registered on the magic upload object */ describe('file upload', function() { - var $uploader; var uploadData; + var uploader; beforeEach(function() { - // note: this isn't the real blueimp file uploader from jquery.fileupload - // but it makes it possible to simulate the event triggering to - // test the response of the handlers - $uploader = $('#file_upload_start'); fileList.setFiles(testFiles); + uploader = fileList._uploader; // simulate data structure from jquery.upload uploadData = { files: [{ @@ -2582,7 +2579,7 @@ describe('OCA.Files.FileList tests', function() { }); afterEach(function() { - $uploader = null; + uploader = null; uploadData = null; }); @@ -2606,11 +2603,7 @@ describe('OCA.Files.FileList tests', function() { * @return event object including the result */ function addFile(data) { - var ev = new $.Event('fileuploadadd', {}); - // using triggerHandler instead of trigger so we can pass - // extra data - $uploader.triggerHandler(ev, data || {}); - return ev; + uploader.trigger('add', {}, data || {}); } it('sets target dir to the current directory', function() { @@ -2632,9 +2625,8 @@ describe('OCA.Files.FileList tests', function() { target: $target } }; - var ev = new $.Event('fileuploaddrop', eventData); - $uploader.trigger(ev, data || {}); - return ev; + uploader.trigger('drop', eventData, data || {}); + return !!data.targetDir; } it('drop on a tr or crumb outside file list does not trigger upload', function() { @@ -2642,62 +2634,62 @@ describe('OCA.Files.FileList tests', function() { var ev; $('#testArea').append($anotherTable); ev = dropOn($anotherTable.find('tr'), uploadData); - expect(ev.result).toEqual(false); + expect(ev).toEqual(false); - ev = dropOn($anotherTable.find('.crumb')); - expect(ev.result).toEqual(false); + ev = dropOn($anotherTable.find('.crumb'), uploadData); + expect(ev).toEqual(false); }); it('drop on an element outside file list container does not trigger upload', function() { var $anotherEl = $('