mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Added test cases to test opening files from browsers.
This commit is contained in:
parent
c6ff46a669
commit
968cbfa19a
@ -62,6 +62,12 @@ class CopyMoveFileHandlerRobot : BaseRobot() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clickOnCancel() {
|
||||||
|
testFlakyView({
|
||||||
|
onView(withText(R.string.cancel)).perform(click())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fun assertZimFileCopiedAndShowingIntoTheReader() {
|
fun assertZimFileCopiedAndShowingIntoTheReader() {
|
||||||
pauseForBetterTestPerformance()
|
pauseForBetterTestPerformance()
|
||||||
isVisible(Findable.ViewId(id.readerFragment))
|
isVisible(Findable.ViewId(id.readerFragment))
|
||||||
|
@ -120,31 +120,14 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
|
|||||||
clickOnMove()
|
clickOnMove()
|
||||||
assertZimFileCopiedAndShowingIntoTheReader()
|
assertZimFileCopiedAndShowingIntoTheReader()
|
||||||
}
|
}
|
||||||
deleteZimFileFromDownloadsFolder(uri!!)
|
|
||||||
} catch (ignore: Exception) {
|
} catch (ignore: Exception) {
|
||||||
deleteZimFileFromDownloadsFolder(uri!!)
|
|
||||||
fail("Could not open file from file manager. Original exception = $ignore")
|
fail("Could not open file from file manager. Original exception = $ignore")
|
||||||
|
} finally {
|
||||||
|
deleteZimFileFromDownloadsFolder(uri!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the zim file from the downloads folder which we have put in the download folder.
|
|
||||||
// Since after this test case we do not have the access to that file, and that file takes the
|
|
||||||
// memory in device.
|
|
||||||
private fun deleteZimFileFromDownloadsFolder(uri: Uri) {
|
|
||||||
val resolver = context.contentResolver
|
|
||||||
try {
|
|
||||||
val rowsDeleted = resolver.delete(uri, null, null)
|
|
||||||
if (rowsDeleted > 0) {
|
|
||||||
Log.d("FileDeletion", "Deleted: $uri")
|
|
||||||
} else {
|
|
||||||
Log.e("FileDeletion", "Failed to delete: $uri")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("FileDeletion", "Error deleting file: $uri, Error: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOpeningFileFromFileManager() {
|
fun testOpeningFileFromFileManager() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
@ -162,14 +145,71 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
|
|||||||
clickOnMove()
|
clickOnMove()
|
||||||
assertZimFileCopiedAndShowingIntoTheReader()
|
assertZimFileCopiedAndShowingIntoTheReader()
|
||||||
}
|
}
|
||||||
deleteZimFileFromDownloadsFolder(uri!!)
|
|
||||||
} catch (ignore: Exception) {
|
} catch (ignore: Exception) {
|
||||||
deleteZimFileFromDownloadsFolder(uri!!)
|
|
||||||
fail("Could not open file from file manager. Original exception = $ignore")
|
fail("Could not open file from file manager. Original exception = $ignore")
|
||||||
|
} finally {
|
||||||
|
deleteZimFileFromDownloadsFolder(uri!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOpeningFileFromBrowser() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
testCopyMoveDialogShowing(
|
||||||
|
Uri.parse(
|
||||||
|
"content://com.opera.browser.DownloadProvider/downloads/beer.stackexchange" +
|
||||||
|
".com_en_all_2023-05.zim?hash=w4A3vMuc7l1FPQwk23rmbgvfPGJfhcj5FujW37NApdA%3D&mt=" +
|
||||||
|
"application%2Foctet-stream"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
testCopyMoveDialogShowing(Uri.parse("content://media/external/downloads/2825"))
|
||||||
|
testCopyMoveDialogShowing(
|
||||||
|
Uri.parse(
|
||||||
|
"content://org.mozilla.firefox.DownloadProvider/" +
|
||||||
|
"downloads/beer.stackexchange.com_en_all_2023-05.zim"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun testCopyMoveDialogShowing(uri: Uri) {
|
||||||
|
ActivityScenario.launch<KiwixMainActivity>(
|
||||||
|
createDeepLinkIntent(uri)
|
||||||
|
).onActivity {}
|
||||||
|
sharedPreferenceUtil.copyMoveZimFilePermissionDialog = false
|
||||||
|
copyMoveFileHandler {
|
||||||
|
assertCopyMovePermissionDialogDisplayed()
|
||||||
|
clickOnCancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createDeepLinkIntent(uri: Uri): Intent {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
|
setDataAndType(uri, "application/octet-stream")
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
setPackage(context.packageName)
|
||||||
|
}
|
||||||
|
return intent
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete the zim file from the downloads folder which we have put in the download folder.
|
||||||
|
// Since after this test case we do not have the access to that file, and that file takes the
|
||||||
|
// memory in device.
|
||||||
|
private fun deleteZimFileFromDownloadsFolder(uri: Uri) {
|
||||||
|
val resolver = context.contentResolver
|
||||||
|
try {
|
||||||
|
val rowsDeleted = resolver.delete(uri, null, null)
|
||||||
|
if (rowsDeleted > 0) {
|
||||||
|
Log.d("FileDeletion", "Deleted: $uri")
|
||||||
|
} else {
|
||||||
|
Log.e("FileDeletion", "Failed to delete: $uri")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("FileDeletion", "Error deleting file: $uri, Error: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun openFileManager() {
|
private fun openFileManager() {
|
||||||
val intent =
|
val intent =
|
||||||
context.packageManager.getLaunchIntentForPackage("com.android.documentsui")
|
context.packageManager.getLaunchIntentForPackage("com.android.documentsui")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user