Bug 1883870 - Improve test logs in bookmarks and downloads storage deletion in UI test

fenix/125.0
oana.horvath 2 months ago committed by mergify[bot]
parent 8a2d4cf665
commit a04657a0d6

@ -58,6 +58,8 @@ import java.util.Locale
object AppAndSystemHelper {
private val bookmarksStorage = PlacesBookmarksStorage(appContext.applicationContext)
suspend fun bookmarks() = bookmarksStorage.getTree(BookmarkRoot.Mobile.id)?.children
fun getPermissionAllowID(): String {
return when
(Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
@ -122,23 +124,26 @@ object AppAndSystemHelper {
// Check if the downloads folder exists
if (downloadsFolder.exists() && downloadsFolder.isDirectory) {
Log.i(TAG, "clearDownloadsFolder: Verified that \"DOWNLOADS\" folder exists")
val files = downloadsFolder.listFiles()
Log.i(TAG, "clearDownloadsFolder: Verified that \"DOWNLOADS\" folder exists.")
var files = downloadsFolder.listFiles()
// Check if the folder is not empty
// If you run this method before a test, files.isNotEmpty() will always return false.
if (files != null && files.isNotEmpty()) {
Log.i(
TAG,
"clearDownloadsFolder: Before cleanup: Downloads storage contains: ${files.size} file(s)",
"clearDownloadsFolder: Before cleanup: Downloads storage contains: ${files.size} file(s).",
)
// Delete all files in the folder
for (file in files) {
for (file in files!!) {
file.delete()
Log.i(
TAG,
"clearDownloadsFolder: Deleted $file from \"DOWNLOADS\" folder." +
" Downloads storage contains ${files.size} file(s): $file",
"clearDownloadsFolder: Deleted $file from \"DOWNLOADS\" folder.",
)
files = downloadsFolder.listFiles()
Log.i(
TAG,
"clearDownloadsFolder: After cleanup: Downloads storage contains: ${files?.size} file(s).",
)
}
} else {
@ -179,8 +184,7 @@ object AppAndSystemHelper {
}
suspend fun deleteBookmarksStorage() {
val bookmarksStorage = PlacesBookmarksStorage(appContext.applicationContext)
val bookmarks = bookmarksStorage.getTree(BookmarkRoot.Mobile.id)?.children
val bookmarks = bookmarks()
Log.i(TAG, "deleteBookmarksStorage before cleanup: Bookmarks storage contains: $bookmarks")
if (bookmarks?.isNotEmpty() == true) {
bookmarks.forEach {
@ -189,10 +193,9 @@ object AppAndSystemHelper {
"deleteBookmarksStorage: Trying to delete $it bookmark from storage.",
)
bookmarksStorage.deleteNode(it.guid)
// TODO: Follow-up with a method to handle the DB update; the logs will still show the bookmarks in the storage before the test starts.
Log.i(
TAG,
"deleteBookmarksStorage: Bookmark deleted. Bookmarks storage contains: $bookmarks",
"deleteBookmarksStorage: Bookmark deleted. Bookmarks storage contains: ${bookmarks()}",
)
}
}

@ -72,9 +72,6 @@ open class TestSetup {
open fun tearDown() {
Log.i(TAG, "TestSetup: Starting the @After tearDown methods.")
runBlocking {
// Check and clear the downloads folder.
AppAndSystemHelper.clearDownloadsFolder()
// Reset locale to EN-US if needed.
// This method is only here temporarily, to set the language before a new activity is started.
// TODO: When https://bugzilla.mozilla.org/show_bug.cgi?id=1812183 is fixed, it should be removed.

Loading…
Cancel
Save