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

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

@ -58,6 +58,8 @@ import java.util.Locale
object AppAndSystemHelper { object AppAndSystemHelper {
private val bookmarksStorage = PlacesBookmarksStorage(appContext.applicationContext)
suspend fun bookmarks() = bookmarksStorage.getTree(BookmarkRoot.Mobile.id)?.children
fun getPermissionAllowID(): String { fun getPermissionAllowID(): String {
return when return when
(Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
@ -122,23 +124,26 @@ object AppAndSystemHelper {
// Check if the downloads folder exists // Check if the downloads folder exists
if (downloadsFolder.exists() && downloadsFolder.isDirectory) { if (downloadsFolder.exists() && downloadsFolder.isDirectory) {
Log.i(TAG, "clearDownloadsFolder: Verified that \"DOWNLOADS\" folder exists") Log.i(TAG, "clearDownloadsFolder: Verified that \"DOWNLOADS\" folder exists.")
val files = downloadsFolder.listFiles() var files = downloadsFolder.listFiles()
// Check if the folder is not empty // 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()) { if (files != null && files.isNotEmpty()) {
Log.i( Log.i(
TAG, 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 // Delete all files in the folder
for (file in files) { for (file in files!!) {
file.delete() file.delete()
Log.i( Log.i(
TAG, TAG,
"clearDownloadsFolder: Deleted $file from \"DOWNLOADS\" folder." + "clearDownloadsFolder: Deleted $file from \"DOWNLOADS\" folder.",
" Downloads storage contains ${files.size} file(s): $file", )
files = downloadsFolder.listFiles()
Log.i(
TAG,
"clearDownloadsFolder: After cleanup: Downloads storage contains: ${files?.size} file(s).",
) )
} }
} else { } else {
@ -179,8 +184,7 @@ object AppAndSystemHelper {
} }
suspend fun deleteBookmarksStorage() { suspend fun deleteBookmarksStorage() {
val bookmarksStorage = PlacesBookmarksStorage(appContext.applicationContext) val bookmarks = bookmarks()
val bookmarks = bookmarksStorage.getTree(BookmarkRoot.Mobile.id)?.children
Log.i(TAG, "deleteBookmarksStorage before cleanup: Bookmarks storage contains: $bookmarks") Log.i(TAG, "deleteBookmarksStorage before cleanup: Bookmarks storage contains: $bookmarks")
if (bookmarks?.isNotEmpty() == true) { if (bookmarks?.isNotEmpty() == true) {
bookmarks.forEach { bookmarks.forEach {
@ -189,10 +193,9 @@ object AppAndSystemHelper {
"deleteBookmarksStorage: Trying to delete $it bookmark from storage.", "deleteBookmarksStorage: Trying to delete $it bookmark from storage.",
) )
bookmarksStorage.deleteNode(it.guid) 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( Log.i(
TAG, 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() { open fun tearDown() {
Log.i(TAG, "TestSetup: Starting the @After tearDown methods.") Log.i(TAG, "TestSetup: Starting the @After tearDown methods.")
runBlocking { runBlocking {
// Check and clear the downloads folder.
AppAndSystemHelper.clearDownloadsFolder()
// Reset locale to EN-US if needed. // Reset locale to EN-US if needed.
// This method is only here temporarily, to set the language before a new activity is started. // 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. // TODO: When https://bugzilla.mozilla.org/show_bug.cgi?id=1812183 is fixed, it should be removed.

Loading…
Cancel
Save