Add File Manager Return and Exit navigation (#1301)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-23 11:04:35 -04:00
commit bf4aa58c68
40 files changed
+549 -55

No files matched your search

@@ -0,0 +1,20 @@
package com.droiddeck.launcher.files
import java.io.File
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
class FileManagerNavigationTest {
@get:Rule val tmp = TemporaryFolder()
@Test fun backCannotNavigateAboveTheCurrentDriveRoot() {
val drive = tmp.newFolder("drive")
val child = File(drive, "folder").apply { mkdir() }
assertTrue(canNavigateUp(child, drive))
assertFalse(canNavigateUp(drive, drive))
}
}
@@ -0,0 +1,121 @@
package com.droiddeck.launcher.files
import java.io.File
import java.util.concurrent.CancellationException
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class FileOpsCancellationTest {
@get:Rule val tmp = TemporaryFolder()
@Test fun cancellingCopyRemovesAnIncompleteNewFile() {
val source = tmp.newFile("source").apply { writeBytes(ByteArray(5 * 1024 * 1024)) }
val destination = File(tmp.root, "destination")
var cancelled = false
assertThrows(CancellationException::class.java) {
FileOps.copyWithProgress(source, destination, { _, _ -> cancelled = true }) { cancelled }
}
assertTrue(source.exists())
assertFalse(destination.exists())
}
@Test fun cancellingMoveFallbackPreservesTheSourceAndExistingDestination() {
val source = tmp.newFile("source").apply { writeText("replacement") }
val destination = tmp.newFile("destination").apply { writeText("original") }
var cancelled = false
assertThrows(CancellationException::class.java) {
FileOps.moveWithProgress(source, destination, { _, _ -> cancelled = true }) { cancelled }
}
assertEquals("replacement", source.readText())
assertEquals("original", destination.readText())
}
@Test fun aCommittedMoveFinishesRemovingTheSourceDespiteCancellation() {
val source = tmp.newFile("source").apply { writeText("replacement") }
val destination = tmp.newFile("destination").apply { writeText("original") }
val isCancelled = { destination.readText() == "replacement" }
assertTrue(FileOps.moveWithProgress(source, destination, null, isCancelled))
assertTrue(isCancelled())
assertEquals("replacement", destination.readText())
assertFalse(source.exists())
assertEquals(setOf("destination"), tmp.root.list()!!.toSet())
}
@Test fun cancellingTheSizeScanStopsBeforeCreatingTheDestination() {
val source = tmp.newFolder("source")
repeat(3) { File(source, "file-$it").writeText("content") }
val destination = File(tmp.root, "destination")
var checks = 0
assertThrows(CancellationException::class.java) {
FileOps.copyWithProgress(source, destination, null) {
assertFalse(destination.exists())
++checks > 2
}
}
assertEquals(3, checks)
assertFalse(destination.exists())
assertEquals(3, source.listFiles()?.size)
}
@Test fun cancellingCopyRemovesANewDestinationDirectory() {
val source = tmp.newFolder("source")
val payload = File(source, "nested/payload").apply {
parentFile!!.mkdirs()
writeText("content")
}
val destination = File(tmp.root, "destination")
assertThrows(CancellationException::class.java) {
FileOps.copyWithProgress(source, destination, { _, _ -> throw CancellationException("cancel") })
}
assertEquals("content", payload.readText())
assertFalse(destination.exists())
}
@Test fun cancellingCopyPreservesAnExistingDestinationDirectory() {
val source = tmp.newFolder("source")
File(source, "nested/payload").apply {
parentFile!!.mkdirs()
writeText("replacement")
}
val destination = tmp.newFolder("destination")
val existing = File(destination, "keep").apply { writeText("original") }
assertThrows(CancellationException::class.java) {
FileOps.copyWithProgress(source, destination, { _, _ -> throw CancellationException("cancel") })
}
assertEquals("original", existing.readText())
assertEquals(setOf("keep"), destination.list()!!.toSet())
}
@Test fun cancellingRecursiveDeleteStopsBeforeTheNextFile() {
val directory = tmp.newFolder("directory")
repeat(3) { File(directory, "file-$it").writeText("content") }
var checks = 0
assertThrows(CancellationException::class.java) {
FileOps.delete(directory) { ++checks > 3 }
}
assertTrue(directory.exists())
assertEquals(2, directory.listFiles()?.size)
}
}
@@ -53,27 +53,25 @@ class FileOpsCopyTest {
assertEquals("replacement", src.readText())
}
@Test fun cancellingStopsATreeOfEmptyFiles() {
@Test fun cancellingRemovesANewTreeOfEmptyFiles() {
val src = tmp.newFolder("source")
for (name in listOf("a", "b", "c")) File(src, name).createNewFile()
val dst = File(tmp.root, "dest")
var checks = 0
assertThrows(CancellationException::class.java) {
FileOps.copyWithProgress(src, dst, null) { checks++ > 1 }
FileOps.copyWithProgress(src, dst, null) { dst.list()?.isNotEmpty() == true }
}
assertEquals(1, dst.list()!!.size)
assertFalse(dst.exists())
assertEquals(3, src.list()!!.size)
}
@Test fun cancellingStopsATreeOfEmptyFolders() {
@Test fun cancellingRemovesANewTreeOfEmptyFolders() {
val src = tmp.newFolder("source")
for (name in listOf("a", "b", "c")) File(src, name).mkdir()
val dst = File(tmp.root, "dest")
var checks = 0
assertThrows(CancellationException::class.java) {
FileOps.copyWithProgress(src, dst, null) { checks++ > 1 }
FileOps.copyWithProgress(src, dst, null) { dst.list()?.isNotEmpty() == true }
}
assertEquals(1, dst.list()!!.size)
assertFalse(dst.exists())
}
@Test fun aCompletedCopyReplacesTheDestination() {