Browse Source

updated tests
Upload:
- obey LOCAL_BEHAVIOUR_COPY
- correct storage path for encrypted files in subdirectories

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

tobiasKaminsky 4 years ago
parent
commit
7f339f9fe0

+ 164 - 2
src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java

@@ -28,20 +28,24 @@ import com.owncloud.android.AbstractOnServerIT;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.db.OCUpload;
+import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.accounts.AccountUtils;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation;
+import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
 import com.owncloud.android.lib.resources.status.OCCapability;
 import com.owncloud.android.lib.resources.status.OwnCloudVersion;
 import com.owncloud.android.lib.resources.users.GetPrivateKeyOperation;
 import com.owncloud.android.lib.resources.users.GetPublicKeyOperation;
 import com.owncloud.android.lib.resources.users.SendCSROperation;
 import com.owncloud.android.lib.resources.users.StorePrivateKeyOperation;
+import com.owncloud.android.operations.DownloadFileOperation;
 import com.owncloud.android.operations.GetCapabilitiesOperation;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.utils.CsrHelper;
 import com.owncloud.android.utils.EncryptionUtils;
+import com.owncloud.android.utils.FileStorageUtils;
 
 import net.bytebuddy.utility.RandomString;
 
@@ -59,6 +63,7 @@ import java.util.Random;
 
 import static com.owncloud.android.lib.resources.status.OwnCloudVersion.nextcloud_19;
 import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertFalse;
 import static junit.framework.TestCase.assertNotNull;
 import static junit.framework.TestCase.assertTrue;
 import static org.junit.Assume.assumeTrue;
@@ -68,7 +73,9 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
         CREATE_FOLDER,
         GO_INTO_FOLDER,
         GO_UP,
-        UPLOAD_FILE
+        UPLOAD_FILE,
+        DOWNLOAD_FILE,
+        DELETE_FILE,
     }
 
     private static ArbitraryDataProvider arbitraryDataProvider;
@@ -83,7 +90,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
     }
 
     @Before
-    public void before() {
+    public void before() throws IOException {
         OCCapability capability = getStorageManager().getCapability(account.name);
 
         if (capability.getVersion().equals(new OwnCloudVersion("0.0.0"))) {
@@ -97,6 +104,8 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
                        .isNewerOrEqual(nextcloud_19)
                   );
 
+        // make sure that every file is available, even after tests that remove source file
+        createDummyFiles();
     }
 
     @Test
@@ -123,6 +132,14 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
                     uploadFile(i);
                     break;
 
+                case DOWNLOAD_FILE:
+                    downloadFile(i);
+                    break;
+
+                case DELETE_FILE:
+                    deleteFile(i);
+                    break;
+
                 default:
                     Log_OC.d(this, "[" + i + "/" + actionCount + "]" + " Unknown action: " + nextAction);
                     break;
@@ -208,6 +225,14 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
         deleteFile(1);
     }
 
+    @Test
+    public void downloadFile() throws Exception {
+        init();
+
+        uploadFile(1);
+        downloadFile(1);
+    }
+
     private void init() throws Exception {
         // create folder
         createFolder(rootEncFolder);
@@ -288,6 +313,131 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
                                          remotePath,
                                          account.name);
         uploadOCUpload(ocUpload);
+        shortSleep();
+
+        OCFile parentFolder = getStorageManager()
+            .getFileByEncryptedRemotePath(new File(ocUpload.getRemotePath()).getParent() + "/");
+        String uploadedFileName = new File(ocUpload.getRemotePath()).getName();
+
+        String decryptedPath = parentFolder.getDecryptedRemotePath() + uploadedFileName;
+
+        OCFile uploadedFile = getStorageManager().getFileByDecryptedRemotePath(decryptedPath);
+        verifyStoragePath(uploadedFile);
+
+        // verify storage path
+        refreshFolder(currentFolder.getRemotePath());
+        uploadedFile = getStorageManager().getFileByDecryptedRemotePath(decryptedPath);
+        verifyStoragePath(uploadedFile);
+
+        // verify that encrypted file is on server
+        assertTrue(new ReadFileRemoteOperation(currentFolder.getRemotePath() + uploadedFile.getEncryptedFileName())
+                       .execute(client)
+                       .isSuccess());
+
+        // verify that unencrypted file is not on server
+        assertFalse(new ReadFileRemoteOperation(currentFolder.getDecryptedRemotePath() + fileName)
+                        .execute(client)
+                        .isSuccess());
+    }
+
+    private void downloadFile(int i) {
+        ArrayList<OCFile> files = new ArrayList<>();
+        for (OCFile file : getStorageManager().getFolderContent(currentFolder, false)) {
+            if (!file.isFolder()) {
+                files.add(file);
+            }
+        }
+
+        if (files.isEmpty()) {
+            Log_OC.d(this, "[" + i + "/" + actionCount + "] No files in: " + currentFolder.getDecryptedRemotePath());
+            return;
+        }
+
+        OCFile fileToDownload = files.get(new Random().nextInt(files.size()));
+        assertNotNull(fileToDownload.getRemoteId());
+
+        Log_OC.d(this,
+                 "[" + i + "/" + actionCount + "] " + "Download file: " +
+                     currentFolder.getDecryptedRemotePath() + fileToDownload.getDecryptedFileName());
+
+        assertTrue(new DownloadFileOperation(account, fileToDownload, targetContext)
+                       .execute(client)
+                       .isSuccess());
+
+        assertTrue(new File(fileToDownload.getStoragePath()).exists());
+        verifyStoragePath(fileToDownload);
+    }
+
+    @Test
+    public void testUploadWithCopy() throws Exception {
+        init();
+
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         currentFolder.getRemotePath() + "nonEmpty.txt",
+                                         account.name);
+
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_COPY);
+
+        File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
+        OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() +
+                                                                                      "nonEmpty.txt");
+
+        assertTrue(originalFile.exists());
+        assertTrue(new File(uploadedFile.getStoragePath()).exists());
+    }
+
+    @Test
+    public void testUploadWithMove() throws Exception {
+        init();
+
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         currentFolder.getRemotePath() + "nonEmpty.txt",
+                                         account.name);
+
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_MOVE);
+
+        File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
+        OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() +
+                                                                                      "nonEmpty.txt");
+
+        assertFalse(originalFile.exists());
+        assertTrue(new File(uploadedFile.getStoragePath()).exists());
+    }
+
+    @Test
+    public void testUploadWithForget() throws Exception {
+        init();
+
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         currentFolder.getRemotePath() + "nonEmpty.txt",
+                                         account.name);
+
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_FORGET);
+
+        File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
+        OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() +
+                                                                                      "nonEmpty.txt");
+
+        assertTrue(originalFile.exists());
+        assertFalse(new File(uploadedFile.getStoragePath()).exists());
+    }
+
+    @Test
+    public void testUploadWithDelete() throws Exception {
+        init();
+
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         currentFolder.getRemotePath() + "nonEmpty.txt",
+                                         account.name);
+
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_DELETE);
+
+        File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
+        OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() +
+                                                                                      "nonEmpty.txt");
+
+        assertFalse(originalFile.exists());
+        assertFalse(new File(uploadedFile.getStoragePath()).exists());
     }
 
     private void deleteFile(int i) {
@@ -298,6 +448,11 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
             }
         }
 
+        if (files.isEmpty()) {
+            Log_OC.d(this, "[" + i + "/" + actionCount + "] No files in: " + currentFolder.getDecryptedRemotePath());
+            return;
+        }
+
         OCFile fileToDelete = files.get(new Random().nextInt(files.size()));
         assertNotNull(fileToDelete.getRemoteId());
 
@@ -467,4 +622,11 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
 
         Log_OC.d(this, "Finished removing content of folder: " + folder.getDecryptedRemotePath());
     }
+
+    private void verifyStoragePath(OCFile file) {
+        assertEquals(FileStorageUtils.getSavePath(account.name) +
+                         currentFolder.getDecryptedRemotePath() +
+                         file.getDecryptedFileName(),
+                     file.getStoragePath());
+    }
 }

+ 1 - 1
src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -186,7 +186,7 @@ public abstract class AbstractIT {
     }
 
     public static File createFile(String name, int iteration) throws IOException {
-        File file = new File(FileStorageUtils.getSavePath(account.name) + File.separator + name);
+        File file = new File(FileStorageUtils.getTemporalPath(account.name) + File.separator + name);
         file.createNewFile();
 
         FileWriter writer = new FileWriter(file);

+ 27 - 8
src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java

@@ -16,6 +16,7 @@ import com.nextcloud.client.device.PowerManagementService;
 import com.nextcloud.client.network.Connectivity;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.java.util.Optional;
+import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.db.OCUpload;
 import com.owncloud.android.files.services.FileUploader;
@@ -43,6 +44,7 @@ import java.io.IOException;
 import androidx.annotation.NonNull;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 
@@ -139,8 +141,13 @@ public abstract class AbstractOnServerIT extends AbstractIT {
         }
     }
 
-    private static void createDummyFiles() throws IOException {
-        new File(FileStorageUtils.getSavePath(account.name)).mkdirs();
+    protected static void createDummyFiles() throws IOException {
+        File tempPath = new File(FileStorageUtils.getTemporalPath(account.name));
+        if (!tempPath.exists()) {
+            assertTrue(tempPath.mkdirs());
+        }
+
+        assertTrue(tempPath.exists());
 
         createFile("empty.txt", 0);
         createFile("nonEmpty.txt", 100);
@@ -170,6 +177,10 @@ public abstract class AbstractOnServerIT extends AbstractIT {
     }
 
     public void uploadOCUpload(OCUpload ocUpload) {
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_COPY);
+    }
+
+    public void uploadOCUpload(OCUpload ocUpload, int localBehaviour) {
         ConnectivityService connectivityServiceMock = new ConnectivityService() {
             @Override
             public boolean isInternetWalled() {
@@ -212,7 +223,7 @@ public abstract class AbstractOnServerIT extends AbstractIT {
             null,
             ocUpload,
             FileUploader.NameCollisionPolicy.DEFAULT,
-            FileUploader.LOCAL_BEHAVIOUR_COPY,
+            localBehaviour,
             targetContext,
             false,
             false
@@ -225,11 +236,19 @@ public abstract class AbstractOnServerIT extends AbstractIT {
 
         RemoteOperationResult result = newUpload.execute(client, getStorageManager());
         assertTrue(result.getLogMessage(), result.isSuccess());
-//
-//        shortSleep();
-//        shortSleep();
-//
-//        assertNotNull(getStorageManager().getFileByDecryptedRemotePath(ocUpload.getRemotePath()).getRemoteId());
+
+        OCFile parentFolder = getStorageManager()
+            .getFileByEncryptedRemotePath(new File(ocUpload.getRemotePath()).getParent() + "/");
+        String uploadedFileName = new File(ocUpload.getRemotePath()).getName();
+        OCFile uploadedFile = getStorageManager().
+            getFileByDecryptedRemotePath(parentFolder.getDecryptedRemotePath() + uploadedFileName);
+
+        assertNotNull(uploadedFile.getRemoteId());
+
+        if (localBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY ||
+            localBehaviour == FileUploader.LOCAL_BEHAVIOUR_MOVE) {
+            assertTrue(new File(uploadedFile.getStoragePath()).exists());
+        }
     }
 
     protected void refreshFolder(String path) {

+ 121 - 0
src/androidTest/java/com/owncloud/android/DownloadIT.java

@@ -0,0 +1,121 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2020 Tobias Kaminsky
+ * Copyright (C) 2020 Nextcloud GmbH
+ * Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.owncloud.android;
+
+import android.net.Uri;
+
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.db.OCUpload;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.operations.DownloadFileOperation;
+import com.owncloud.android.operations.RefreshFolderOperation;
+import com.owncloud.android.operations.RemoveFileOperation;
+import com.owncloud.android.utils.FileStorageUtils;
+
+import org.junit.After;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests related to file uploads
+ */
+
+public class DownloadIT extends AbstractOnServerIT {
+    private static final String FOLDER = "/testUpload/";
+
+    @After
+    public void after() {
+        RemoteOperationResult result = new RefreshFolderOperation(getStorageManager().getFileByPath("/"),
+                                                                  System.currentTimeMillis() / 1000L,
+                                                                  false,
+                                                                  true,
+                                                                  getStorageManager(),
+                                                                  account,
+                                                                  targetContext)
+            .execute(client);
+
+        // cleanup only if folder exists
+        if (result.isSuccess() && getStorageManager().getFileByDecryptedRemotePath(FOLDER) != null) {
+            new RemoveFileOperation(getStorageManager().getFileByDecryptedRemotePath(FOLDER),
+                                    false,
+                                    account,
+                                    false,
+                                    targetContext)
+                .execute(client, getStorageManager());
+        }
+    }
+
+    @Test
+    public void verifyDownload() {
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         FOLDER + "nonEmpty.txt",
+                                         account.name);
+
+        uploadOCUpload(ocUpload);
+
+        OCUpload ocUpload2 = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                          FOLDER + "nonEmpty2.txt",
+                                          account.name);
+
+        uploadOCUpload(ocUpload2);
+
+        refreshFolder("/");
+        refreshFolder(FOLDER);
+
+        OCFile file1 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
+        OCFile file2 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty2.txt");
+        verifyDownload(file1, file2);
+
+        assertTrue(new DownloadFileOperation(account, file1, targetContext).execute(client).isSuccess());
+        assertTrue(new DownloadFileOperation(account, file2, targetContext).execute(client).isSuccess());
+
+        refreshFolder(FOLDER);
+
+        file1 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
+        file2 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty2.txt");
+
+        verifyDownload(file1, file2);
+    }
+
+    private void verifyDownload(OCFile file1, OCFile file2) {
+        assertNotNull(file1);
+        assertNotNull(file2);
+        assertNotSame(file1.getStoragePath(), file2.getStoragePath());
+
+        assertTrue(new File(file1.getStoragePath()).exists());
+        assertTrue(new File(file2.getStoragePath()).exists());
+
+        // test against hardcoded path to make sure that it is correct
+        assertEquals("/storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/" +
+                         Uri.encode(account.name, "@") + "/testUpload/nonEmpty.txt",
+                     file1.getStoragePath());
+        assertEquals("/storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/" +
+                         Uri.encode(account.name, "@") + "/testUpload/nonEmpty2.txt",
+                     file2.getStoragePath());
+    }
+}

+ 88 - 30
src/androidTest/java/com/owncloud/android/UploadIT.java

@@ -26,6 +26,7 @@ import com.nextcloud.client.device.BatteryStatus;
 import com.nextcloud.client.device.PowerManagementService;
 import com.nextcloud.client.network.Connectivity;
 import com.nextcloud.client.network.ConnectivityService;
+import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.db.OCUpload;
 import com.owncloud.android.files.services.FileUploader;
@@ -36,10 +37,15 @@ import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.utils.FileStorageUtils;
 
 import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
+import java.io.File;
+import java.io.IOException;
+
 import androidx.annotation.NonNull;
 
+import static junit.framework.TestCase.assertEquals;
 import static junit.framework.TestCase.assertFalse;
 import static junit.framework.TestCase.assertTrue;
 
@@ -84,6 +90,12 @@ public class UploadIT extends AbstractOnServerIT {
         }
     };
 
+    @Before
+    public void before() throws IOException {
+        // make sure that every file is available, even after tests that remove source file
+        createDummyFiles();
+    }
+
     @After
     public void after() {
         RemoteOperationResult result = new RefreshFolderOperation(getStorageManager().getFileByPath("/"),
@@ -108,7 +120,7 @@ public class UploadIT extends AbstractOnServerIT {
 
     @Test
     public void testEmptyUpload() {
-        OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
                                          FOLDER + "empty.txt",
                                          account.name);
 
@@ -117,7 +129,7 @@ public class UploadIT extends AbstractOnServerIT {
 
     @Test
     public void testNonEmptyUpload() {
-        OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
                                          FOLDER + "nonEmpty.txt",
                                          account.name);
 
@@ -125,46 +137,87 @@ public class UploadIT extends AbstractOnServerIT {
     }
 
     @Test
-    public void testChunkedUpload() {
-        OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/chunkedFile.txt",
-                                         FOLDER + "chunkedFile.txt", account.name);
+    public void testUploadWithCopy() {
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         FOLDER + "nonEmpty.txt",
+                                         account.name);
 
-        uploadOCUpload(ocUpload);
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_COPY);
+
+        File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
+        OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
+
+        assertTrue(originalFile.exists());
+        assertTrue(new File(uploadedFile.getStoragePath()).exists());
+        verifyStoragePath(uploadedFile);
     }
 
-    public RemoteOperationResult testUpload(OCUpload ocUpload) {
-        UploadFileOperation newUpload = new UploadFileOperation(
-            uploadsStorageManager,
-            connectivityServiceMock,
-            powerManagementServiceMock,
-            user,
-            null,
-            ocUpload,
-            FileUploader.NameCollisionPolicy.DEFAULT,
-            FileUploader.LOCAL_BEHAVIOUR_COPY,
-            targetContext,
-            false,
-            false
-        );
-        newUpload.addRenameUploadListener(() -> {
-            // dummy
-        });
+    @Test
+    public void testUploadWithMove() {
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         FOLDER + "nonEmpty.txt",
+                                         account.name);
 
-        newUpload.setRemoteFolderToBeCreated();
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_MOVE);
+
+        File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
+        OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
+
+        assertFalse(originalFile.exists());
+        assertTrue(new File(uploadedFile.getStoragePath()).exists());
+        verifyStoragePath(uploadedFile);
+    }
+
+    @Test
+    public void testUploadWithForget() {
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         FOLDER + "nonEmpty.txt",
+                                         account.name);
+
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_FORGET);
+
+        File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
+        OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
+
+        assertTrue(originalFile.exists());
+        assertFalse(new File(uploadedFile.getStoragePath()).exists());
+        assertTrue(uploadedFile.getStoragePath().isEmpty());
+    }
+
+    @Test
+    public void testUploadWithDelete() {
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
+                                         FOLDER + "nonEmpty.txt",
+                                         account.name);
+
+        uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_DELETE);
+
+        File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
+        OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
+
+        assertFalse(originalFile.exists());
+        assertFalse(new File(uploadedFile.getStoragePath()).exists());
+        assertTrue(uploadedFile.getStoragePath().isEmpty());
+    }
 
-        return newUpload.execute(client, getStorageManager());
+    @Test
+    public void testChunkedUpload() {
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/chunkedFile.txt",
+                                         FOLDER + "chunkedFile.txt", account.name);
+
+        uploadOCUpload(ocUpload);
     }
 
     @Test
     public void testUploadInNonExistingFolder() {
-        OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
                                          FOLDER + "2/3/4/1.txt", account.name);
 
         uploadOCUpload(ocUpload);
     }
     @Test
     public void testUploadOnChargingOnlyButNotCharging() {
-        OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
                                          FOLDER + "notCharging.txt", account.name);
         ocUpload.setWhileChargingOnly(true);
 
@@ -210,7 +263,7 @@ public class UploadIT extends AbstractOnServerIT {
             }
         };
 
-        OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
                                          FOLDER + "charging.txt", account.name);
         ocUpload.setWhileChargingOnly(true);
 
@@ -249,7 +302,7 @@ public class UploadIT extends AbstractOnServerIT {
                 return new Connectivity(true, false, false, true);
             }
         };
-        OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
                                          FOLDER + "noWifi.txt", account.name);
         ocUpload.setUseWifiOnly(true);
 
@@ -277,7 +330,7 @@ public class UploadIT extends AbstractOnServerIT {
 
     @Test
     public void testUploadOnWifiOnlyAndWifi() {
-        OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
+        OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
                                          FOLDER + "wifi.txt", account.name);
         ocUpload.setWhileChargingOnly(true);
 
@@ -310,4 +363,9 @@ public class UploadIT extends AbstractOnServerIT {
                                 targetContext)
             .execute(client, getStorageManager());
     }
+
+    private void verifyStoragePath(OCFile file) {
+        assertEquals(FileStorageUtils.getSavePath(account.name) + FOLDER + file.getDecryptedFileName(),
+                     file.getStoragePath());
+    }
 }

+ 16 - 3
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -475,6 +475,7 @@ public class UploadFileOperation extends SyncOperation {
                 return collisionResult;
             }
 
+            mFile.setDecryptedRemotePath(parentFile.getDecryptedRemotePath() + originalFile.getName());
             String expectedPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), mFile);
             expectedFile = new File(expectedPath);
 
@@ -794,10 +795,14 @@ public class UploadFileOperation extends SyncOperation {
                                                                         mFile.getRemotePath(),
                                                                         mFile.getMimeType(),
                                                                         mFile.getEtagInConflict(),
-                                                                        timeStamp, onWifiConnection);
+                                                                        timeStamp,
+                                                                        onWifiConnection);
             } else {
                 mUploadOperation = new UploadFileRemoteOperation(mFile.getStoragePath(),
-                                                                 mFile.getRemotePath(), mFile.getMimeType(), mFile.getEtagInConflict(), timeStamp);
+                                                                 mFile.getRemotePath(),
+                                                                 mFile.getMimeType(),
+                                                                 mFile.getEtagInConflict(),
+                                                                 timeStamp);
             }
 
             for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
@@ -932,7 +937,9 @@ public class UploadFileOperation extends SyncOperation {
         return null;
     }
 
-    private void handleSuccessfulUpload(File temporalFile, File expectedFile, File originalFile,
+    private void handleSuccessfulUpload(File temporalFile,
+                                        File expectedFile,
+                                        File originalFile,
                                         OwnCloudClient client) {
         switch (mLocalBehaviour) {
             case FileUploader.LOCAL_BEHAVIOUR_FORGET:
@@ -955,6 +962,12 @@ public class UploadFileOperation extends SyncOperation {
                     } catch (IOException e) {
                         Log_OC.e(TAG, e.getMessage());
                     }
+                } else if (originalFile != null) {
+                    try {
+                        copy(originalFile, expectedFile);
+                    } catch (IOException e) {
+                        Log_OC.e(TAG, e.getMessage());
+                    }
                 }
                 mFile.setStoragePath(expectedFile.getAbsolutePath());
                 saveUploadedFile(client);