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) metrics.track(Event.DownloadsItemOpened)
val fileWasOpened = AbstractFetchDownloadService.openFile( val fileWasOpened = AbstractFetchDownloadService.openFile(
context = context, applicationContext = context.applicationContext,
contentType = downloadState.contentType, download = downloadState
filePath = downloadState.filePath
) )
if (!fileWasOpened) { if (!fileWasOpened) {

@ -98,12 +98,13 @@ class DownloadFragment : LibraryPageFragment<DownloadItem>(), UserInteractionHan
.sortedByDescending { it.createdTime } // sort from newest to oldest .sortedByDescending { it.createdTime } // sort from newest to oldest
.map { .map {
DownloadItem( DownloadItem(
it.id, id = it.id,
it.fileName, url = it.url,
it.filePath, fileName = it.fileName,
it.contentLength?.toString() ?: "0", filePath = it.filePath,
it.contentType, size = it.contentLength?.toString() ?: "0",
it.status contentType = it.contentType,
status = it.status
) )
}.filter { }.filter {
it.status == DownloadState.Status.COMPLETED it.status == DownloadState.Status.COMPLETED
@ -249,10 +250,21 @@ class DownloadFragment : LibraryPageFragment<DownloadItem>(), UserInteractionHan
mode?.let { (activity as HomeActivity).browsingModeManager.mode = it } mode?.let { (activity as HomeActivity).browsingModeManager.mode = it }
context?.let { context?.let {
val contentLength = if (item.size.isNotEmpty()) {
item.size.toLong()
} else {
0L
}
AbstractFetchDownloadService.openFile( AbstractFetchDownloadService.openFile(
context = it, applicationContext = it.applicationContext,
contentType = item.contentType, download = DownloadState(
filePath = item.filePath 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 * Class representing a downloads entry
* @property id Unique id of the download item * @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 fileName File name of the download item
* @property filePath Full path of the download item * @property filePath Full path of the download item
* @property size The size in bytes of the download item * @property size The size in bytes of the download item
* @property contentType The type of file the download is * @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( data class DownloadItem(
val id: String, val id: String,
val url: String,
val fileName: String?, val fileName: String?,
val filePath: String, val filePath: String,
val size: String, val size: String,

@ -14,7 +14,15 @@ import org.mozilla.fenix.library.downloads.DownloadItem
class DownloadItemKtTest { class DownloadItemKtTest {
@Test @Test
fun getIcon() { 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_image, downloadItem.getIcon())
assertEquals(R.drawable.ic_file_type_audio_note, downloadItem.copy(contentType = "audio/mp3").getIcon()) assertEquals(R.drawable.ic_file_type_audio_note, downloadItem.copy(contentType = "audio/mp3").getIcon())

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

@ -21,7 +21,15 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@RunWith(FenixRobolectricTestRunner::class) @RunWith(FenixRobolectricTestRunner::class)
class DownloadControllerTest { 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 scope = TestCoroutineScope()
private val store: DownloadFragmentStore = mockk(relaxed = true) private val store: DownloadFragmentStore = mockk(relaxed = true)
private val state: DownloadFragmentState = mockk(relaxed = true) private val state: DownloadFragmentState = mockk(relaxed = true)

@ -11,8 +11,24 @@ import org.junit.Assert.assertNotSame
import org.junit.Test import org.junit.Test
class DownloadFragmentStoreTest { class DownloadFragmentStoreTest {
private val downloadItem = DownloadItem("0", "title", "url", "77", "jpg", DownloadState.Status.COMPLETED) private val downloadItem = DownloadItem(
private val newDownloadItem = DownloadItem("1", "title", "url", "77", "jpg", DownloadState.Status.COMPLETED) 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 @Test
fun exitEditMode() = runBlocking { fun exitEditMode() = runBlocking {

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

@ -12,7 +12,15 @@ import org.junit.Assert.assertTrue
import org.junit.Test import org.junit.Test
class DownloadInteractorTest { 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 controller: DownloadController = mockk(relaxed = true)
val interactor = DownloadInteractor(controller) val interactor = DownloadInteractor(controller)

Loading…
Cancel
Save