communicate: add slice-4 pass-2 tests for calls, GV, RCS dialog and services
- Commit
c5e12455a432cefa83263959555f106721187dab- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 07:43 UTC (29 days ago)
- Parents
09702e3
Slice 4/6 (googlevoice/, car/, call/ and other subpackages) merged INSTRUCTION coverage, by package prefix: 32.9% (11056/33644) -> 52.3% (17597/33644); classes at >=85%: 36/76 -> 44/76. Full module suite: 1082 tests, 0 failures. Adds 14 Slice4Pass2 test files: - ui/call/InAppCallScreenSlice4Pass2Test: full call screen in Idle/Incoming/Outgoing/Active-keypad/Active-video/Ended phases via InAppCallRegistry (answer/hangup/DTMF fan-out, ended auto-close). - telephony/ForegroundServices + SyncServices: FG answer/hangup (reject-while-ringing), sync stop/null-start/timeout contracts. - telephony/RcsDialogSlice4Pass2Test: real SipMessage inbound dialog handlers (INVITE/BYE/NOTIFY/SUBSCRIBE/UPDATE/OPTIONS/REFER response builders) - enabled by a test-only aosp-stubs dependency (communicate/build.gradle.kts); Robolectric supplies the real SipMessage at runtime. - telephony/RcsInboundParseSlice4Pass2Test, SimCallBridgeSlice4Pass2Test, DeliverReceiversSlice4Pass2Test (downloaded MMS parse + cleanup, WAP push), GoogleVoiceConnectionServiceSlice4Pass2Test (self-managed Telecom connections), MiscServicesSlice4Pass2Test (car app service), notifications/BubbleActivitySlice4Pass2Test. - googlevoice: client auth guard (every RPC fails fast with no session), call-manager state without a live leg, SipClient offline message building, GV sign-in screen rendering. No production changes; no bugs found. 85% slice target not reached: remaining uncovered code is live-stack only - RcsSyncService/RCS session internals behind the IMS SipDelegate, WebRtcAudioSession (native WebRTC), SipClient inbound handling (private, hard-coded wss endpoint), car screens (need a CarContext host), GoogleVoice WebSender (WebView bot-token mint with 60s live page), and CommunicateInCallService (needs framework telecom Call objects). Verified: gslot ./gradlew :communicate:testDevUnitTest (via createMergedCoverageReport, 1082 tests green). (cherry picked from commit 78e532dcdc077e54f3cd5945158073579548149c)
Diff
communicate/build.gradle.kts
diff --git a/communicate/build.gradle.kts b/communicate/build.gradle.ktsindex df2cb48b82..882500490a 100644--- a/communicate/build.gradle.kts+++ b/communicate/build.gradle.kts@@ -222,6 +222,9 @@ dependencies { // on the JVM; same reason emergency/pdf use it. testImplementation(libs.robolectric) testImplementation(libs.androidx.test.core)+ // Compile-only hidden-API stubs (SipMessage etc.) so RCS inbound tests can reference+ // them; Robolectric's android-all supplies the real implementations at runtime.+ testImplementation(project(":library:aosp-stubs")) // Route slice-6 contract tests use KClass reflection (sealedSubclasses, constructors). testImplementation(libs.kotlin.reflect) // RCS slice tests: real in-memory Room database via the bundled sqlite driver
communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceCallManagerSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceCallManagerSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceCallManagerSlice4Pass2Test.ktnew file mode 100644index 0000000000..0de740eb62--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceCallManagerSlice4Pass2Test.kt@@ -0,0 +1,46 @@+package com.vayunmathur.communicate.googlevoice++import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.data.googlevoice.call.CallPhase+import com.vayunmathur.communicate.data.googlevoice.call.GoogleVoiceCallManager+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: GV call manager state transitions that need no live SIP/WebRTC leg. */+@RunWith(RobolectricTestRunner::class)+class GoogleVoiceCallManagerSlice4Pass2Test {++ @Test+ fun muteAndSpeakerUpdateStateWithoutAudioSession() {+ GoogleVoiceCallManager.stopRegistration()+ assertEquals(CallPhase.Idle, GoogleVoiceCallManager.state.value.phase)+ GoogleVoiceCallManager.setMuted(true)+ assertEquals(true, GoogleVoiceCallManager.state.value.muted)+ GoogleVoiceCallManager.setSpeaker(true)+ assertEquals(true, GoogleVoiceCallManager.state.value.speaker)+ GoogleVoiceCallManager.setMuted(false)+ GoogleVoiceCallManager.setSpeaker(false)+ assertFalse(GoogleVoiceCallManager.state.value.muted)+ assertFalse(GoogleVoiceCallManager.state.value.speaker)+ // DTMF with no audio session is a no-op (must not throw)+ GoogleVoiceCallManager.sendDtmf("5")+ }++ @Test+ fun actionsBeforeInitAreSafeAndStopResetsState() {+ val ctx = ApplicationProvider.getApplicationContext<android.content.Context>()+ GoogleVoiceCallManager.init(ctx)+ GoogleVoiceCallManager.init(ctx) // idempotent+ GoogleVoiceCallManager.setMuted(true)+ GoogleVoiceCallManager.stopRegistration()+ val state = GoogleVoiceCallManager.state.value+ assertEquals(CallPhase.Idle, state.phase)+ assertFalse(state.muted)+ // Clear-ended on an idle state keeps it idle+ GoogleVoiceCallManager.clearEnded()+ assertEquals(CallPhase.Idle, GoogleVoiceCallManager.state.value.phase)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceClientSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceClientSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceClientSlice4Pass2Test.ktnew file mode 100644index 0000000000..72afbbf8de--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/GoogleVoiceClientSlice4Pass2Test.kt@@ -0,0 +1,51 @@+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 kotlinx.coroutines.runBlocking+import kotlin.test.Test+import kotlin.test.assertFailsWith+import kotlin.test.assertNotNull+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: GV client auth guard — every RPC fails fast with no session, before any network. */+@RunWith(RobolectricTestRunner::class)+class GoogleVoiceClientSlice4Pass2Test {++ private val ctx get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ @Test+ fun clientGetReturnsUsableInstance() {+ val client = GoogleVoiceClient.get(ctx)+ assertNotNull(client)+ assertNotNull(GoogleVoiceSession.get(ctx))+ }++ @Test+ fun everyRpcThrowsAuthWithoutCredentials() = runBlocking {+ val client = GoogleVoiceClient(GoogleVoiceSession.get(ctx))+ // Ensure no credentials are present in this fresh Robolectric store.+ assertFailsWith<GoogleVoiceAuthException> { client.getAccount() }+ assertFailsWith<GoogleVoiceAuthException> { client.listThreads(GvFolder.Inbox) }+ assertFailsWith<GoogleVoiceAuthException> { client.listThreads() }+ assertFailsWith<GoogleVoiceAuthException> { client.getThread("remote-1") }+ assertFailsWith<GoogleVoiceAuthException> { client.search("hello") }+ assertFailsWith<GoogleVoiceAuthException> { client.listCalls() }+ assertFailsWith<GoogleVoiceAuthException> { client.listVoicemails() }+ assertFailsWith<GoogleVoiceAuthException> { client.markVoicemailRead("remote-1") }+ assertFailsWith<GoogleVoiceAuthException> { client.sendSms("+1555", "hi") }+ assertFailsWith<GoogleVoiceAuthException> { client.sendSms("+1555", "hi", "thread-1") }+ assertFailsWith<GoogleVoiceAuthException> { client.sendPreparedSms("{}") }+ assertFailsWith<GoogleVoiceAuthException> {+ client.updateThreadAttributes("remote-1", GoogleVoiceParser.ThreadAction.MarkRead)+ }+ assertFailsWith<GoogleVoiceAuthException> { client.markAllRead() }+ assertFailsWith<GoogleVoiceAuthException> { client.getSipRegisterInfo() }+ Unit+ }+}
communicate/src/test/java/com/vayunmathur/communicate/googlevoice/SipClientSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/SipClientSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/SipClientSlice4Pass2Test.ktnew file mode 100644index 0000000000..6e70e0a2a8--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/googlevoice/SipClientSlice4Pass2Test.kt@@ -0,0 +1,74 @@+package com.vayunmathur.communicate.googlevoice++import com.vayunmathur.communicate.data.googlevoice.GvSipRegisterInfo+import com.vayunmathur.communicate.data.googlevoice.call.SipClient+import com.vayunmathur.communicate.data.googlevoice.call.randomToken+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.runBlocking+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: SipClient message-building paths with no socket connected (send is a no-op). */+@RunWith(RobolectricTestRunner::class)+class SipClientSlice4Pass2Test {++ private val events = mutableListOf<String>()+ private val listener = object : SipClient.Listener {+ override fun onRegistered() { events += "registered" }+ override fun onProvisional(code: Int) { events += "prov:$code" }+ override fun onAnswered(remoteSdp: String) { events += "answered" }+ override fun onEarlyMedia(remoteSdp: String) { events += "early" }+ override fun onEnded() { events += "ended" }+ override fun onFailed(reason: String) { events += "failed:$reason" }+ override fun onIncomingInvite(remoteSdp: String, from: String) { events += "invite:$from" }+ }++ private fun client(credentials: List<String> = listOf("user=1", "secret")): SipClient {+ val info = GvSipRegisterInfo(phoneNumber = "+15550001", credentials = credentials)+ return SipClient(info, "+15550001", CoroutineScope(Dispatchers.Unconfined), listener)+ }++ @Test+ fun clientDerivesAuthIdentityFromCredentials() {+ val c = client()+ assertEquals("user=1", c.authUsername)+ assertEquals("secret", c.authPassword)+ assertEquals("user%3D1", c.aorUser)+ assertTrue(c.localHost.endsWith(".invalid"))+ assertTrue(c.callId.isNotBlank())+ assertEquals(8, c.contactUser.length)+ // No credentials: falls back to the GV number and a blank password+ val bare = client(emptyList())+ assertEquals("+15550001", bare.authUsername)+ assertEquals("", bare.authPassword)+ }++ @Test+ fun outboundRequestsBuildWithoutSocket() = runBlocking {+ val c = client()+ c.register()+ c.register(expires = 600, authHeader = "Digest abc")+ c.invite("+15559999", "v=0\r\no=- 1 1 IN IP4 0.0.0.0\r\nm=audio 9 RTP/AVP 0\r\n")+ c.ack("+15559999")+ c.bye("+15559999")+ c.answerInbound("v=0 answer")+ c.declineInbound()+ c.close()+ c.close() // idempotent+ // Nothing was connected, so no listener callbacks should have fired+ assertEquals(emptyList(), events.toList())+ Unit+ }++ @Test+ fun randomTokenShape() {+ val token = randomToken(16)+ assertEquals(16, token.length)+ assertTrue(token.all { it.isLowerCase() || it.isDigit() })+ assertEquals(1, randomToken(1).length)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/notifications/BubbleActivitySlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/notifications/BubbleActivitySlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/notifications/BubbleActivitySlice4Pass2Test.ktnew file mode 100644index 0000000000..336dbcd0b1--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/notifications/BubbleActivitySlice4Pass2Test.kt@@ -0,0 +1,51 @@+package com.vayunmathur.communicate.notifications++import android.content.Intent+import androidx.test.core.app.ApplicationProvider+import kotlin.test.Test+import kotlin.test.assertNotNull+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config++/** Slice-4 pass-2: bubble activity intent parsing (line fallback, extras) under Robolectric. */+@RunWith(RobolectricTestRunner::class)+@Config(sdk = [34])+class BubbleActivitySlice4Pass2Test {++ private val ctx get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ @Test+ fun activityCreatesWithSimExtras() {+ val intent = Intent(ctx, BubbleActivity::class.java).apply {+ putExtra(ConversationSpace.EXTRA_LINE, "Sim")+ putExtra(ConversationSpace.EXTRA_ADDRESS, "+1555")+ putExtra(ConversationSpace.EXTRA_THREAD_ID, 7L)+ putExtra(ConversationSpace.EXTRA_TITLE, "Pat")+ putExtra(ConversationSpace.EXTRA_SUB_ID, 2)+ putExtra(ConversationSpace.EXTRA_IS_GROUP, false)+ }+ val controller = Robolectric.buildActivity(BubbleActivity::class.java, intent).setup()+ assertNotNull(controller.get())+ controller.pause().stop().destroy()+ }++ @Test+ fun activityCreatesWithBogusLineFallingBackToSim() {+ val intent = Intent(ctx, BubbleActivity::class.java).apply {+ putExtra(ConversationSpace.EXTRA_LINE, "NotALine")+ putExtra(ConversationSpace.EXTRA_ADDRESS, "+1999")+ }+ val controller = Robolectric.buildActivity(BubbleActivity::class.java, intent).setup()+ assertNotNull(controller.get())+ controller.pause().stop().destroy()+ }++ @Test+ fun activityCreatesWithNoExtras() {+ val controller = Robolectric.buildActivity(BubbleActivity::class.java, Intent(ctx, BubbleActivity::class.java)).setup()+ assertNotNull(controller.get())+ controller.pause().stop().destroy()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/DeliverReceiversSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/DeliverReceiversSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/DeliverReceiversSlice4Pass2Test.ktnew file mode 100644index 0000000000..fe7f993800--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/DeliverReceiversSlice4Pass2Test.kt@@ -0,0 +1,114 @@+package com.vayunmathur.communicate.telephony++import android.content.Intent+import android.provider.Telephony+import androidx.test.core.app.ApplicationProvider+import java.io.File+import kotlin.test.Test+import kotlin.test.assertFalse+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: MMS downloaded-file handling and push triggering in [MmsDeliverReceiver]. */+@RunWith(RobolectricTestRunner::class)+class DeliverReceiversSlice4Pass2Test {++ private val context get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ /** Minimal hand-built M-Retrieve.conf (mirrors MmsPduReaderSlice4Test's builder). */+ private fun retrieveConf(from: String = "+1555/TYPE=PLMN", text: String = "hello mms"): ByteArray {+ val out = mutableListOf<Byte>()+ fun b(v: Int) = out.add(v.toByte())+ b(0x8C); b(0x84)+ val fromText = from.toByteArray(Charsets.UTF_8).toList() + listOf(0.toByte())+ val fromInner = listOf(0xEA.toByte()) + fromText+ val fromBody = listOf(fromInner.size.toByte()) + fromInner+ b(0x89)+ b(fromBody.size + 1)+ b(0x80)+ out.addAll(fromBody)+ b(0x84); b(0xA1)+ val textBytes = text.toByteArray(Charsets.UTF_8)+ val ctAndLoc = byteArrayOf(0x83.toByte()) ++ byteArrayOf(0x8E.toByte()) + "p.txt".toByteArray(Charsets.UTF_8) + byteArrayOf(0x00)+ b(0x01)+ b(ctAndLoc.size)+ b(textBytes.size)+ out.addAll(ctAndLoc.toList())+ out.addAll(textBytes.toList())+ return out.toByteArray()+ }++ private fun awaitDeleted(file: File, timeoutMs: Long = 10_000) {+ val deadline = System.currentTimeMillis() + timeoutMs+ while (System.currentTimeMillis() < deadline) {+ if (!file.exists()) return+ Thread.sleep(50)+ }+ assertFalse(file.exists(), "downloaded MMS file should be cleaned up")+ }++ @Test+ fun downloadedMmsFileIsParsedAndCleanedUp() {+ val file = File.createTempFile("mms_in_", ".pdu", context.cacheDir)+ file.writeBytes(retrieveConf())+ val receiver = MmsDeliverReceiver()+ receiver.onReceive(+ context,+ Intent("com.vayunmathur.communicate.MMS_DOWNLOADED").apply {+ putExtra("file", file.absolutePath)+ },+ )+ awaitDeleted(file)+ }++ @Test+ fun downloadedMissingFileExtraIsIgnored() {+ val receiver = MmsDeliverReceiver()+ receiver.onReceive(context, Intent("com.vayunmathur.communicate.MMS_DOWNLOADED"))+ // Nonexistent path: the worker thread swallows the read failure.+ val ghost = File(context.cacheDir, "nope_${System.nanoTime()}.pdu")+ receiver.onReceive(+ context,+ Intent("com.vayunmathur.communicate.MMS_DOWNLOADED").apply {+ putExtra("file", ghost.absolutePath)+ },+ )+ assertFalse(ghost.exists())+ }++ @Test+ fun pushWithContentLocationAttemptsDownload() {+ val pdu = byteArrayOf(+ 0x8C.toByte(), 0x82.toByte(),+ 0x98.toByte(), 0x74, 0x31, 0x00,+ 0x83.toByte(),+ *"http://mms.example/x".toByteArray(Charsets.UTF_8), 0x00,+ )+ val receiver = MmsDeliverReceiver()+ // SmsManager.downloadMultimediaMessage is a shadow no-op under Robolectric;+ // the contract is that a located push does not throw and creates its staging dir.+ receiver.onReceive(+ context,+ Intent(Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION).apply {+ putExtra("data", pdu)+ },+ )+ assertTrue(File(context.cacheDir, "mms").isDirectory)+ }++ @Test+ fun pushWithoutContentLocationReturnsEarly() {+ val pdu = byteArrayOf(+ 0x8C.toByte(), 0x82.toByte(),+ 0x98.toByte(), 0x74, 0x31, 0x00,+ )+ MmsDeliverReceiver().onReceive(+ context,+ Intent(Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION).apply {+ putExtra("data", pdu)+ },+ )+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/ForegroundServicesSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/ForegroundServicesSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/ForegroundServicesSlice4Pass2Test.ktnew file mode 100644index 0000000000..0c08b792d4--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/ForegroundServicesSlice4Pass2Test.kt@@ -0,0 +1,114 @@+package com.vayunmathur.communicate.telephony++import android.app.Service+import android.content.Intent+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 kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: foreground call services driven through their start actions under Robolectric. */+@RunWith(RobolectricTestRunner::class)+class ForegroundServicesSlice4Pass2Test {++ 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+ }++ private fun startIncomingCall() {+ InAppCallRegistry.bind(CommunicateLine.Signal, controller, CallCapabilities.AudioOnly)+ InAppCallRegistry.onCallStarting(CommunicateLine.Signal, "peer-1", "Pat Lee", false, incoming = true)+ }++ @Test+ fun inAppCallServiceAnswerActionAnswersAndBindsNothing() {+ startIncomingCall()+ val service = Robolectric.setupService(InAppCallForegroundService::class.java)+ assertNull(service.onBind(Intent()))+ val result = service.onStartCommand(+ Intent().apply { action = "com.vayunmathur.communicate.inappcall.ANSWER_CALL" }, 0, 1,+ )+ assertEquals(Service.START_STICKY, result)+ assertEquals(listOf("answer"), actions.toList())+ service.onDestroy()+ }++ @Test+ fun inAppCallServiceHangupRejectsWhileIncoming() {+ startIncomingCall()+ val service = Robolectric.setupService(InAppCallForegroundService::class.java)+ service.onStartCommand(+ Intent().apply { action = "com.vayunmathur.communicate.inappcall.HANGUP_CALL" }, 0, 1,+ )+ assertEquals(listOf("reject"), actions.toList())+ service.onDestroy()+ }++ @Test+ fun inAppCallServiceHangupHangsUpWhileOngoing() {+ startIncomingCall()+ InAppCallRegistry.onPhase(InAppCallPhase.Active)+ val service = Robolectric.setupService(InAppCallForegroundService::class.java)+ val result = service.onStartCommand(+ Intent().apply { action = "com.vayunmathur.communicate.inappcall.HANGUP_CALL" }, 0, 1,+ )+ assertEquals(Service.START_STICKY, result)+ assertEquals(listOf("hangup"), actions.toList())+ service.onDestroy()+ }++ @Test+ fun inAppCallServiceNullIntentStillGoesForeground() {+ startIncomingCall()+ val service = Robolectric.setupService(InAppCallForegroundService::class.java)+ assertEquals(Service.START_STICKY, service.onStartCommand(null, 0, 1))+ assertEquals(emptyList(), actions.toList())+ service.onDestroy()+ }++ @Test+ fun googleVoiceCallServiceActionsAndStopPaths() {+ // No GV call is registered, so answer/hangup forward into the manager as no-ops;+ // the contract under test is that the service enters the foreground and stays sticky.+ val service = Robolectric.setupService(GoogleVoiceCallForegroundService::class.java)+ assertNull(service.onBind(Intent()))+ assertEquals(+ Service.START_STICKY,+ service.onStartCommand(+ Intent().apply { action = "com.vayunmathur.communicate.googlevoice.ANSWER_CALL" }, 0, 1,+ ),+ )+ assertEquals(+ Service.START_STICKY,+ service.onStartCommand(+ Intent().apply { action = "com.vayunmathur.communicate.googlevoice.HANGUP_CALL" }, 0, 2,+ ),+ )+ assertEquals(Service.START_STICKY, service.onStartCommand(null, 0, 3))+ service.onDestroy()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionServiceSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionServiceSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionServiceSlice4Pass2Test.ktnew file mode 100644index 0000000000..b318cb7de8--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionServiceSlice4Pass2Test.kt@@ -0,0 +1,84 @@+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.googlevoice.call.GoogleVoiceCallManager+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: GV Telecom connection service creating self-managed connections. */+@RunWith(RobolectricTestRunner::class)+class GoogleVoiceConnectionServiceSlice4Pass2Test {++ private val ctx get() = ApplicationProvider.getApplicationContext<android.content.Context>()++ private fun handle() = PhoneAccountHandle(+ ComponentName(ctx, GoogleVoiceConnectionService::class.java), "gv",+ )++ @Test+ fun outgoingConnectionIsSelfManagedAndDialing() {+ val service = Robolectric.setupService(GoogleVoiceConnectionService::class.java)+ val request = ConnectionRequest(handle(), Uri.fromParts("tel", "+15559999", null), Bundle())+ val connection = service.onCreateOutgoingConnection(handle(), request)+ assertNotNull(connection)+ assertTrue(+ connection.connectionProperties and Connection.PROPERTY_SELF_MANAGED != 0,+ "GV connections must be self-managed",+ )+ assertEquals(Connection.STATE_DIALING, connection.state)+ assertTrue(connection === GoogleVoiceCallManager.connection)+ GoogleVoiceCallManager.stopRegistration()+ GoogleVoiceCallManager.connection = null+ service.onDestroy()+ }++ @Test+ fun incomingConnectionIsRingingWithCallerName() {+ val service = Robolectric.setupService(GoogleVoiceConnectionService::class.java)+ val extras = Bundle().apply {+ putParcelable(+ TelecomManager.EXTRA_INCOMING_CALL_ADDRESS,+ Uri.fromParts("tel", "+15551234", null),+ )+ }+ val request = ConnectionRequest(handle(), Uri.fromParts("tel", "+15551234", null), extras)+ val connection = service.onCreateIncomingConnection(handle(), request)+ assertEquals(Connection.STATE_RINGING, connection.state)+ assertTrue(connection.connectionProperties and Connection.PROPERTY_SELF_MANAGED != 0)+ assertTrue(connection === GoogleVoiceCallManager.connection)+ GoogleVoiceCallManager.connection = null+ service.onDestroy()+ }++ @Test+ fun failedConnectionCallbacksAreSafe() {+ val service = Robolectric.setupService(GoogleVoiceConnectionService::class.java)+ service.onCreateOutgoingConnectionFailed(handle(), null)+ service.onCreateIncomingConnectionFailed(handle(), null)+ service.onDestroy()+ }++ @Test+ fun nullRequestConnectionsStillCreated() {+ val service = Robolectric.setupService(GoogleVoiceConnectionService::class.java)+ val outgoing = service.onCreateOutgoingConnection(null, null)+ assertNotNull(outgoing)+ val incoming = service.onCreateIncomingConnection(null, null)+ assertNotNull(incoming)+ GoogleVoiceCallManager.stopRegistration()+ GoogleVoiceCallManager.connection = null+ service.onDestroy()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/MiscServicesSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/MiscServicesSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/MiscServicesSlice4Pass2Test.ktnew file mode 100644index 0000000000..ff9a82889f--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/MiscServicesSlice4Pass2Test.kt@@ -0,0 +1,57 @@+package com.vayunmathur.communicate.telephony++import android.app.Service+import android.content.Intent+import androidx.car.app.SessionInfo+import com.vayunmathur.communicate.service.car.CommunicateCarAppService+import com.vayunmathur.communicate.service.car.CommunicateCarSession+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: car app service, in-call service start actions, and session creation. */+@RunWith(RobolectricTestRunner::class)+class MiscServicesSlice4Pass2Test {++ @Test+ fun carAppServiceCreatesSessionsAndAllowsAllHosts() {+ val service = Robolectric.setupService(CommunicateCarAppService::class.java)+ assertNotNull(service.createHostValidator())+ val session = service.onCreateSession()+ assertTrue(session is CommunicateCarSession)+ val perDisplay = service.onCreateSession(SessionInfo(SessionInfo.DISPLAY_TYPE_MAIN, "cluster"))+ assertTrue(perDisplay is CommunicateCarSession)+ assertEquals(+ androidx.car.app.CarAppService.THEME_SOURCE_APP,+ service.carAppThemeSource,+ )+ }++ @Test+ fun inCallServiceActionsWithNoCallAreSafe() {+ val service = Robolectric.setupService(CommunicateInCallService::class.java)+ for (action in listOf(+ "com.vayunmathur.communicate.regularcall.ANSWER",+ "com.vayunmathur.communicate.regularcall.DECLINE",+ "com.vayunmathur.communicate.regularcall.DISCONNECT",+ null,+ )) {+ val intent = action?.let { Intent().apply { this.action = it } }+ assertEquals(Service.START_NOT_STICKY, service.onStartCommand(intent, 0, 1))+ }+ service.onDestroy()+ }++ @Test+ fun carSessionOnCreateScreenReturnsThreadListScreen() {+ val session = CommunicateCarSession()+ // onCreateScreen needs a CarContext, which only a host provides; the session's+ // lifecycle/cancellation contract is covered by CommunicateCarSessionSlice4Test.+ assertNotNull(session.scope)+ assertNotNull(session.repository)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/RcsDialogSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/RcsDialogSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/RcsDialogSlice4Pass2Test.ktnew file mode 100644index 0000000000..b52595c2f3--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/RcsDialogSlice4Pass2Test.kt@@ -0,0 +1,130 @@+package com.vayunmathur.communicate.telephony++import android.telephony.ims.SipMessage+import kotlinx.coroutines.runBlocking+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.test.assertNull+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: RCS inbound dialog handlers driven with real SipMessages under Robolectric. */+@RunWith(RobolectricTestRunner::class)+class RcsDialogSlice4Pass2Test {++ private fun service() = Robolectric.setupService(RcsSyncService::class.java)++ private fun message(startLine: String, headers: String, body: String = ""): SipMessage =+ SipMessage(startLine, headers, body.toByteArray(Charsets.UTF_8))++ private val inviteHeaders = "Via: SIP/2.0/TCP h;branch=z9hG4bK9\r\n" ++ "From: \"Bob\" <sip:[email protected]>;tag=ftag\r\n" ++ "To: <sip:[email protected]>\r\n" ++ "Call-ID: dialog-1\r\n" ++ "Content-Type: application/sdp\r\n"++ @Test+ fun sipMessageRoundTripsThroughFrameworkClass() {+ val msg = message("INVITE sip:me@x SIP/2.0", inviteHeaders, "v=0 body")+ assertEquals("INVITE sip:me@x SIP/2.0", msg.startLine)+ assertEquals("dialog-1", msg.callIdParameter)+ assertEquals("z9hG4bK9", msg.viaBranchParameter)+ }++ @Test+ fun parseEnvelopeFromRealSipMessage() {+ val service = service()+ val headers = "Via: SIP/2.0/TCP h;branch=z9hG4bK1\r\n" ++ "From: \"Bob\" <sip:[email protected]>;tag=t1\r\n" ++ "Content-Type: text/plain\r\n" ++ "Call-ID: call-42\r\n"+ val envelope = service.parseEnvelope(message("MESSAGE sip:me@x SIP/2.0", headers, "hello there"))+ assertNotNull(envelope)+ assertEquals("+15551234", envelope.from)+ assertEquals("text/plain", envelope.contentType)+ assertEquals("hello there", envelope.raw)+ service.onDestroy()+ }++ @Test+ fun handleInboundByeTearsDownUnknownDialog() = runBlocking {+ val service = service()+ service.handleInboundBye(message("BYE sip:me@x SIP/2.0", inviteHeaders))+ // No session existed; the contract is that it completes without throwing.+ service.closeDeadMsrpConnections()+ service.onDestroy()+ Unit+ }++ @Test+ fun handleInboundInviteWithoutSdpDeclines() = runBlocking {+ val service = service()+ service.handleInboundInvite(message("INVITE sip:me@x SIP/2.0", inviteHeaders, "no sdp here"))+ service.onDestroy()+ Unit+ }++ @Test+ fun handleInboundInviteWithSdpNotifies() = runBlocking {+ val service = service()+ val sdp = "v=0\r\no=- 1 1 IN IP4 0.0.0.0\r\nm=message 9 TCP/MSRP *\r\n"+ service.handleInboundInvite(message("INVITE sip:me@x SIP/2.0", inviteHeaders, sdp))+ service.onDestroy()+ Unit+ }++ @Test+ fun notifySubscribeUpdateOptionsAndReferHandlers() = runBlocking {+ val service = service()+ val base = "Via: SIP/2.0/TCP h;branch=z9hG4bK5\r\n" ++ "From: \"Bob\" <sip:[email protected]>;tag=ftag\r\n" ++ "To: <sip:[email protected]>\r\n" ++ "Call-ID: dialog-9\r\n"++ // NOTIFY with a refer sipfrag, then a conference event+ service.handleInboundNotify(+ message("NOTIFY sip:me@x SIP/2.0", base + "Event: refer\r\nCSeq: 3 NOTIFY\r\n", "SIP/2.0 200 OK"),+ )+ service.handleInboundNotify(+ message("NOTIFY sip:me@x SIP/2.0", base + "Event: conference\r\nCSeq: 4 NOTIFY\r\n", "<conference-info/>"),+ )+ // Direct response builders+ val notifyMsg = message("NOTIFY sip:me@x SIP/2.0", base + "CSeq: 5 NOTIFY\r\n")+ service.sendNotifyResponse(notifyMsg)+ service.notifyReferStatus(notifyMsg, ok = true)+ service.notifyReferStatus(notifyMsg, ok = false)++ // SUBSCRIBE: bad event is rejected, conference is accepted+ service.handleInboundSubscribe(+ message("SUBSCRIBE sip:me@x SIP/2.0", base + "Event: presence\r\nCSeq: 1 SUBSCRIBE\r\n"),+ )+ service.handleInboundSubscribe(+ message("SUBSCRIBE sip:me@x SIP/2.0", base + "Event: conference\r\nCSeq: 2 SUBSCRIBE\r\n"),+ )+ service.sendSubscribeResponse(notifyMsg, 202, "Accepted")++ // UPDATE on an unknown dialog gets 481 via sendSessionResponse+ service.handleInboundUpdate(message("UPDATE sip:me@x SIP/2.0", base + "CSeq: 6 UPDATE\r\n", "v=0"))+ service.sendSessionResponse(notifyMsg, 200, "OK", "sdp".toByteArray(), "application/sdp")+ service.sendSessionResponse(notifyMsg, 481, "Call/Transaction Does Not Exist")++ // OPTIONS capability ping + REFER without Refer-To (early return) and with one+ service.handleInboundOptions(message("OPTIONS sip:me@x SIP/2.0", base + "CSeq: 1 OPTIONS\r\n"))+ service.handleInboundRefer(message("REFER sip:me@x SIP/2.0", base + "CSeq: 1 REFER\r\n"))+ service.sendReferResponse(notifyMsg, 202, "Accepted")+ service.onDestroy()+ Unit+ }++ @Test+ fun dialogHandlersIgnoreMissingCallId() = runBlocking {+ val service = service()+ val noCallId = "Via: SIP/2.0/TCP h;branch=z9hG4bK7\r\nFrom: <sip:+1555@x>;tag=t\r\n"+ service.handleInboundBye(message("BYE sip:me@x SIP/2.0", noCallId))+ assertNull(service.parseEnvelope(message("MESSAGE sip:me@x SIP/2.0", noCallId, " ")))+ service.onDestroy()+ Unit+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/RcsInboundParseSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/RcsInboundParseSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/RcsInboundParseSlice4Pass2Test.ktnew file mode 100644index 0000000000..a439c1edf7--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/RcsInboundParseSlice4Pass2Test.kt@@ -0,0 +1,91 @@+package com.vayunmathur.communicate.telephony++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.test.assertNull+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: RCS inbound envelope parsing on a Robolectric-created [RcsSyncService].+ * (SipMessage itself is a hidden-API class with no test-classpath stub, so envelope+ * construction is exercised through [Envelope] directly; header parsing is covered by+ * RcsInboundHelpersSlice4Test.) */+@RunWith(RobolectricTestRunner::class)+class RcsInboundParseSlice4Pass2Test {++ private fun service() = Robolectric.setupService(RcsSyncService::class.java)++ @Test+ fun parseInboundPlainTextBecomesInboxRow() {+ val service = service()+ val parsed = service.parseInbound(+ Envelope(from = "+1555", contentType = "text/plain", raw = "hello world", callId = "c1", viaBranch = "br1"),+ )+ assertNotNull(parsed)+ assertEquals("+1555", parsed.conversationId)+ assertEquals("hello world", parsed.body)+ assertEquals(InboundKind.Text, parsed.kind)+ assertTrue(parsed.messageId.startsWith("in-c1"))+ service.onDestroy()+ }++ @Test+ fun parseInboundTypingAndReceiptKinds() {+ val service = service()+ val typing = service.parseInbound(+ Envelope(+ from = "+1555", contentType = "application/im-iscomposing+xml",+ raw = "<?xml version=\"1.0\"?><isComposing xmlns=\"urn:ietf:params:xml:ns:im-composing\"><state>active</state></isComposing>",+ callId = "c2", viaBranch = "br",+ ),+ )+ assertNotNull(typing)+ assertEquals(InboundKind.Typing, typing.kind)+ assertEquals("", typing.body)++ val blank = service.parseInbound(+ Envelope(from = "+1555", contentType = "text/plain", raw = " ", callId = "c3", viaBranch = "br"),+ )+ assertNull(blank)+ service.onDestroy()+ }++ @Test+ fun parseInboundCpimWrappedTextIsUnwrapped() {+ val service = service()+ val cpim = "Content-Type: message/cpim\r\n\r\n" ++ "From: <sip:+1555@x>\r\nContent-Type: text/plain\r\n\r\nwrapped hello"+ val parsed = service.parseInbound(+ Envelope(from = "+1555", contentType = "message/cpim", raw = cpim, callId = "c4", viaBranch = "br"),+ )+ assertNotNull(parsed)+ assertEquals("wrapped hello", parsed.body)+ service.onDestroy()+ }++ @Test+ fun rcsSyncServiceNullIntentStartsRegistrationAttempt() {+ val service = service()+ // Dev builds have RcsFeature enabled, so a plain start goes sticky and kicks off+ // registration in the service scope (which fails harmlessly with no IMS stack).+ val result = service.onStartCommand(null, 0, 7)+ assertEquals(android.app.Service.START_STICKY, result)+ Thread.sleep(300)+ service.onDestroy()+ }++ @Test+ fun rcsSyncServiceStopAndTimeoutPaths() {+ val service = service()+ val result = service.onStartCommand(+ android.content.Intent().apply { action = "com.vayunmathur.communicate.rcs.STOP_SYNC" }, 0, 1,+ )+ assertEquals(android.app.Service.START_NOT_STICKY, result)+ service.onTimeout(1, 0)+ assertNull(service.onBind(android.content.Intent()))+ service.onDestroy()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/SimCallBridgeSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/SimCallBridgeSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/SimCallBridgeSlice4Pass2Test.ktnew file mode 100644index 0000000000..1bf85391e4--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/SimCallBridgeSlice4Pass2Test.kt@@ -0,0 +1,81 @@+package com.vayunmathur.communicate.telephony++import android.telecom.Call+import android.telecom.CallAudioState+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.data.call.InAppCallPhase+import com.vayunmathur.communicate.data.call.InAppCallRegistry+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: SimCallBridge phase mapping and audio-state mirroring. */+@RunWith(RobolectricTestRunner::class)+class SimCallBridgeSlice4Pass2Test {++ @BeforeTest+ fun setUp() {+ InAppCallRegistry.onEnded("reset")+ InAppCallRegistry.clearEnded()+ InAppCallRegistry.videoController = null+ InAppCallRegistry.dtmfController = null+ InAppCallRegistry.holdController = null+ InAppCallRegistry.connection = null+ }++ @Test+ fun mapPhaseCoversEveryTelecomState() {+ assertEquals(InAppCallPhase.Incoming, SimCallBridge.mapPhase(Call.STATE_RINGING))+ assertEquals(InAppCallPhase.Outgoing, SimCallBridge.mapPhase(Call.STATE_DIALING))+ assertEquals(InAppCallPhase.Outgoing, SimCallBridge.mapPhase(Call.STATE_CONNECTING))+ assertEquals(InAppCallPhase.Outgoing, SimCallBridge.mapPhase(Call.STATE_SELECT_PHONE_ACCOUNT))+ assertEquals(InAppCallPhase.Active, SimCallBridge.mapPhase(Call.STATE_ACTIVE))+ assertEquals(InAppCallPhase.Active, SimCallBridge.mapPhase(Call.STATE_HOLDING))+ assertEquals(InAppCallPhase.Ended, SimCallBridge.mapPhase(Call.STATE_DISCONNECTED))+ assertEquals(InAppCallPhase.Ended, SimCallBridge.mapPhase(Call.STATE_DISCONNECTING))+ assertEquals(InAppCallPhase.Connecting, SimCallBridge.mapPhase(Call.STATE_NEW))+ assertEquals(InAppCallPhase.Connecting, SimCallBridge.mapPhase(999))+ }++ @Test+ fun capabilitiesOfferKeypadAndHoldOnly() {+ val caps = SimCallBridge.capabilities+ assertTrue(caps.dtmf)+ assertTrue(caps.hold)+ assertFalse(caps.video)+ assertFalse(caps.screenShare)+ }++ @Test+ fun audioStateMirrorsOnlyForSimLine() {+ // Non-SIM line: audio state is ignored+ InAppCallRegistry.bind(CommunicateLine.Signal, NoopController)+ InAppCallRegistry.onCallStarting(CommunicateLine.Signal, "p", "Pat", false, incoming = false)+ SimCallBridge.onAudioStateChanged(CallAudioState(true, CallAudioState.ROUTE_SPEAKER, CallAudioState.ROUTE_SPEAKER))+ assertFalse(InAppCallRegistry.state.value.muted)+ assertFalse(InAppCallRegistry.state.value.speaker)++ // SIM line: mute + speaker route are mirrored+ InAppCallRegistry.onEnded("reset"); InAppCallRegistry.clearEnded()+ InAppCallRegistry.bind(CommunicateLine.Sim, NoopController)+ InAppCallRegistry.onCallStarting(CommunicateLine.Sim, "+1555", "Pat", false, incoming = false)+ SimCallBridge.onAudioStateChanged(CallAudioState(true, CallAudioState.ROUTE_SPEAKER, CallAudioState.ROUTE_SPEAKER))+ assertTrue(InAppCallRegistry.state.value.muted)+ assertTrue(InAppCallRegistry.state.value.speaker)+ SimCallBridge.onAudioStateChanged(CallAudioState(false, CallAudioState.ROUTE_EARPIECE, CallAudioState.ROUTE_EARPIECE))+ assertFalse(InAppCallRegistry.state.value.muted)+ assertFalse(InAppCallRegistry.state.value.speaker)+ }++ private object NoopController : com.vayunmathur.communicate.data.call.InAppCallController {+ override fun answer() {}+ override fun reject() {}+ override fun hangup() {}+ override fun setMuted(muted: Boolean) {}+ override fun setSpeaker(on: Boolean) {}+ }+}
communicate/src/test/java/com/vayunmathur/communicate/telephony/SyncServicesSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/telephony/SyncServicesSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/telephony/SyncServicesSlice4Pass2Test.ktnew file mode 100644index 0000000000..9b8ebe75a8--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/telephony/SyncServicesSlice4Pass2Test.kt@@ -0,0 +1,76 @@+package com.vayunmathur.communicate.telephony++import android.app.Service+import android.content.Intent+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import org.junit.runner.RunWith+import org.robolectric.Robolectric+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: sync services' stop/start contract under Robolectric (no live credentials). */+@RunWith(RobolectricTestRunner::class)+class SyncServicesSlice4Pass2Test {++ @Test+ fun googleVoiceSyncStopActionIsNotStickyAndBindsNothing() {+ val service = Robolectric.setupService(GoogleVoiceSyncService::class.java)+ assertNull(service.onBind(Intent()))+ val result = service.onStartCommand(+ Intent().apply { action = "com.vayunmathur.communicate.googlevoice.STOP_SYNC" }, 0, 1,+ )+ assertEquals(Service.START_NOT_STICKY, result)+ service.onDestroy()+ }++ @Test+ fun signalSyncStopActionIsNotSticky() {+ val service = Robolectric.setupService(SignalSyncService::class.java)+ assertNull(service.onBind(Intent()))+ val result = service.onStartCommand(+ Intent().apply { action = "com.vayunmathur.communicate.signal.STOP_SYNC" }, 0, 1,+ )+ assertEquals(Service.START_NOT_STICKY, result)+ service.onDestroy()+ }++ @Test+ fun whatsAppSyncStopActionIsNotSticky() {+ val service = Robolectric.setupService(WhatsAppSyncService::class.java)+ assertNull(service.onBind(Intent()))+ val result = service.onStartCommand(+ Intent().apply { action = "com.vayunmathur.communicate.whatsapp.STOP_SYNC" }, 0, 1,+ )+ assertEquals(Service.START_NOT_STICKY, result)+ service.onDestroy()+ }++ @Test+ fun syncServicesNullIntentStartStickyThenShutdownWithoutCredentials() {+ // No credentials in the Robolectric store, so each service's launched check+ // shuts it down again; the synchronous contract is START_STICKY.+ val gv = Robolectric.setupService(GoogleVoiceSyncService::class.java)+ assertEquals(Service.START_STICKY, gv.onStartCommand(null, 0, 1))+ gv.onDestroy()+ val signal = Robolectric.setupService(SignalSyncService::class.java)+ assertEquals(Service.START_STICKY, signal.onStartCommand(null, 0, 1))+ signal.onDestroy()+ val wa = Robolectric.setupService(WhatsAppSyncService::class.java)+ assertEquals(Service.START_STICKY, wa.onStartCommand(null, 0, 1))+ wa.onDestroy()+ }++ @Test+ fun syncServicesTimeoutCallbackDoesNotCrash() {+ val gv = Robolectric.setupService(GoogleVoiceSyncService::class.java)+ gv.onTimeout(1, 0)+ gv.onDestroy()+ val signal = Robolectric.setupService(SignalSyncService::class.java)+ signal.onTimeout(1, 0)+ signal.onDestroy()+ val wa = Robolectric.setupService(WhatsAppSyncService::class.java)+ wa.onTimeout(1, 0)+ wa.onDestroy()+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/call/InAppCallScreenSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/call/InAppCallScreenSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/call/InAppCallScreenSlice4Pass2Test.ktnew file mode 100644index 0000000000..110a858a73--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/call/InAppCallScreenSlice4Pass2Test.kt@@ -0,0 +1,144 @@+package com.vayunmathur.communicate.ui.call++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasClickAction+import androidx.compose.ui.test.hasContentDescriptionExactly+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+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.InAppCallDtmfController+import com.vayunmathur.communicate.data.call.InAppCallPhase+import com.vayunmathur.communicate.data.call.InAppCallRegistry+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: the full [InAppCallScreen] driven through the registry, phase by phase. */+@RunWith(RobolectricTestRunner::class)+class InAppCallScreenSlice4Pass2Test {++ @get:Rule val rule = createComposeRule()++ 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()+ // Drive the registry back to Idle regardless of what a previous test left behind.+ InAppCallRegistry.onEnded("reset")+ InAppCallRegistry.clearEnded()+ InAppCallRegistry.videoController = null+ InAppCallRegistry.dtmfController = null+ InAppCallRegistry.holdController = null+ InAppCallRegistry.connection = null+ }++ private fun startCall(+ incoming: Boolean,+ capabilities: CallCapabilities = CallCapabilities.AudioOnly,+ video: Boolean = false,+ ) {+ InAppCallRegistry.bind(CommunicateLine.Signal, controller, capabilities)+ InAppCallRegistry.onCallStarting(+ line = CommunicateLine.Signal,+ peerId = "peer-1",+ peerName = "Pat Lee",+ isVideo = video,+ incoming = incoming,+ capabilities = capabilities,+ )+ }++ @Test+ fun idleScreenClosesImmediately() {+ var closed = 0+ rule.setContent { InAppCallScreen(onClose = { closed++ }) }+ rule.waitForIdle()+ assertTrue(closed >= 1, "Idle phase should close the call screen")+ }++ @Test+ fun incomingScreenShowsPeerAndAnswerDeclineWork() {+ startCall(incoming = true)+ var closed = 0+ rule.setContent { InAppCallScreen(onClose = { closed++ }) }+ rule.onNodeWithText("Pat Lee").assertIsDisplayed()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Call")).performClick()+ rule.waitForIdle()+ assertEquals(listOf("answer"), actions.toList())+ assertEquals(0, closed)+ }++ @Test+ fun outgoingScreenShowsDialingAndHangupWorks() {+ startCall(incoming = false)+ rule.setContent { InAppCallScreen(onClose = {}) }+ rule.onNodeWithText("Pat Lee").assertIsDisplayed()+ rule.onNodeWithText("Dialing…").assertIsDisplayed()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("End call")).performClick()+ rule.waitForIdle()+ assertEquals(listOf("hangup"), actions.toList())+ }++ @Test+ fun activeKeypadCallCanOpenKeypadAndSendDigits() {+ val digits = mutableListOf<String>()+ startCall(incoming = false, capabilities = CallCapabilities.AudioAndKeypad)+ InAppCallRegistry.dtmfController = object : InAppCallDtmfController {+ override fun sendDtmf(digit: String) { digits += digit }+ }+ InAppCallRegistry.onPhase(InAppCallPhase.Active)+ rule.setContent { InAppCallScreen(onClose = {}) }+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("Keypad")).performClick()+ rule.waitForIdle()+ rule.onNodeWithText("5").performClick()+ rule.waitForIdle()+ assertEquals(listOf("5"), digits.toList())+ }++ @Test+ fun activeVideoCapabilityScreenWithoutControllerStillShowsControls() {+ startCall(incoming = false, capabilities = CallCapabilities.AudioAndVideo, video = true)+ InAppCallRegistry.onPhase(InAppCallPhase.Active)+ InAppCallRegistry.onRemoteVideo(true)+ rule.setContent { InAppCallScreen(onClose = {}) }+ // No video controller is bound, so CallVideo returns early and the header/controls remain.+ rule.onNodeWithText("Pat Lee").assertIsDisplayed()+ rule.onNode(hasClickAction() and hasContentDescriptionExactly("End call")).performClick()+ assertEquals(listOf("hangup"), actions.toList())+ }++ @Test+ fun endedScreenClosesAfterHold() {+ startCall(incoming = false)+ InAppCallRegistry.onEnded("done")+ var closed = 0+ rule.setContent { InAppCallScreen(onClose = { closed++ }) }+ rule.mainClock.advanceTimeBy(2_000)+ rule.waitForIdle()+ assertTrue(closed >= 1, "Ended phase should close after the hold")+ assertEquals(InAppCallPhase.Idle, InAppCallRegistry.state.value.phase)+ }++ @Test+ fun selfViewConstantsClampWindow() {+ assertEquals(108, SELF_VIEW_WIDTH)+ assertEquals(72, SELF_VIEW_MIN)+ assertTrue(SELF_VIEW_MIN_SCALE < 1f && SELF_VIEW_MAX_SCALE > 1f)+ assertEquals(220, SELF_VIEW_BOTTOM_INSET)+ }+}
communicate/src/test/java/com/vayunmathur/communicate/ui/googlevoice/GoogleVoiceSignInSlice4Pass2Test.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/ui/googlevoice/GoogleVoiceSignInSlice4Pass2Test.kt b/communicate/src/test/java/com/vayunmathur/communicate/ui/googlevoice/GoogleVoiceSignInSlice4Pass2Test.ktnew file mode 100644index 0000000000..78db16714e--- /dev/null+++ b/communicate/src/test/java/com/vayunmathur/communicate/ui/googlevoice/GoogleVoiceSignInSlice4Pass2Test.kt@@ -0,0 +1,32 @@+package com.vayunmathur.communicate.ui.googlevoice++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.communicate.R+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Slice-4 pass-2: GV WebView sign-in screen renders its scaffold under Robolectric. */+@RunWith(RobolectricTestRunner::class)+class GoogleVoiceSignInSlice4Pass2Test {++ @get:Rule val rule = createComposeRule()++ @Test+ fun signInScreenShowsTitleAndWebView() {+ val ctx = ApplicationProvider.getApplicationContext<android.content.Context>()+ var back = 0+ var signedIn = 0+ rule.setContent {+ GoogleVoiceSignInScreen(onBack = { back++ }, onSignedIn = { signedIn++ })+ }+ rule.onNodeWithText(ctx.getString(R.string.gv_sign_in_title)).assertIsDisplayed()+ assertEquals(0, back)+ assertEquals(0, signedIn)+ }+}