diff --git a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoResult.kt b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoResult.kt index add83e8928d..e5b8bc908e1 100644 --- a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoResult.kt +++ b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoResult.kt @@ -4,6 +4,7 @@ package mozilla.components.browser.engine.gecko +import android.util.Log import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart @@ -21,13 +22,19 @@ import kotlin.coroutines.suspendCoroutine * Wait for a GeckoResult to be complete in a co-routine. */ suspend fun GeckoResult.await() = suspendCoroutine { continuation -> + Log.w("gri", "2.1") + Log.w("gri", "looper: $looper") then( { + Log.w("gri", "2.2") continuation.resume(it) + Log.w("gri", "2.3") GeckoResult() }, { + Log.w("gri", "2.4") continuation.resumeWithException(it) + Log.w("gri", "2.5") GeckoResult() } ) @@ -65,11 +72,17 @@ fun CoroutineScope.launchGeckoResult( start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T ) = GeckoResult().apply { + Log.w("gri", "1.1") launch(context, start) { + Log.w("gri", "1.2") try { + Log.w("gri", "1.3") val value = block() + Log.w("gri", "1.4") complete(value) + Log.w("gri", "1.5") } catch (exception: Throwable) { + Log.w("gri", "1.6") completeExceptionally(exception) } } diff --git a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt index acfa43f7c7a..3b8394cd52e 100644 --- a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt +++ b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt @@ -11,7 +11,8 @@ import android.os.Message import android.view.WindowManager import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runBlockingTest +import kotlinx.coroutines.test.UnconfinedTestDispatcher +import kotlinx.coroutines.test.runTest import mozilla.components.browser.engine.gecko.ext.geckoTrackingProtectionPermission import mozilla.components.browser.engine.gecko.ext.isExcludedForTrackingProtection import mozilla.components.browser.engine.gecko.permission.geckoContentPermission @@ -772,7 +773,7 @@ class GeckoEngineSessionTest { } @Test - fun `notifies configured history delegate of title changes`() = runBlockingTest { + fun `notifies configured history delegate of title changes`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( runtime, geckoSessionProvider = geckoSessionProvider, context = coroutineContext @@ -799,7 +800,7 @@ class GeckoEngineSessionTest { } @Test - fun `does not notify configured history delegate of title changes for private sessions`() = runBlockingTest { + fun `does not notify configured history delegate of title changes for private sessions`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -831,7 +832,7 @@ class GeckoEngineSessionTest { } @Test - fun `notifies configured history delegate of preview image URL changes`() = runBlockingTest { + fun `notifies configured history delegate of preview image URL changes`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( runtime, geckoSessionProvider = geckoSessionProvider, context = coroutineContext @@ -862,7 +863,7 @@ class GeckoEngineSessionTest { } @Test - fun `does not notify configured history delegate of preview image URL changes for private sessions`() = runBlockingTest { + fun `does not notify configured history delegate of preview image URL changes for private sessions`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -894,7 +895,7 @@ class GeckoEngineSessionTest { } @Test - fun `does not notify configured history delegate for top-level visits to error pages`() = runBlockingTest { + fun `does not notify configured history delegate for top-level visits to error pages`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -917,7 +918,7 @@ class GeckoEngineSessionTest { } @Test - fun `notifies configured history delegate of visits`() = runBlockingTest { + fun `notifies configured history delegate of visits`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -936,7 +937,7 @@ class GeckoEngineSessionTest { } @Test - fun `notifies configured history delegate of reloads`() = runBlockingTest { + fun `notifies configured history delegate of reloads`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -955,7 +956,7 @@ class GeckoEngineSessionTest { } @Test - fun `checks with the delegate before trying to record a visit`() = runBlockingTest { + fun `checks with the delegate before trying to record a visit`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -983,7 +984,7 @@ class GeckoEngineSessionTest { } @Test - fun `correctly processes redirect visit flags`() = runBlockingTest { + fun `correctly processes redirect visit flags`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -1045,7 +1046,7 @@ class GeckoEngineSessionTest { } @Test - fun `does not notify configured history delegate of visits for private sessions`() = runBlockingTest { + fun `does not notify configured history delegate of visits for private sessions`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -1064,7 +1065,7 @@ class GeckoEngineSessionTest { } @Test - fun `requests visited URLs from configured history delegate`() = runBlockingTest { + fun `requests visited URLs from configured history delegate`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -1086,7 +1087,7 @@ class GeckoEngineSessionTest { } @Test - fun `does not request visited URLs from configured history delegate in private sessions`() = runBlockingTest { + fun `does not request visited URLs from configured history delegate in private sessions`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, @@ -1105,7 +1106,7 @@ class GeckoEngineSessionTest { } @Test - fun `notifies configured history delegate of state changes`() = runBlockingTest { + fun `notifies configured history delegate of state changes`() = runTest(UnconfinedTestDispatcher()) { val engineSession = GeckoEngineSession( mock(), geckoSessionProvider = geckoSessionProvider, diff --git a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoResultTest.kt b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoResultTest.kt index 350f32ef182..9e2fd38d86e 100644 --- a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoResultTest.kt +++ b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoResultTest.kt @@ -4,62 +4,77 @@ package mozilla.components.browser.engine.gecko +import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runBlockingTest +import kotlinx.coroutines.test.* import mozilla.components.support.test.mock import mozilla.components.support.test.whenever -import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Assert.fail +import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.gecko.util.ThreadUtils import org.mozilla.geckoview.GeckoResult @ExperimentalCoroutinesApi @RunWith(AndroidJUnit4::class) class GeckoResultTest { + private val dispatcher = StandardTestDispatcher() + @Test - fun awaitWithResult() = runBlockingTest { + fun awaitWithResult() = runTest(UnconfinedTestDispatcher()) { val result = GeckoResult.fromValue(42).await() assertEquals(42, result) } @Test(expected = IllegalStateException::class) - fun awaitWithException() = runBlockingTest { + fun awaitWithException() = runTest(UnconfinedTestDispatcher()) { GeckoResult.fromException(IllegalStateException()).await() } @Test - fun fromResult() = runBlockingTest { - val result = launchGeckoResult { 42 } + fun fromResult() = runTest(dispatcher) { + Dispatchers.setMain(dispatcher) + Log.w("gri", "1") + if (ThreadUtils.isOnUiThread()) { + Log.w("gri", "isOnUiThread") + } + val result = launchGeckoResult { Log.w("gri", "2"); 42 } + Log.w("gri", "3") result.then { + Log.w("gri", "4") assertEquals(42, it) GeckoResult.fromValue(null) }.await() + Log.w("gri", "5") + Dispatchers.resetMain() } @Test - fun fromException() = runBlockingTest { - val result = launchGeckoResult { throw IllegalStateException() } - + fun fromException() = runTest(UnconfinedTestDispatcher()) { + Log.w("gri", "1") + val result = this.launchGeckoResult { Log.w("gri", "2"); throw IllegalStateException() } + Log.w("gri", "3") result.then( { + Log.w("gri", "4") assertTrue("Invalid branch", false) GeckoResult.fromValue(null) }, { + Log.w("gri", "5") assertTrue(it is IllegalStateException) GeckoResult.fromValue(null) } ).await() + Log.w("gri", "6") } @Test - fun asCancellableOperation() = runBlockingTest { + fun asCancellableOperation() = runTest(UnconfinedTestDispatcher()) { val geckoResult: GeckoResult = mock() val op = geckoResult.asCancellableOperation() diff --git a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/permission/GeckoSitePermissionsStorageTest.kt b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/permission/GeckoSitePermissionsStorageTest.kt index 2d87ec73602..3ea137cd76a 100644 --- a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/permission/GeckoSitePermissionsStorageTest.kt +++ b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/permission/GeckoSitePermissionsStorageTest.kt @@ -6,7 +6,8 @@ package mozilla.components.browser.engine.gecko.permission import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runBlockingTest +import kotlinx.coroutines.test.UnconfinedTestDispatcher +import kotlinx.coroutines.test.runTest import mozilla.components.concept.engine.permission.SitePermissions import mozilla.components.concept.engine.permission.SitePermissions.AutoplayStatus import mozilla.components.concept.engine.permission.SitePermissions.Status.ALLOWED @@ -66,7 +67,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a location permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `GIVEN a location permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(location = ALLOWED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_GEOLOCATION) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_GEOLOCATION, geckoPermissions, mock()) @@ -83,7 +84,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a notification permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `GIVEN a notification permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(notification = BLOCKED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_DESKTOP_NOTIFICATION) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_DESKTOP_NOTIFICATION, geckoPermissions, mock()) @@ -100,7 +101,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a localStorage permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `GIVEN a localStorage permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(localStorage = BLOCKED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_PERSISTENT_STORAGE) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_PERSISTENT_STORAGE, geckoPermissions, mock()) @@ -117,7 +118,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a crossOriginStorageAccess permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `GIVEN a crossOriginStorageAccess permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(crossOriginStorageAccess = BLOCKED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_STORAGE_ACCESS) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_STORAGE_ACCESS, geckoPermissions, mock()) @@ -134,7 +135,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a mediaKeySystemAccess permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `GIVEN a mediaKeySystemAccess permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(mediaKeySystemAccess = ALLOWED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_MEDIA_KEY_SYSTEM_ACCESS) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_MEDIA_KEY_SYSTEM_ACCESS, geckoPermissions, mock()) @@ -151,7 +152,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a autoplayInaudible permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `GIVEN a autoplayInaudible permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(autoplayInaudible = AutoplayStatus.ALLOWED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_AUTOPLAY_INAUDIBLE) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_AUTOPLAY_INAUDIBLE, geckoPermissions, mock()) @@ -168,7 +169,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a autoplayAudible permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `GIVEN a autoplayAudible permission WHEN saving THEN the permission is saved in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(autoplayAudible = AutoplayStatus.ALLOWED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_AUTOPLAY_AUDIBLE) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_AUTOPLAY_AUDIBLE, geckoPermissions, mock()) @@ -185,7 +186,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN saving a site permission THEN the permission is saved in the gecko storage and in disk storage`() = runBlockingTest { + fun `WHEN saving a site permission THEN the permission is saved in the gecko storage and in disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(autoplayAudible = AutoplayStatus.ALLOWED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_AUTOPLAY_AUDIBLE) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_AUTOPLAY_AUDIBLE, geckoPermissions, mock()) @@ -199,7 +200,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a temporary permission WHEN saving THEN the permission is saved in memory`() = runBlockingTest { + fun `GIVEN a temporary permission WHEN saving THEN the permission is saved in memory`() = runTest(UnconfinedTestDispatcher()) { val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_AUTOPLAY_AUDIBLE) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_AUTOPLAY_AUDIBLE, geckoPermissions, mock()) @@ -209,7 +210,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN media type temporary permission WHEN saving THEN the permission is NOT saved in memory`() = runBlockingTest { + fun `GIVEN media type temporary permission WHEN saving THEN the permission is NOT saved in memory`() = runTest(UnconfinedTestDispatcher()) { val geckoRequest = GeckoPermissionRequest.Media("mozilla.org", emptyList(), emptyList(), mock()) assertTrue(geckoStorage.geckoTemporaryPermissions.isEmpty()) @@ -220,7 +221,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN multiple saved temporary permissions WHEN clearing all temporary permission THEN all permissions are cleared`() = runBlockingTest { + fun `GIVEN multiple saved temporary permissions WHEN clearing all temporary permission THEN all permissions are cleared`() = runTest(UnconfinedTestDispatcher()) { val geckoAutoPlayPermissions = geckoContentPermission("mozilla.org", PERMISSION_AUTOPLAY_AUDIBLE) val geckoPersistentStoragePermissions = geckoContentPermission("mozilla.org", PERMISSION_PERSISTENT_STORAGE) val geckoStorageAccessPermissions = geckoContentPermission("mozilla.org", PERMISSION_STORAGE_ACCESS) @@ -250,7 +251,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a localStorage permission WHEN updating THEN the permission is updated in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `GIVEN a localStorage permission WHEN updating THEN the permission is updated in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(location = ALLOWED) val geckoPermissions = geckoContentPermission("mozilla.org", PERMISSION_GEOLOCATION) val geckoRequest = GeckoPermissionRequest.Content("mozilla.org", PERMISSION_AUTOPLAY_AUDIBLE, geckoPermissions, mock()) @@ -264,7 +265,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN updating a permission THEN the permission is updated in the gecko storage and on the disk storage`() = runBlockingTest { + fun `WHEN updating a permission THEN the permission is updated in the gecko storage and on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = createNewSitePermission().copy(location = ALLOWED) doReturn(sitePermissions).`when`(geckoStorage).updateGeckoPermissionIfNeeded(sitePermissions) @@ -276,7 +277,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN updating THEN the permission is updated in the gecko storage and set to the default value on the disk storage`() = runBlockingTest { + fun `WHEN updating THEN the permission is updated in the gecko storage and set to the default value on the disk storage`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = SitePermissions( origin = "mozilla.dev", localStorage = ALLOWED, @@ -323,7 +324,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN querying the store by origin THEN the gecko and the on disk storage are queried and results are combined`() = runBlockingTest { + fun `WHEN querying the store by origin THEN the gecko and the on disk storage are queried and results are combined`() = runTest(UnconfinedTestDispatcher()) { val sitePermissions = SitePermissions( origin = "mozilla.dev", localStorage = ALLOWED, @@ -365,7 +366,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN a gecko and on disk permissions WHEN merging values THEN both should be combined into one`() = runBlockingTest { + fun `GIVEN a gecko and on disk permissions WHEN merging values THEN both should be combined into one`() = runTest(UnconfinedTestDispatcher()) { val onDiskPermissions = SitePermissions( origin = "mozilla.dev", localStorage = ALLOWED, @@ -404,7 +405,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `GIVEN permissions that are not present on the gecko storage WHEN merging THEN favor the values on disk permissions`() = runBlockingTest { + fun `GIVEN permissions that are not present on the gecko storage WHEN merging THEN favor the values on disk permissions`() = runTest(UnconfinedTestDispatcher()) { val onDiskPermissions = SitePermissions( origin = "mozilla.dev", localStorage = ALLOWED, @@ -471,7 +472,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN removing a site permissions THEN permissions should be removed from the on disk and gecko storage`() = runBlockingTest { + fun `WHEN removing a site permissions THEN permissions should be removed from the on disk and gecko storage`() = runTest(UnconfinedTestDispatcher()) { val onDiskPermissions = createNewSitePermission() doReturn(Unit).`when`(geckoStorage).removeGeckoContentPermissionBy(onDiskPermissions.origin) @@ -483,7 +484,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN removing gecko permissions THEN permissions should be set to the default values in the gecko storage`() = runBlockingTest { + fun `WHEN removing gecko permissions THEN permissions should be set to the default values in the gecko storage`() = runTest(UnconfinedTestDispatcher()) { val geckoPermissions = listOf( geckoContentPermission(type = PERMISSION_GEOLOCATION), geckoContentPermission(type = PERMISSION_DESKTOP_NOTIFICATION), @@ -511,7 +512,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN removing a temporary permissions THEN the permissions should be remove from memory`() = runBlockingTest { + fun `WHEN removing a temporary permissions THEN the permissions should be remove from memory`() = runTest(UnconfinedTestDispatcher()) { val geckoPermissions = listOf( geckoContentPermission(type = PERMISSION_GEOLOCATION), geckoContentPermission(type = PERMISSION_GEOLOCATION), @@ -539,7 +540,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN removing all THEN all permissions should be removed from the on disk and gecko storage`() = runBlockingTest { + fun `WHEN removing all THEN all permissions should be removed from the on disk and gecko storage`() = runTest(UnconfinedTestDispatcher()) { doReturn(Unit).`when`(geckoStorage).removeGeckoAllContentPermissions() @@ -550,7 +551,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN removing all gecko permissions THEN remove all permissions on gecko and clear the site permissions info`() = runBlockingTest { + fun `WHEN removing all gecko permissions THEN remove all permissions on gecko and clear the site permissions info`() = runTest(UnconfinedTestDispatcher()) { val geckoPermissions = listOf( geckoContentPermission(type = PERMISSION_GEOLOCATION), geckoContentPermission(type = PERMISSION_DESKTOP_NOTIFICATION), @@ -574,7 +575,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN querying all permission THEN the gecko and the on disk storage are queried and results are combined`() = runBlockingTest { + fun `WHEN querying all permission THEN the gecko and the on disk storage are queried and results are combined`() = runTest(UnconfinedTestDispatcher()) { val onDiskPermissions = SitePermissions( origin = "mozilla.dev", localStorage = ALLOWED, @@ -616,7 +617,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN filtering temporary permissions THEN all temporary permissions should be removed`() = runBlockingTest { + fun `WHEN filtering temporary permissions THEN all temporary permissions should be removed`() = runTest(UnconfinedTestDispatcher()) { val temporary = listOf(geckoContentPermission(type = PERMISSION_GEOLOCATION)) val geckoPermissions = listOf( @@ -637,7 +638,7 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN compering two gecko ContentPermissions THEN they are the same when host and permissions are the same`() = runBlockingTest { + fun `WHEN compering two gecko ContentPermissions THEN they are the same when host and permissions are the same`() = runTest(UnconfinedTestDispatcher()) { val location1 = geckoContentPermission(uri = "mozilla.dev", type = PERMISSION_GEOLOCATION) val location2 = geckoContentPermission(uri = "mozilla.dev", type = PERMISSION_GEOLOCATION) val notification = geckoContentPermission(uri = "mozilla.dev", type = PERMISSION_DESKTOP_NOTIFICATION) @@ -647,28 +648,28 @@ class GeckoSitePermissionsStorageTest { } @Test - fun `WHEN converting from gecko status to sitePermissions status THEN they get converted to the equivalent one`() = runBlockingTest { + fun `WHEN converting from gecko status to sitePermissions status THEN they get converted to the equivalent one`() = runTest(UnconfinedTestDispatcher()) { assertEquals(NO_DECISION, VALUE_PROMPT.toStatus()) assertEquals(BLOCKED, VALUE_DENY.toStatus()) assertEquals(ALLOWED, VALUE_ALLOW.toStatus()) } @Test - fun `WHEN converting from gecko status to autoplay sitePermissions status THEN they get converted to the equivalent one`() = runBlockingTest { + fun `WHEN converting from gecko status to autoplay sitePermissions status THEN they get converted to the equivalent one`() = runTest(UnconfinedTestDispatcher()) { assertEquals(AutoplayStatus.BLOCKED, VALUE_PROMPT.toAutoPlayStatus()) assertEquals(AutoplayStatus.BLOCKED, VALUE_DENY.toAutoPlayStatus()) assertEquals(AutoplayStatus.ALLOWED, VALUE_ALLOW.toAutoPlayStatus()) } @Test - fun `WHEN converting a sitePermissions status to gecko status THEN they get converted to the equivalent one`() = runBlockingTest { + fun `WHEN converting a sitePermissions status to gecko status THEN they get converted to the equivalent one`() = runTest(UnconfinedTestDispatcher()) { assertEquals(VALUE_PROMPT, NO_DECISION.toGeckoStatus()) assertEquals(VALUE_DENY, BLOCKED.toGeckoStatus()) assertEquals(VALUE_ALLOW, ALLOWED.toGeckoStatus()) } @Test - fun `WHEN converting from autoplay sitePermissions to gecko status THEN they get converted to the equivalent one`() = runBlockingTest { + fun `WHEN converting from autoplay sitePermissions to gecko status THEN they get converted to the equivalent one`() = runTest(UnconfinedTestDispatcher()) { assertEquals(VALUE_DENY, AutoplayStatus.BLOCKED.toGeckoStatus()) assertEquals(VALUE_ALLOW, AutoplayStatus.ALLOWED.toGeckoStatus()) } diff --git a/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/SystemEngineViewTest.kt b/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/SystemEngineViewTest.kt index 9bb848e628f..bb0a210bc87 100644 --- a/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/SystemEngineViewTest.kt +++ b/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/SystemEngineViewTest.kt @@ -28,6 +28,7 @@ import android.webkit.WebView import android.webkit.WebView.HitTestResult import android.webkit.WebViewClient import android.webkit.WebViewDatabase +import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.runBlocking import mozilla.components.browser.engine.system.matcher.UrlMatcher @@ -918,7 +919,7 @@ class SystemEngineViewTest { val engineView = SystemEngineView(testContext) engineView.render(engineSession) - val view = View(RuntimeEnvironment.systemContext) + val view = View(ApplicationProvider.getApplicationContext()) val customViewCallback = mock() assertNull(engineSession.fullScreenCallback) @@ -939,7 +940,7 @@ class SystemEngineViewTest { val engineView = SystemEngineView(testContext) engineView.render(engineSession) - val view = View(RuntimeEnvironment.systemContext) + val view = View(ApplicationProvider.getApplicationContext()) val customViewCallback = mock() engineSession.webView.tag = "not_webview" @@ -954,7 +955,7 @@ class SystemEngineViewTest { val engineView = SystemEngineView(testContext) engineView.render(engineSession) - val view = View(RuntimeEnvironment.systemContext) + val view = View(ApplicationProvider.getApplicationContext()) val customViewCallback = mock() // When the fullscreen view isn't available