|
|
|
@ -34,6 +34,9 @@ import androidx.test.uiautomator.UiSelector
|
|
|
|
|
import androidx.test.uiautomator.Until
|
|
|
|
|
import junit.framework.AssertionFailedError
|
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
|
import mozilla.appservices.places.BookmarkRoot
|
|
|
|
|
import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
|
|
|
|
|
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
|
|
|
|
|
import org.junit.Assert
|
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
|
import org.mozilla.fenix.Config
|
|
|
|
@ -43,6 +46,7 @@ import org.mozilla.fenix.helpers.Constants.PackageName.PIXEL_LAUNCHER
|
|
|
|
|
import org.mozilla.fenix.helpers.Constants.PackageName.YOUTUBE_APP
|
|
|
|
|
import org.mozilla.fenix.helpers.Constants.TAG
|
|
|
|
|
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
|
|
|
|
|
import org.mozilla.fenix.helpers.TestHelper.appContext
|
|
|
|
|
import org.mozilla.fenix.helpers.TestHelper.mDevice
|
|
|
|
|
import org.mozilla.fenix.helpers.ext.waitNotNull
|
|
|
|
|
import org.mozilla.fenix.helpers.idlingresource.NetworkConnectionIdlingResource
|
|
|
|
@ -70,7 +74,7 @@ object AppAndSystemHelper {
|
|
|
|
|
fun deleteDownloadedFileOnStorage(fileName: String) {
|
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
|
|
|
|
|
val storageManager: StorageManager? =
|
|
|
|
|
TestHelper.appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager?
|
|
|
|
|
appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager?
|
|
|
|
|
val storageVolumes = storageManager!!.storageVolumes
|
|
|
|
|
val storageVolume: StorageVolume = storageVolumes[0]
|
|
|
|
|
val file = File(storageVolume.directory!!.path + "/Download/" + fileName)
|
|
|
|
@ -110,7 +114,7 @@ object AppAndSystemHelper {
|
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
|
|
|
|
|
Log.i(TAG, "clearDownloadsFolder: API > 29")
|
|
|
|
|
val storageManager: StorageManager? =
|
|
|
|
|
TestHelper.appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager?
|
|
|
|
|
appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager?
|
|
|
|
|
val storageVolumes = storageManager!!.storageVolumes
|
|
|
|
|
val storageVolume: StorageVolume = storageVolumes[0]
|
|
|
|
|
val downloadsFolder = File(storageVolume.directory!!.path + "/Download/")
|
|
|
|
@ -121,16 +125,26 @@ object AppAndSystemHelper {
|
|
|
|
|
val 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: Verified that \"DOWNLOADS\" folder is not empty",
|
|
|
|
|
"clearDownloadsFolder: Before cleanup: Downloads storage contains: ${files.size} file(s)",
|
|
|
|
|
)
|
|
|
|
|
// Delete all files in the folder
|
|
|
|
|
for (file in files) {
|
|
|
|
|
file.delete()
|
|
|
|
|
Log.i(TAG, "clearDownloadsFolder: Deleted $file from \"DOWNLOADS\" folder")
|
|
|
|
|
Log.i(
|
|
|
|
|
TAG,
|
|
|
|
|
"clearDownloadsFolder: Deleted $file from \"DOWNLOADS\" folder." +
|
|
|
|
|
" Downloads storage contains ${files.size} file(s): $file",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Log.i(
|
|
|
|
|
TAG,
|
|
|
|
|
"clearDownloadsFolder: Downloads storage is empty.",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -139,6 +153,7 @@ object AppAndSystemHelper {
|
|
|
|
|
Log.i(TAG, "clearDownloadsFolder: Verifying if any download files exist.")
|
|
|
|
|
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
|
|
|
|
.listFiles()?.forEach {
|
|
|
|
|
Log.i(TAG, "clearDownloadsFolder: Downloads storage contains: $it.")
|
|
|
|
|
it.delete()
|
|
|
|
|
Log.i(TAG, "clearDownloadsFolder: Download file $it deleted.")
|
|
|
|
|
}
|
|
|
|
@ -146,6 +161,36 @@ object AppAndSystemHelper {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suspend fun deleteHistoryStorage() {
|
|
|
|
|
val historyStorage = PlacesHistoryStorage(appContext.applicationContext)
|
|
|
|
|
Log.i(
|
|
|
|
|
TAG,
|
|
|
|
|
"deleteHistoryStorage before cleanup: History storage contains: ${historyStorage.getVisited()}",
|
|
|
|
|
)
|
|
|
|
|
if (historyStorage.getVisited().isNotEmpty()) {
|
|
|
|
|
Log.i(TAG, "deleteHistoryStorage: Trying to delete all history storage.")
|
|
|
|
|
historyStorage.deleteEverything()
|
|
|
|
|
Log.i(
|
|
|
|
|
TAG,
|
|
|
|
|
"deleteHistoryStorage after cleanup: History storage contains: ${historyStorage.getVisited()}",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suspend fun deleteBookmarksStorage() {
|
|
|
|
|
val bookmarksStorage = PlacesBookmarksStorage(appContext.applicationContext)
|
|
|
|
|
val bookmarks = bookmarksStorage.getTree(BookmarkRoot.Mobile.id)?.children
|
|
|
|
|
Log.i(TAG, "deleteBookmarksStorage before cleanup: Bookmarks storage contains: $bookmarks")
|
|
|
|
|
if (bookmarks?.isNotEmpty() == true) {
|
|
|
|
|
bookmarks.forEach {
|
|
|
|
|
Log.i(TAG, "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")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun setNetworkEnabled(enabled: Boolean) {
|
|
|
|
|
val networkDisconnectedIdlingResource = NetworkConnectionIdlingResource(false)
|
|
|
|
|
val networkConnectedIdlingResource = NetworkConnectionIdlingResource(true)
|
|
|
|
@ -228,7 +273,7 @@ object AppAndSystemHelper {
|
|
|
|
|
*/
|
|
|
|
|
fun isExternalAppBrowserActivityInCurrentTask(): Boolean {
|
|
|
|
|
Log.i(TAG, "Trying to verify that the latest activity of the application is used for custom tabs or PWAs")
|
|
|
|
|
val activityManager = TestHelper.appContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
|
|
val activityManager = appContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
|
|
|
|
|
|
|
mDevice.waitForIdle(TestAssetHelper.waitingTimeShort)
|
|
|
|
|
|
|
|
|
|