Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions app/src/androidTest/java/com/nmc/android/ui/LauncherActivityIT.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-FileCopyrightText: 2023 TSI-mc
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
*/
package com.nmc.android.ui

import android.content.Intent
import android.os.SystemClock
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
Expand Down Expand Up @@ -46,9 +48,7 @@ class LauncherActivityIT : AbstractIT() {
fun testSplashScreenWithEmptyTitlesShouldNotDelayNextScreen() {
val activity = launchLauncherActivity()

instrumentation.waitForIdleSync()

assertTrue(activity.isFinishing)
assertTrue("Splash screen without titles did not open the next screen", activity.awaitFinishing())
}

private fun launchLauncherActivity(): LauncherActivity {
Expand All @@ -57,4 +57,24 @@ class LauncherActivityIT : AbstractIT() {

return instrumentation.startActivitySync(intent) as LauncherActivity
}

private fun LauncherActivity.awaitFinishing(): Boolean {
val deadline = SystemClock.uptimeMillis() + FINISH_TIMEOUT_IN_MILLIS
var finishing = false

while (!finishing && SystemClock.uptimeMillis() < deadline) {
instrumentation.runOnMainSync { finishing = isFinishing }

if (!finishing) {
Thread.sleep(FINISH_POLL_INTERVAL_IN_MILLIS)
}
}

return finishing
}

companion object {
private const val FINISH_TIMEOUT_IN_MILLIS = 5000L
private const val FINISH_POLL_INTERVAL_IN_MILLIS = 50L
}
}
151 changes: 0 additions & 151 deletions app/src/androidTest/java/com/owncloud/android/FileIT.java

This file was deleted.

125 changes: 125 additions & 0 deletions app/src/androidTest/java/com/owncloud/android/FileIT.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-FileCopyrightText: 2018 Tobias Kaminsky <tobias@kaminsky.me>
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
*/
package com.owncloud.android

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.operations.CreateFolderOperation
import com.owncloud.android.operations.RenameFileOperation
import com.owncloud.android.operations.SynchronizeFolderOperation
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File

/**
* Tests related to file operations.
*
* Every test starts with an empty server and an empty local database, and [AbstractOnServerIT.after] wipes both again
* afterwards, so no test needs to clean up after itself.
*/
@RunWith(AndroidJUnit4::class)
class FileIT : AbstractOnServerIT() {

@Test
fun testCreateFolder() {
val path = "/testFolder/"
assertNull(storageManager.getFileByDecryptedRemotePath(path))
createFolderOrFail(path)
assertTrue(localFile(path).isFolder)
}

@Test
fun testCreateNonExistingSubFolder() {
val path = "/subFolder/1/2/3/4/5/"
assertNull(storageManager.getFileByDecryptedRemotePath(path))
createFolderOrFail(path)
assertTrue(localFile(path).isFolder)
}

@Test
fun testRemoteIdNull() {
storageManager.deleteAllFiles()
assertEquals(0, storageManager.allFiles.size)

storageManager.saveFile(OCFile("/123.txt"))
assertEquals(1, storageManager.allFiles.size)

storageManager.deleteAllFiles()
assertEquals(0, storageManager.allFiles.size)
}

@Test
fun testRenameFolder() {
val folderPath = "/testRenameFolder/"
val filePath = folderPath + UPLOADED_FILE_NAME
val renamedFolderPath = "/$NEW_FOLDER_NAME/"
val renamedFilePath = renamedFolderPath + UPLOADED_FILE_NAME

// the upload creates the parent folder on the server and in the local database
uploadFile(getDummyFile(DUMMY_FILE_NAME), filePath)
synchronizeFolder(folderPath)

val folderCopy = localCopyOf(folderPath)
val fileCopy = localCopyOf(filePath)
assertTrue("$folderPath was not downloaded", folderCopy.exists())
assertTrue("$filePath was not downloaded", fileCopy.exists())

val result = RenameFileOperation(folderPath, NEW_FOLDER_NAME, storageManager).execute(client)
assertTrue("Rename of $folderPath failed: ${result.logMessage}", result.isSuccess)

assertTrue("$renamedFolderPath has no local copy", localCopyOf(renamedFolderPath).exists())
assertTrue("$renamedFilePath has no local copy", localCopyOf(renamedFilePath).exists())

assertNull(storageManager.getFileByDecryptedRemotePath(folderPath))
assertNull(storageManager.getFileByDecryptedRemotePath(filePath))

assertFalse("$folderPath was not moved locally", folderCopy.exists())
assertFalse("$filePath was not moved locally", fileCopy.exists())
}

private fun createFolderOrFail(remotePath: String) {
val result = CreateFolderOperation(remotePath, user, targetContext, storageManager).execute(client)
assertTrue("Creation of $remotePath failed: ${result.logMessage}", result.isSuccess)
}

private fun synchronizeFolder(remotePath: String) {
val result = SynchronizeFolderOperation(
targetContext,
remotePath,
user,
storageManager,
false,
false
).execute(client)

assertTrue("Sync of $remotePath failed: ${result.logMessage}", result.isSuccess)
}

private fun localFile(remotePath: String): OCFile {
val file = storageManager.getFileByDecryptedRemotePath(remotePath)
assertNotNull("$remotePath is missing from the local database", file)
return file!!
}

private fun localCopyOf(remotePath: String): File {
val storagePath = localFile(remotePath).storagePath
assertFalse("$remotePath has no storage path", storagePath.isNullOrEmpty())
return File(storagePath)
}

companion object {
private const val DUMMY_FILE_NAME = "nonEmpty.txt"
private const val UPLOADED_FILE_NAME = "text.txt"
private const val NEW_FOLDER_NAME = "test123"
}
}
Loading