Fix openFile breaking changes

upstream-sync
Arturo Mejia 3 years ago
parent 816e8bebc0
commit c725493bea

@ -106,9 +106,8 @@ class DynamicDownloadDialog(
metrics.track(Event.DownloadsItemOpened)
val fileWasOpened = AbstractFetchDownloadService.openFile(
context = context,
contentType = downloadState.contentType,
filePath = downloadState.filePath
applicationContext = context.applicationContext,
download = downloadState
)
if (!fileWasOpened) {

@ -98,12 +98,13 @@ class DownloadFragment : LibraryPageFragment<DownloadItem>(), UserInteractionHan
.sortedByDescending { it.createdTime } // sort from newest to oldest
.map {
DownloadItem(
it.id,
it.fileName,
it.filePath,
it.contentLength?.toString() ?: "0",
it.contentType,
it.status
id = it.id,
url = it.url,
fileName = it.fileName,
filePath = it.filePath,
size = it.contentLength?.toString() ?: "0",
contentType = it.contentType,
status = it.status
)
}.filter {
it.status == DownloadState.Status.COMPLETED
@ -249,10 +250,21 @@ class DownloadFragment : LibraryPageFragment<DownloadItem>(), UserInteractionHan
mode?.let { (activity as HomeActivity).browsingModeManager.mode = it }
context?.let {
val contentLength = if (item.size.isNotEmpty()) {
item.size.toLong()
} else {
0L
}
AbstractFetchDownloadService.openFile(
context = it,
contentType = item.contentType,
filePath = item.filePath
applicationContext = it.applicationContext,
download = DownloadState(
id = item.id,
url = item.url,
fileName = item.fileName,
contentType = item.contentType,
status = item.status,
contentLength = contentLength
)
)
}

@ -12,13 +12,16 @@ import mozilla.components.lib.state.Store
/**
* Class representing a downloads entry
* @property id Unique id of the download item
* @property url The full url to the content that should be downloaded
* @property fileName File name of the download item
* @property filePath Full path of the download item
* @property size The size in bytes of the download item
* @property contentType The type of file the download is
* @property status The status that represents every state that a download can be in
*/
data class DownloadItem(
val id: String,
val url: String,
val fileName: String?,
val filePath: String,
val size: String,

@ -14,7 +14,15 @@ import org.mozilla.fenix.library.downloads.DownloadItem
class DownloadItemKtTest {
@Test
fun getIcon() {
val downloadItem = DownloadItem("0", "MyAwesomeFile", "", "", "image/png", DownloadState.Status.COMPLETED)
val downloadItem = DownloadItem(
id = "0",
url = "url",
fileName = "MyAwesomeFile",
filePath = "",
size = "",
contentType = "image/png",
status = DownloadState.Status.COMPLETED
)
assertEquals(R.drawable.ic_file_type_image, downloadItem.getIcon())
assertEquals(R.drawable.ic_file_type_audio_note, downloadItem.copy(contentType = "audio/mp3").getIcon())

@ -27,9 +27,33 @@ class ListTest {
file1.createNewFile()
file3.createNewFile()
val item1 = DownloadItem("71", "filepath.txt", filePath1, "71 Mb", "Image/png", DownloadState.Status.COMPLETED)
val item2 = DownloadItem("71", "filepath2.txt", "filepath2.txt", "71 Mb", "Image/png", DownloadState.Status.COMPLETED)
val item3 = DownloadItem("71", "filepath3.txt", filePath3, "71 Mb", "Image/png", DownloadState.Status.COMPLETED)
val item1 = DownloadItem(
id = "71",
url = "url",
fileName = "filepath.txt",
filePath = filePath1,
size = "71 Mb",
contentType = "Image/png",
status = DownloadState.Status.COMPLETED
)
val item2 = DownloadItem(
id = "71",
url = "url",
fileName = "filepath2.txt",
filePath = "filepath2.txt",
size = "71 Mb",
contentType = "Image/png",
status = DownloadState.Status.COMPLETED
)
val item3 = DownloadItem(
id = "71",
url = "url",
fileName = "filepath3.txt",
filePath = filePath3,
size = "71 Mb",
contentType = "Image/png",
status = DownloadState.Status.COMPLETED
)
val testList = mutableListOf(item1, item2, item3)
val comparisonList: MutableList<DownloadItem> = mutableListOf(item1, item3)
@ -58,9 +82,33 @@ class ListTest {
file2.createNewFile()
file3.createNewFile()
val item1 = DownloadItem("71", "filepath.txt", filePath1, "71 Mb", "text/plain", DownloadState.Status.COMPLETED)
val item2 = DownloadItem("72", "filepath2.txt", filePath2, "71 Mb", "text/plain", DownloadState.Status.COMPLETED)
val item3 = DownloadItem("73", "filepath3.txt", filePath3, "71 Mb", "text/plain", DownloadState.Status.COMPLETED)
val item1 = DownloadItem(
id = "71",
url = "url",
fileName = "filepath.txt",
filePath = filePath1,
size = "71 Mb",
contentType = "text/plain",
status = DownloadState.Status.COMPLETED
)
val item2 = DownloadItem(
id = "72",
url = "url",
fileName = "filepath2.txt",
filePath = filePath2,
size = "71 Mb",
contentType = "text/plain",
status = DownloadState.Status.COMPLETED
)
val item3 = DownloadItem(
id = "73",
url = "url",
fileName = "filepath3.txt",
filePath = filePath3,
size = "71 Mb",
contentType = "text/plain",
status = DownloadState.Status.COMPLETED
)
val testList = mutableListOf(item1, item2, item3)
val comparisonList: MutableList<DownloadItem> = mutableListOf(item1, item2, item3)

@ -21,7 +21,15 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@ExperimentalCoroutinesApi
@RunWith(FenixRobolectricTestRunner::class)
class DownloadControllerTest {
private val downloadItem = DownloadItem("0", "title", "url", "77", "jpg", DownloadState.Status.COMPLETED)
private val downloadItem = DownloadItem(
id = "0",
url = "url",
fileName = "title",
filePath = "url",
size = "77",
contentType = "jpg",
status = DownloadState.Status.COMPLETED
)
private val scope = TestCoroutineScope()
private val store: DownloadFragmentStore = mockk(relaxed = true)
private val state: DownloadFragmentState = mockk(relaxed = true)

@ -11,8 +11,24 @@ import org.junit.Assert.assertNotSame
import org.junit.Test
class DownloadFragmentStoreTest {
private val downloadItem = DownloadItem("0", "title", "url", "77", "jpg", DownloadState.Status.COMPLETED)
private val newDownloadItem = DownloadItem("1", "title", "url", "77", "jpg", DownloadState.Status.COMPLETED)
private val downloadItem = DownloadItem(
id = "0",
url = "url",
fileName = "title",
filePath = "url",
size = "77",
contentType = "jpg",
status = DownloadState.Status.COMPLETED
)
private val newDownloadItem = DownloadItem(
id = "1",
url = "url",
fileName = "title",
filePath = "url",
size = "77",
contentType = "jpg",
status = DownloadState.Status.COMPLETED
)
@Test
fun exitEditMode() = runBlocking {

@ -45,28 +45,31 @@ class DownloadFragmentTest {
val expectedList = listOf(
DownloadItem(
"3",
"3.pdf",
downloadedFile3.path,
"0",
null,
DownloadState.Status.COMPLETED
id = "3",
url = "url",
fileName = "3.pdf",
filePath = downloadedFile3.path,
size = "0",
contentType = null,
status = DownloadState.Status.COMPLETED
),
DownloadItem(
"2",
"2.pdf",
downloadedFile2.path,
"0",
null,
DownloadState.Status.COMPLETED
id = "2",
url = "url",
fileName = "2.pdf",
filePath = downloadedFile2.path,
size = "0",
contentType = null,
status = DownloadState.Status.COMPLETED
),
DownloadItem(
"1",
"1.pdf",
downloadedFile1.path,
"0",
null,
DownloadState.Status.COMPLETED
id = "1",
url = "url",
fileName = "1.pdf",
filePath = downloadedFile1.path,
size = "0",
contentType = null,
status = DownloadState.Status.COMPLETED
)
)
@ -118,12 +121,13 @@ class DownloadFragmentTest {
val expectedList = listOf(
DownloadItem(
"1",
"1.pdf",
downloadedFile0.path,
"0",
null,
DownloadState.Status.COMPLETED
id = "1",
url = "url",
fileName = "1.pdf",
filePath = downloadedFile0.path,
size = "0",
contentType = null,
status = DownloadState.Status.COMPLETED
)
)

@ -12,7 +12,15 @@ import org.junit.Assert.assertTrue
import org.junit.Test
class DownloadInteractorTest {
private val downloadItem = DownloadItem("0", "title", "url", "5.6 mb", "png", DownloadState.Status.COMPLETED)
private val downloadItem = DownloadItem(
id = "0",
url = "url",
fileName = "title",
filePath = "filePath",
size = "5.6 mb",
contentType = "png",
status = DownloadState.Status.COMPLETED
)
val controller: DownloadController = mockk(relaxed = true)
val interactor = DownloadInteractor(controller)

Loading…
Cancel
Save