mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
Code review fixes.
This commit is contained in:
parent
792fca8400
commit
5c253bbd28
1 changed files with 13 additions and 7 deletions
|
@ -17,15 +17,16 @@
|
|||
package im.vector.app.core.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.webkit.PermissionRequest
|
||||
import androidx.core.content.ContextCompat.checkSelfPermission
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import org.amshove.kluent.shouldBe
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
|
@ -41,7 +42,6 @@ class CheckWebViewPermissionsUseCaseTest {
|
|||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockKAnnotations.init(this)
|
||||
mockkStatic("androidx.core.content.ContextCompat")
|
||||
}
|
||||
|
||||
|
@ -53,34 +53,33 @@ class CheckWebViewPermissionsUseCaseTest {
|
|||
@Test
|
||||
fun `given an audio permission is granted when the web client requests audio permission then use case returns true`() {
|
||||
val permissionRequest = givenAPermissionRequest(arrayOf(PermissionRequest.RESOURCE_AUDIO_CAPTURE))
|
||||
|
||||
every { checkSelfPermission(activity.applicationContext, any()) } returns PackageManager.PERMISSION_GRANTED
|
||||
|
||||
checkWebViewPermissionsUseCase.execute(activity, permissionRequest) shouldBe true
|
||||
verifyPermissionsChecked(activity.applicationContext, PERMISSIONS_FOR_AUDIO_IP_CALL)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given a camera permission is granted when the web client requests video permission then use case returns true`() {
|
||||
val permissionRequest = givenAPermissionRequest(arrayOf(PermissionRequest.RESOURCE_VIDEO_CAPTURE))
|
||||
|
||||
every { checkSelfPermission(activity.applicationContext, any()) } returns PackageManager.PERMISSION_GRANTED
|
||||
|
||||
checkWebViewPermissionsUseCase.execute(activity, permissionRequest) shouldBe true
|
||||
verifyPermissionsChecked(activity.applicationContext, PERMISSIONS_FOR_VIDEO_IP_CALL)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given an audio and camera permissions are granted when the web client requests audio and video permissions then use case returns true`() {
|
||||
val permissionRequest = givenAPermissionRequest(arrayOf(PermissionRequest.RESOURCE_AUDIO_CAPTURE, PermissionRequest.RESOURCE_VIDEO_CAPTURE))
|
||||
|
||||
every { checkSelfPermission(activity.applicationContext, any()) } returns PackageManager.PERMISSION_GRANTED
|
||||
|
||||
checkWebViewPermissionsUseCase.execute(activity, permissionRequest) shouldBe true
|
||||
verifyPermissionsChecked(activity.applicationContext, PERMISSIONS_FOR_AUDIO_IP_CALL + PERMISSIONS_FOR_VIDEO_IP_CALL)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given an audio permission is granted but camera isn't when the web client requests audio and video permissions then use case returns false`() {
|
||||
val permissionRequest = givenAPermissionRequest(arrayOf(PermissionRequest.RESOURCE_AUDIO_CAPTURE, PermissionRequest.RESOURCE_VIDEO_CAPTURE))
|
||||
|
||||
PERMISSIONS_FOR_AUDIO_IP_CALL.forEach {
|
||||
every { checkSelfPermission(activity.applicationContext, it) } returns PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
@ -89,15 +88,22 @@ class CheckWebViewPermissionsUseCaseTest {
|
|||
}
|
||||
|
||||
checkWebViewPermissionsUseCase.execute(activity, permissionRequest) shouldBe false
|
||||
verifyPermissionsChecked(activity.applicationContext, PERMISSIONS_FOR_AUDIO_IP_CALL + PERMISSIONS_FOR_VIDEO_IP_CALL.first())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given an audio and camera permissions are granted when the web client requests another permission then use case returns false`() {
|
||||
val permissionRequest = givenAPermissionRequest(arrayOf(PermissionRequest.RESOURCE_AUDIO_CAPTURE, PermissionRequest.RESOURCE_MIDI_SYSEX))
|
||||
|
||||
every { checkSelfPermission(activity.applicationContext, any()) } returns PackageManager.PERMISSION_GRANTED
|
||||
|
||||
checkWebViewPermissionsUseCase.execute(activity, permissionRequest) shouldBe false
|
||||
verifyPermissionsChecked(activity.applicationContext, PERMISSIONS_FOR_AUDIO_IP_CALL)
|
||||
}
|
||||
|
||||
private fun verifyPermissionsChecked(context: Context, permissions: List<String>) {
|
||||
permissions.forEach {
|
||||
verify { checkSelfPermission(context, it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun givenAPermissionRequest(resources: Array<String>): PermissionRequest {
|
||||
|
|
Loading…
Reference in a new issue