communicate: add voice pass-3 tests for GV client, SMS and Telecom bridges
- Commit
fff90b8768032a4b9e69f7cd31587f153e13caed- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 12:21 UTC (29 days ago)
- Parents
8312254
Slice (data/googlevoice + data/call + telephony non-RCS) merged INSTRUCTION coverage: 61.7% (11835/19179) on current main, which already includes the separately-committed GoogleVoiceClient transport seam (aa143c1d8, cherry-picked by the lead) and all pass-2 tests. Module total: 44.2% (103574/234468, protobuf classes now excluded); module suite 1214 tests, 0 failures. Adds 3 VoicePass3 test files (12 tests): - googlevoice/GoogleVoiceClientVoicePass3Test: the client over a fake transport replaying recorded protojson - account/threads/ search/thread-messages/calls/voicemails parsing, request URL and header contract, sends/updates/mark-all-read/SIP-info bodies, and 401/403/500 error mapping. No network is touched. - telephony/SmsDeliverVoicePass3Test: full SMS_DELIVER path with a real GSM 03.40 PDU (multipart too) under Robolectric, asserting the conversation notification is posted. - telephony/TelecomConnectionsVoicePass3Test: GoogleVoiceConnection and InAppCallConnection lifecycles, InAppCallConnectionService mirror creation (failed mirrors do not end the call), and the GoogleVoice/InAppCall Telecom account registration surface. No bugs found. 85% slice target not reached: the remainder is SipClient inbound handling (private, hard-coded wss endpoint whose WebSocketClient cannot be faked without a bigger transport refactor), WebRtcAudioSession (native WebRTC), GoogleVoiceWebSender (live WebView bot-token mint), CommunicateInCallService (framework telecom Call objects), and the sync services' credential-gated polling loops (which would touch the real network with the default transport). Verified: gslot ./gradlew :communicate:createMergedCoverageReport. (cherry picked from commit 0c03bd4171d2005658b076cdb00d075c0806d743)
Diff
communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceClientVoicePass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceClientVoicePass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceClientVoicePass3Test.ktnew file mode 100644index 0000000000..b1b03fccca--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceClientVoicePass3Test.kt@@ -0,0 +1,139 @@+package com.vayunmathur.communicate.googlevoice++import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceAuthException+import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceClient+import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceParser+import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceSession+import com.vayunmathur.communicate.data.googlevoice.GvFolder+import com.vayunmathur.library.network.SimpleResponse+import java.io.IOException+import kotlinx.coroutines.runBlocking+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFailsWith+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Voice pass-3: GoogleVoiceClient over a fake transport replaying recorded protojson. */+@RunWith(RobolectricTestRunner::class)+class GoogleVoiceClientVoicePass3Test {++ private val ctx get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ private val threadBody = "[[[\"t.+14152124034\",1,[[\"h1\",1786409649630,\"+12133945548\"," ++ "[\"+14152124034\",\"+14152124034\",null,null,null,null,0],10,1,null,null,null," ++ "\"Hello there\",null,null,5,1,null,\"+14152124034\",0]],null,[[\"+14152124034\"]]]]]"++ private class FakeTransport(var status: Int = 200, var body: String = "") {+ val requests = mutableListOf<Triple<String, Map<String, String>, String>>()+ suspend fun post(url: String, headers: Map<String, String>, requestBody: String): SimpleResponse {+ requests += Triple(url, headers, requestBody)+ return SimpleResponse(status, "fake", body, emptyMap(), url)+ }+ }++ private suspend fun signedInSession(): GoogleVoiceSession {+ val session = GoogleVoiceSession.get(ctx)+ session.save(+ cookieHeader = "SAPISID=sapisid-value; OTHER=x",+ apiKey = "test-api-key",+ authUser = "0",+ )+ return session+ }++ @Test+ fun getAccountParsesAndStoresPhoneNumber() = runBlocking {+ val transport = FakeTransport(body = "[\"+15550001111\",null,[\"settings\"]]")+ val client = GoogleVoiceClient(signedInSession()) { u, h, b -> transport.post(u, h, b) }+ val account = client.getAccount()+ assertEquals("+15550001111", account.phoneNumber)+ assertEquals("+15550001111", GoogleVoiceSession.get(ctx).phoneNumber())+ val (url, headers, _) = transport.requests.single()+ assertTrue(url.contains("account/get"), url)+ assertTrue(url.contains("key=test-api-key"), url)+ assertTrue(headers.containsKey("Authorization"))+ assertEquals("SAPISID=sapisid-value; OTHER=x", headers["Cookie"])+ Unit+ }++ @Test+ fun listAndSearchThreadsParseRecordedBody() = runBlocking {+ val transport = FakeTransport(body = threadBody)+ val client = GoogleVoiceClient(signedInSession()) { u, h, b -> transport.post(u, h, b) }+ val threads = client.listThreads(GvFolder.Inbox)+ assertEquals(1, threads.size)+ assertEquals("+14152124034", threads.first().phoneNumber)+ val searched = client.search("hello")+ assertEquals(1, searched.size)+ assertTrue(transport.requests[0].first.contains("api2thread/list"))+ assertTrue(transport.requests[1].first.contains("api2thread/search"))+ assertTrue(transport.requests[1].third.contains("hello"))+ Unit+ }++ @Test+ fun getThreadFindsMessagesAndFallsBackAcrossFolders() = runBlocking {+ val transport = FakeTransport(body = threadBody)+ val client = GoogleVoiceClient(signedInSession()) { u, h, b -> transport.post(u, h, b) }+ val messages = client.getThread("t.+14152124034")+ assertEquals(1, messages.size)+ assertEquals("Hello there", messages.first().text)+ // Unknown thread: Inbox then All are both consulted, result stays empty+ val none = client.getThread("t.missing")+ assertTrue(none.isEmpty())+ assertTrue(transport.requests.size >= 3)+ Unit+ }++ @Test+ fun listCallsAndVoicemailsHitListEndpoint() = runBlocking {+ val transport = FakeTransport(body = threadBody)+ val client = GoogleVoiceClient(signedInSession()) { u, h, b -> transport.post(u, h, b) }+ client.listCalls()+ client.listVoicemails()+ assertEquals(2, transport.requests.size)+ assertTrue(transport.requests.all { it.first.contains("api2thread/list") })+ Unit+ }++ @Test+ fun sendsAndUpdatesPostExpectedBodies() = runBlocking {+ val transport = FakeTransport(body = "[]")+ val client = GoogleVoiceClient(signedInSession()) { u, h, b -> transport.post(u, h, b) }+ client.sendSms("+1555", "hi there")+ client.sendPreparedSms("[prepared]")+ client.updateThreadAttributes("t.abc", GoogleVoiceParser.ThreadAction.MarkRead)+ client.markVoicemailRead("t.vm")+ client.markAllRead()+ client.getSipRegisterInfo()+ val paths = transport.requests.map { it.first }+ assertTrue(paths[0].contains("api2thread/sendsms"))+ assertEquals("[prepared]", transport.requests[1].third)+ assertTrue(paths[2].contains("thread/batchupdateattributes"))+ assertTrue(paths[4].contains("thread/markallread"))+ assertEquals("[1]", transport.requests[4].third)+ assertTrue(paths[5].contains("sipregisterinfo/get"))+ Unit+ }++ @Test+ fun authAndHttpErrorsMapToExceptions() = runBlocking {+ val session = signedInSession()+ val unauthorized = GoogleVoiceClient(session) { _, _, _ ->+ SimpleResponse(401, "no", "", emptyMap(), "x")+ }+ assertFailsWith<GoogleVoiceAuthException> { unauthorized.getAccount() }+ val forbidden = GoogleVoiceClient(session) { _, _, _ ->+ SimpleResponse(403, "no", "", emptyMap(), "x")+ }+ assertFailsWith<GoogleVoiceAuthException> { forbidden.listThreads() }+ val serverError = GoogleVoiceClient(session) { _, _, _ ->+ SimpleResponse(500, "err", "boom", emptyMap(), "x")+ }+ assertFailsWith<IOException> { serverError.getAccount() }+ Unit+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/SmsDeliverVoicePass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/SmsDeliverVoicePass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/SmsDeliverVoicePass3Test.ktnew file mode 100644index 0000000000..bf5ec3df28--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/SmsDeliverVoicePass3Test.kt@@ -0,0 +1,61 @@+package com.vayunmathur.communicate.telephony++import android.app.NotificationManager+import android.content.Context+import android.content.Intent+import android.provider.Telephony+import androidx.test.core.app.ApplicationProvider+import kotlin.test.Test+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.Shadows.shadowOf++/** Voice pass-3: full SMS_DELIVER path with a real GSM PDU under Robolectric. */+@RunWith(RobolectricTestRunner::class)+class SmsDeliverVoicePass3Test {++ private val context get() = ApplicationProvider.getApplicationContext<Context>()++ private fun hexToBytes(hex: String): ByteArray =+ ByteArray(hex.length / 2) { hex.substring(it * 2, it * 2 + 2).toInt(16).toByte() }++ // GSM 03.40 example SMS-DELIVER PDU ("hellohello" from +46708251355)+ private val pduHex = "07916407058099F9040B916407281553F80000993092516195800AE8329BFD4697D9EC37"++ @Test+ fun deliverWithValidPduStoresAndNotifies() {+ val intent = Intent(Telephony.Sms.Intents.SMS_DELIVER_ACTION).apply {+ putExtra("pdus", arrayOf(hexToBytes(pduHex)))+ putExtra("format", "3gpp")+ putExtra("subscription", 1)+ }+ val receiver = SmsDeliverReceiver()+ receiver.onReceive(context, intent)++ // Storage runs on the receiver's background thread; poll for the notification.+ val nm = context.getSystemService(NotificationManager::class.java)+ val deadline = System.currentTimeMillis() + 10_000+ var notified = false+ while (System.currentTimeMillis() < deadline) {+ if (shadowOf(nm).allNotifications.isNotEmpty()) {+ notified = true+ break+ }+ Thread.sleep(50)+ }+ assertTrue(notified, "inbound SMS should post a conversation notification")+ }++ @Test+ fun deliverWithMultipartPduConcatenates() {+ val intent = Intent(Telephony.Sms.Intents.SMS_DELIVER_ACTION).apply {+ putExtra("pdus", arrayOf(hexToBytes(pduHex), hexToBytes(pduHex)))+ putExtra("format", "3gpp")+ }+ SmsDeliverReceiver().onReceive(context, intent)+ // No assertion on the provider (Robolectric has none); reaching here without+ // throwing on the caller thread is the contract, storage is best-effort async.+ Thread.sleep(300)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/TelecomConnectionsVoicePass3Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/TelecomConnectionsVoicePass3Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/TelecomConnectionsVoicePass3Test.ktnew file mode 100644index 0000000000..8e52bedbe5--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/TelecomConnectionsVoicePass3Test.kt@@ -0,0 +1,151 @@+package com.vayunmathur.communicate.telephony++import android.content.ComponentName+import android.net.Uri+import android.os.Bundle+import android.telecom.Connection+import android.telecom.ConnectionRequest+import android.telecom.PhoneAccountHandle+import android.telecom.TelecomManager+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.data.call.CallCapabilities+import com.vayunmathur.communicate.data.call.InAppCallController+import com.vayunmathur.communicate.data.call.InAppCallPhase+import com.vayunmathur.communicate.data.call.InAppCallRegistry+import com.vayunmathur.communicate.data.googlevoice.call.GoogleVoiceCallManager+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner++/** Voice pass-3: Telecom Connection/ConnectionService bridges for GV and in-app calls. */+@RunWith(RobolectricTestRunner::class)+class TelecomConnectionsVoicePass3Test {++ private val ctx get() = ApplicationProvider.getApplicationContext<android.content.Context>()+ private val actions = mutableListOf<String>()+ private val controller = object : InAppCallController {+ override fun answer() { actions += "answer" }+ override fun reject() { actions += "reject" }+ override fun hangup() { actions += "hangup" }+ override fun setMuted(muted: Boolean) { actions += "muted=$muted" }+ override fun setSpeaker(on: Boolean) { actions += "speaker=$on" }+ }++ @BeforeTest+ fun setUp() {+ actions.clear()+ InAppCallRegistry.onEnded("reset")+ InAppCallRegistry.clearEnded()+ InAppCallRegistry.videoController = null+ InAppCallRegistry.dtmfController = null+ InAppCallRegistry.holdController = null+ InAppCallRegistry.connection = null+ GoogleVoiceCallManager.connection = null+ }++ private fun handle(serviceClass: Class<*>) =+ PhoneAccountHandle(ComponentName(ctx, serviceClass), "acct")++ @Test+ fun googleVoiceConnectionLifecycle() {+ val connection = GoogleVoiceConnection()+ assertTrue(connection.audioModeIsVoip)+ assertTrue(connection.connectionCapabilities and Connection.CAPABILITY_MUTE != 0)+ assertTrue(connection.connectionCapabilities and Connection.CAPABILITY_SUPPORT_HOLD != 0)+ connection.onCallActive()+ assertEquals(Connection.STATE_ACTIVE, connection.state)+ // DTMF and answer without an initialized manager are no-ops+ connection.onPlayDtmfTone('5')+ connection.onAnswer()++ val rejected = GoogleVoiceConnection()+ rejected.onReject()+ assertEquals(Connection.STATE_DISCONNECTED, rejected.state)++ val disconnected = GoogleVoiceConnection()+ disconnected.onDisconnect()+ assertEquals(Connection.STATE_DISCONNECTED, disconnected.state)++ val aborted = GoogleVoiceConnection()+ aborted.onAbort()+ assertEquals(Connection.STATE_DISCONNECTED, aborted.state)++ val ended = GoogleVoiceConnection()+ ended.onCallEnded()+ assertEquals(Connection.STATE_DISCONNECTED, ended.state)+ }++ @Test+ fun inAppCallConnectionBridgesToRegistry() {+ InAppCallRegistry.bind(CommunicateLine.Signal, controller, CallCapabilities.AudioOnly)+ InAppCallRegistry.onCallStarting(CommunicateLine.Signal, "peer-1", "Pat Lee", false, incoming = false)+ val connection = InAppCallConnection()+ connection.onMuteStateChanged(true)+ assertEquals(listOf("muted=true"), actions.toList())+ assertTrue(InAppCallRegistry.state.value.muted)+ // Same mute state again: no toggle back+ connection.onMuteStateChanged(true)+ assertEquals(listOf("muted=true"), actions.toList())++ connection.onCallActive()+ assertEquals(Connection.STATE_ACTIVE, connection.state)++ val disconnecting = InAppCallConnection()+ disconnecting.onDisconnect()+ assertEquals("hangup", actions.last())+ assertEquals(Connection.STATE_DISCONNECTED, disconnecting.state)++ val ending = InAppCallConnection()+ ending.onCallEnded()+ assertEquals(Connection.STATE_DISCONNECTED, ending.state)+ }++ @Test+ fun inAppCallConnectionServiceCreatesMirrors() {+ InAppCallRegistry.bind(CommunicateLine.Signal, controller, CallCapabilities.AudioOnly)+ InAppCallRegistry.onCallStarting(CommunicateLine.Signal, "peer-1", "Pat Lee", false, incoming = false)+ val service = Robolectric.setupService(InAppCallConnectionService::class.java)+ val outgoing = service.onCreateOutgoingConnection(+ handle(InAppCallConnectionService::class.java),+ ConnectionRequest(handle(InAppCallConnectionService::class.java), Uri.fromParts("sip", "peer-1", null), Bundle()),+ )+ assertEquals(Connection.STATE_DIALING, outgoing.state)+ assertTrue(outgoing.connectionProperties and Connection.PROPERTY_SELF_MANAGED != 0)+ assertTrue(InAppCallRegistry.connection === outgoing)++ val incoming = service.onCreateIncomingConnection(handle(InAppCallConnectionService::class.java), null)+ assertEquals(Connection.STATE_RINGING, incoming.state)+ assertTrue(InAppCallRegistry.connection === incoming)++ // Failed mirrors must not end the underlying call+ service.onCreateOutgoingConnectionFailed(handle(InAppCallConnectionService::class.java), null)+ service.onCreateIncomingConnectionFailed(handle(InAppCallConnectionService::class.java), null)+ assertTrue(actions.isEmpty())+ service.onDestroy()+ }++ @Test+ fun telecomAccountHandlesAndRegistration() {+ val gvHandle = GoogleVoiceTelecom.handle(ctx)+ assertEquals("google_voice_line", gvHandle.id)+ GoogleVoiceTelecom.registerPhoneAccount(ctx, "+1 555 0001")+ GoogleVoiceTelecom.placeOutgoing(ctx, "+15559999")+ GoogleVoiceTelecom.addIncoming(ctx, "+15551234")+ GoogleVoiceTelecom.unregisterPhoneAccount(ctx)++ val inAppHandle = InAppCallTelecom.handle(ctx)+ assertEquals("communicate_inapp_calls", inAppHandle.id)+ assertTrue(gvHandle != inAppHandle)+ InAppCallTelecom.registerPhoneAccount(ctx, "Calls")+ InAppCallTelecom.addOutgoing(ctx, "peer-1")+ InAppCallTelecom.addIncoming(ctx, "peer-1")+ InAppCallTelecom.unregisterPhoneAccount(ctx)+ assertEquals(InAppCallConnectionService::class.java.name, inAppHandle.componentName.className)+ assertEquals(GoogleVoiceConnectionService::class.java.name, gvHandle.componentName.className)+ }+}