49 lines · 2.3 KB · KotlinRaw
package com.cottondb.messagesimport android.app.Applicationimport android.app.Notificationimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertFalseimport org.junit.Assert.assertNotNullimport org.junit.Assert.assertTrueimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.RuntimeEnvironmentimport org.robolectric.annotation.Config/** * AUDIT E (a stolen phone): every notice Comms posts is private on the lock screen, its public version naming only the * app; a chat's Reply and Mark as read ask the phone's lock first. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], application = Application::class)class ChatNoticesLockScreenTest { private val context: Application = RuntimeEnvironment.getApplication() private val words = NoticeWords("Messages", "Missed calls", "Reply", "Message", "Mark as read", "You", "New message") private fun assertPrivate(n: Notification, secret: String) { assertEquals(Notification.VISIBILITY_PRIVATE, n.visibility) assertNotNull(n.publicVersion) val public = n.publicVersion!! val shown = listOfNotNull(public.extras.getCharSequence(Notification.EXTRA_TITLE), public.extras.getCharSequence(Notification.EXTRA_TEXT)).joinToString(" ") assertFalse("the lock screen shows $shown", shown.contains(secret)) assertEquals(context.applicationInfo.loadLabel(context.packageManager).toString(), public.extras.getCharSequence(Notification.EXTRA_TITLE).toString()) } @Test fun a_chat_is_private_and_its_acts_ask_the_lock() { val notice = Notice("t1", "Asha Invented", null, false, false, listOf(NoticeLine("meet at the ferry", 5L, false, null)), 1, 5L, true, "t1") val n = ChatNotices.chat(context, notice, words, silent = true) assertPrivate(n, "Asha") assertPrivate(n, "ferry") assertEquals(2, n.actions.size) assertTrue(n.actions.all { it.isAuthenticationRequired }) } @Test fun a_missed_call_and_a_download_are_private() { assertPrivate(ChatNotices.missed(context, MissedCall("c1", "t1", "Missed call", "Asha Invented", null, false, 9L, "Call back")), "Asha") assertPrivate(ChatNotices.download(context, DownloadNotice("f1", "Downloads", "night-ferry.mkv · Done", 9L)), "night-ferry") }}