summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-02 10:13:58 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-11-02 10:13:58 +0100
commit01adefaf509840cfa7212b654e69a1d291228a5e (patch)
tree91375b98bd5dcaad9e199de55f89c55c37882928 /apps
parentb6ca23afe13304f904811d510a8e843a4ea832e9 (diff)
parent80cf4e84e32f09838e9f9e362568f02642ef7658 (diff)
downloadnextcloud-server-01adefaf509840cfa7212b654e69a1d291228a5e.tar.gz
nextcloud-server-01adefaf509840cfa7212b654e69a1d291228a5e.zip
Merge pull request #20181 from owncloud/files-fixdownloadspinner
Fix file action download spinner
Diffstat (limited to 'apps')
-rw-r--r--apps/files/js/fileactions.js2
-rw-r--r--apps/files/js/files.js7
-rw-r--r--apps/files/tests/js/fileactionsSpec.js43
-rw-r--r--apps/files/tests/js/filesSpec.js52
4 files changed, 101 insertions, 3 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 079c5330ec2..6a767d48a28 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -589,7 +589,7 @@
context.fileList.showFileBusyState(filename, false);
};
- context.fileList.showFileBusyState(downloadFileaction, true);
+ context.fileList.showFileBusyState(filename, true);
OCA.Files.Files.handleDownload(url, disableLoadingState);
}
}
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 9ab7609cc40..ae38511ec05 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -295,7 +295,12 @@
}
};
- OC.redirect(url + '&downloadStartSecret=' + randomToken);
+ if (url.indexOf('?') >= 0) {
+ url += '&';
+ } else {
+ url += '?';
+ }
+ OC.redirect(url + 'downloadStartSecret=' + randomToken);
OC.Util.waitFor(checkForDownloadCookie, 500);
}
};
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js
index 6a57c56c3af..d29164c5136 100644
--- a/apps/files/tests/js/fileactionsSpec.js
+++ b/apps/files/tests/js/fileactionsSpec.js
@@ -227,7 +227,7 @@ describe('OCA.Files.FileActions tests', function() {
name: 'Test',
type: OCA.Files.FileActions.TYPE_INLINE,
mime: 'all',
- icon: OC.imagePath('core', 'actions/test'),
+ icon: OC.imagePath('core', 'actions/test'),
permissions: OC.PERMISSION_READ,
actionHandler: actionStub
});
@@ -556,4 +556,45 @@ describe('OCA.Files.FileActions tests', function() {
expect(handler.notCalled).toEqual(true);
});
});
+ describe('default actions', function() {
+ describe('download', function() {
+ it('redirects to URL and sets busy state to list', function() {
+ var handleDownloadStub = sinon.stub(OCA.Files.Files, 'handleDownload');
+ var busyStub = sinon.stub(fileList, 'showFileBusyState');
+ var fileData = {
+ id: 18,
+ type: 'file',
+ name: 'testName.txt',
+ mimetype: 'text/plain',
+ size: '1234',
+ etag: 'a01234c',
+ mtime: '123456',
+ permissions: OC.PERMISSION_READ | OC.PERMISSION_UPDATE
+ };
+
+ // note: FileActions.display() is called implicitly
+ fileList.add(fileData);
+
+ var model = fileList.getModelForFile('testName.txt');
+
+ fileActions.registerDefaultActions();
+ fileActions.triggerAction('Download', model, fileList);
+
+ expect(busyStub.calledOnce).toEqual(true);
+ expect(busyStub.calledWith('testName.txt', true)).toEqual(true);
+ expect(handleDownloadStub.calledOnce).toEqual(true);
+ expect(handleDownloadStub.getCall(0).args[0]).toEqual(
+ OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=testName.txt'
+ );
+ busyStub.reset();
+ handleDownloadStub.yield();
+
+ expect(busyStub.calledOnce).toEqual(true);
+ expect(busyStub.calledWith('testName.txt', false)).toEqual(true);
+
+ busyStub.restore();
+ handleDownloadStub.restore();
+ });
+ });
+ });
});
diff --git a/apps/files/tests/js/filesSpec.js b/apps/files/tests/js/filesSpec.js
index f20ba03e2f1..30e6675c155 100644
--- a/apps/files/tests/js/filesSpec.js
+++ b/apps/files/tests/js/filesSpec.js
@@ -87,4 +87,56 @@ describe('OCA.Files.Files tests', function() {
expect(url).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=%5B%22test%20file.txt%22%2C%22abc.txt%22%5D');
});
});
+ describe('handleDownload', function() {
+ var redirectStub;
+ var cookieStub;
+ var clock;
+ var testUrl;
+
+ beforeEach(function() {
+ testUrl = 'http://example.com/owncloud/path/download.php';
+ redirectStub = sinon.stub(OC, 'redirect');
+ cookieStub = sinon.stub(OC.Util, 'isCookieSetToValue');
+ clock = sinon.useFakeTimers();
+ });
+ afterEach(function() {
+ redirectStub.restore();
+ cookieStub.restore();
+ clock.restore();
+ });
+
+ it('appends secret to url when no existing parameters', function() {
+ Files.handleDownload(testUrl);
+ expect(redirectStub.calledOnce).toEqual(true);
+ expect(redirectStub.getCall(0).args[0]).toContain(testUrl + '?downloadStartSecret=');
+ });
+ it('appends secret to url with existing parameters', function() {
+ Files.handleDownload(testUrl + '?test=1');
+ expect(redirectStub.calledOnce).toEqual(true);
+ expect(redirectStub.getCall(0).args[0]).toContain(testUrl + '?test=1&downloadStartSecret=');
+ });
+ it('sets cookie and calls callback when cookie appears', function() {
+ var callbackStub = sinon.stub();
+ var token;
+ Files.handleDownload(testUrl, callbackStub);
+ expect(redirectStub.calledOnce).toEqual(true);
+ token = OC.parseQueryString(redirectStub.getCall(0).args[0]).downloadStartSecret;
+ expect(token).toBeDefined();
+
+ expect(cookieStub.calledOnce).toEqual(true);
+ cookieStub.returns(false);
+ clock.tick(600);
+
+ expect(cookieStub.calledTwice).toEqual(true);
+ expect(cookieStub.getCall(1).args[0]).toEqual('ocDownloadStarted');
+ expect(cookieStub.getCall(1).args[1]).toEqual(token);
+ expect(callbackStub.notCalled).toEqual(true);
+
+ cookieStub.returns(true);
+ clock.tick(2000);
+
+ expect(cookieStub.callCount).toEqual(3);
+ expect(callbackStub.calledOnce).toEqual(true);
+ });
+ });
});