CallIntentDataParser is now a class.
This commit is contained in:
parent
9541389519
commit
c96ad7addc
3 changed files with 22 additions and 18 deletions
|
|
@ -18,8 +18,9 @@ package io.element.android.features.call
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
object CallIntentDataParser {
|
class CallIntentDataParser @Inject constructor() {
|
||||||
|
|
||||||
private val validHttpSchemes = sequenceOf("http", "https")
|
private val validHttpSchemes = sequenceOf("http", "https")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import javax.inject.Inject
|
||||||
class ElementCallActivity : ComponentActivity() {
|
class ElementCallActivity : ComponentActivity() {
|
||||||
|
|
||||||
@Inject lateinit var userAgentProvider: UserAgentProvider
|
@Inject lateinit var userAgentProvider: UserAgentProvider
|
||||||
|
@Inject lateinit var callIntentDataParser: CallIntentDataParser
|
||||||
|
|
||||||
private lateinit var audioManager: AudioManager
|
private lateinit var audioManager: AudioManager
|
||||||
|
|
||||||
|
|
@ -129,7 +130,7 @@ class ElementCallActivity : ComponentActivity() {
|
||||||
finishAndRemoveTask()
|
finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseUrl(url: String?): String? = CallIntentDataParser.parse(url)
|
private fun parseUrl(url: String?): String? = callIntentDataParser.parse(url)
|
||||||
|
|
||||||
private fun registerPermissionResultLauncher(): ActivityResultLauncher<Array<String>> {
|
private fun registerPermissionResultLauncher(): ActivityResultLauncher<Array<String>> {
|
||||||
return registerForActivityResult(
|
return registerForActivityResult(
|
||||||
|
|
|
||||||
|
|
@ -25,28 +25,30 @@ import java.net.URLEncoder
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
class CallIntentDataParserTests {
|
class CallIntentDataParserTests {
|
||||||
|
|
||||||
|
private val callIntentDataParser = CallIntentDataParser()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a null data returns null`() {
|
fun `a null data returns null`() {
|
||||||
val url: String? = null
|
val url: String? = null
|
||||||
assertThat(CallIntentDataParser.parse(url)).isNull()
|
assertThat(callIntentDataParser.parse(url)).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `empty data returns null`() {
|
fun `empty data returns null`() {
|
||||||
val url = ""
|
val url = ""
|
||||||
assertThat(CallIntentDataParser.parse(url)).isNull()
|
assertThat(callIntentDataParser.parse(url)).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `invalid data returns null`() {
|
fun `invalid data returns null`() {
|
||||||
val url = "!"
|
val url = "!"
|
||||||
assertThat(CallIntentDataParser.parse(url)).isNull()
|
assertThat(callIntentDataParser.parse(url)).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `data with no scheme returns null`() {
|
fun `data with no scheme returns null`() {
|
||||||
val url = "test"
|
val url = "test"
|
||||||
assertThat(CallIntentDataParser.parse(url)).isNull()
|
assertThat(callIntentDataParser.parse(url)).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -55,10 +57,10 @@ class CallIntentDataParserTests {
|
||||||
val httpCallUrl = "http://call.element.io/some-actual-call?with=parameters"
|
val httpCallUrl = "http://call.element.io/some-actual-call?with=parameters"
|
||||||
val httpsBaseUrl = "https://call.element.io"
|
val httpsBaseUrl = "https://call.element.io"
|
||||||
val httpsCallUrl = "https://call.element.io/some-actual-call?with=parameters"
|
val httpsCallUrl = "https://call.element.io/some-actual-call?with=parameters"
|
||||||
assertThat(CallIntentDataParser.parse(httpBaseUrl)).isEqualTo(httpBaseUrl)
|
assertThat(callIntentDataParser.parse(httpBaseUrl)).isEqualTo(httpBaseUrl)
|
||||||
assertThat(CallIntentDataParser.parse(httpCallUrl)).isEqualTo(httpCallUrl)
|
assertThat(callIntentDataParser.parse(httpCallUrl)).isEqualTo(httpCallUrl)
|
||||||
assertThat(CallIntentDataParser.parse(httpsBaseUrl)).isEqualTo(httpsBaseUrl)
|
assertThat(callIntentDataParser.parse(httpsBaseUrl)).isEqualTo(httpsBaseUrl)
|
||||||
assertThat(CallIntentDataParser.parse(httpsCallUrl)).isEqualTo(httpsCallUrl)
|
assertThat(callIntentDataParser.parse(httpsCallUrl)).isEqualTo(httpsCallUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -67,10 +69,10 @@ class CallIntentDataParserTests {
|
||||||
val httpsBaseUrl = "https://app.element.io"
|
val httpsBaseUrl = "https://app.element.io"
|
||||||
val httpInvalidUrl = "http://"
|
val httpInvalidUrl = "http://"
|
||||||
val httpsInvalidUrl = "http://"
|
val httpsInvalidUrl = "http://"
|
||||||
assertThat(CallIntentDataParser.parse(httpBaseUrl)).isNull()
|
assertThat(callIntentDataParser.parse(httpBaseUrl)).isNull()
|
||||||
assertThat(CallIntentDataParser.parse(httpsBaseUrl)).isNull()
|
assertThat(callIntentDataParser.parse(httpsBaseUrl)).isNull()
|
||||||
assertThat(CallIntentDataParser.parse(httpInvalidUrl)).isNull()
|
assertThat(callIntentDataParser.parse(httpInvalidUrl)).isNull()
|
||||||
assertThat(CallIntentDataParser.parse(httpsInvalidUrl)).isNull()
|
assertThat(callIntentDataParser.parse(httpsInvalidUrl)).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -78,7 +80,7 @@ class CallIntentDataParserTests {
|
||||||
val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters"
|
val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters"
|
||||||
val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8")
|
val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8")
|
||||||
val url = "element://call?url=$encodedUrl"
|
val url = "element://call?url=$encodedUrl"
|
||||||
assertThat(CallIntentDataParser.parse(url)).isEqualTo(embeddedUrl)
|
assertThat(callIntentDataParser.parse(url)).isEqualTo(embeddedUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -86,7 +88,7 @@ class CallIntentDataParserTests {
|
||||||
val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters"
|
val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters"
|
||||||
val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8")
|
val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8")
|
||||||
val url = "element://call?no-url=$encodedUrl"
|
val url = "element://call?no-url=$encodedUrl"
|
||||||
assertThat(CallIntentDataParser.parse(url)).isNull()
|
assertThat(callIntentDataParser.parse(url)).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -94,12 +96,12 @@ class CallIntentDataParserTests {
|
||||||
val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters"
|
val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters"
|
||||||
val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8")
|
val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8")
|
||||||
val url = "element://no-call?url=$encodedUrl"
|
val url = "element://no-call?url=$encodedUrl"
|
||||||
assertThat(CallIntentDataParser.parse(url)).isNull()
|
assertThat(callIntentDataParser.parse(url)).isNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `element scheme with no data returns null`() {
|
fun `element scheme with no data returns null`() {
|
||||||
val url = "element://call?url="
|
val url = "element://call?url="
|
||||||
assertThat(CallIntentDataParser.parse(url)).isNull()
|
assertThat(callIntentDataParser.parse(url)).isNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue