-
Notifications
You must be signed in to change notification settings - Fork 46
Fix secondary user SMS notification hiding sender and message #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
m4pl
wants to merge
3
commits into
GrapheneOS:main
Choose a base branch
from
m4pl:task/75-secondary-user-sms-notification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,139
−425
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...otlin/com/android/messaging/data/contact/formatter/ContactDestinationFormatterImplTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package com.android.messaging.data.contact.formatter | ||
|
|
||
| import com.android.messaging.data.phone.formatter.PhoneNumberFormatter | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import io.mockk.verify | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| internal class ContactDestinationFormatterImplTest { | ||
|
|
||
| private val phoneNumberFormatter = mockk<PhoneNumberFormatter>() | ||
| private val formatter = ContactDestinationFormatterImpl( | ||
| phoneNumberFormatter = phoneNumberFormatter, | ||
| ) | ||
|
|
||
| @Test | ||
| fun canonicalize_whenValueIsBlank_returnsTrimmedBlank() { | ||
| assertEquals("", formatter.canonicalize(" ")) | ||
| verify(exactly = 0) { | ||
| phoneNumberFormatter.getCanonicalForEnteredNumber(any()) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun canonicalize_whenValueIsEmail_trimsAndLowercasesEmail() { | ||
| assertEquals("alice@example.com", formatter.canonicalize(" Alice@Example.COM ")) | ||
| verify(exactly = 0) { | ||
| phoneNumberFormatter.getCanonicalForEnteredNumber(any()) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun canonicalize_whenValueIsPhone_trimsCanonicalizesAndStripsSeparators() { | ||
| every { | ||
| phoneNumberFormatter.getCanonicalForEnteredNumber("+1 (555) 123-4567") | ||
| } returns "+1 (555) 123-4567" | ||
|
|
||
| assertEquals("+15551234567", formatter.canonicalize(" +1 (555) 123-4567 ")) | ||
| } | ||
|
|
||
| @Test | ||
| fun canonicalize_withCountryCandidates_passesCandidatesToPhoneNumberFormatter() { | ||
| val countryCandidates = listOf("US", "CA") | ||
| every { | ||
| phoneNumberFormatter.getCanonicalForEnteredNumber("555.123/4567", countryCandidates) | ||
| } returns "555.123/4567" | ||
|
|
||
| assertEquals( | ||
| "5551234567", | ||
| formatter.canonicalize("555.123/4567", countryCandidates), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun formatPhoneForDisplay_delegatesToPhoneNumberFormatter() { | ||
| every { phoneNumberFormatter.formatForDisplay("+15551234") } returns "+1 555-1234" | ||
|
|
||
| assertEquals("+1 555-1234", formatter.formatPhoneForDisplay("+15551234")) | ||
| } | ||
|
|
||
| @Test | ||
| fun countryCandidates_delegatesToPhoneNumberFormatter() { | ||
| val countryCandidates = listOf("US", "CA") | ||
| every { phoneNumberFormatter.countryCandidates() } returns countryCandidates | ||
|
|
||
| assertEquals(countryCandidates, formatter.countryCandidates()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...rc/test/kotlin/com/android/messaging/data/phone/formatter/PhoneNumberFormatterImplTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package com.android.messaging.data.phone.formatter | ||
|
|
||
| import com.android.messaging.util.PhoneUtils | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import io.mockk.verify | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
|
|
||
| internal class PhoneNumberFormatterImplTest { | ||
|
|
||
| private val phoneUtils = mockk<PhoneUtils>() | ||
| private val formatter = PhoneNumberFormatterImpl(phoneUtils = phoneUtils) | ||
|
|
||
| @Test | ||
| fun formatForDisplay_delegatesToPhoneUtils() { | ||
| every { phoneUtils.formatForDisplay(PHONE_NUMBER) } returns FORMATTED_PHONE_NUMBER | ||
|
|
||
| assertEquals(FORMATTED_PHONE_NUMBER, formatter.formatForDisplay(PHONE_NUMBER)) | ||
| } | ||
|
|
||
| @Test | ||
| fun formatForDisplayUsingSimCountry_whenPhoneUtilsReturnsNull_returnsEmptyString() { | ||
| every { phoneUtils.formatForDisplayUsingSimCountry(PHONE_NUMBER) } returns null | ||
|
|
||
| assertEquals("", formatter.formatForDisplayUsingSimCountry(PHONE_NUMBER)) | ||
| } | ||
|
|
||
| @Test | ||
| fun formatNormalizedUsingSimCountry_whenPhoneUtilsReturnsNull_returnsEmptyString() { | ||
| every { phoneUtils.formatNormalizedDestinationUsingSimCountry(PHONE_NUMBER) } returns null | ||
|
|
||
| assertEquals("", formatter.formatNormalizedUsingSimCountry(PHONE_NUMBER)) | ||
| } | ||
|
|
||
| @Test | ||
| fun getCanonicalForEnteredNumber_delegatesToPhoneUtils() { | ||
| every { phoneUtils.getCanonicalForEnteredPhoneNumber(PHONE_NUMBER) } returns | ||
| CANONICAL_NUMBER | ||
|
|
||
| assertEquals(CANONICAL_NUMBER, formatter.getCanonicalForEnteredNumber(PHONE_NUMBER)) | ||
| } | ||
|
|
||
| @Test | ||
| fun getCanonicalForEnteredNumber_withCountryCandidates_delegatesToPhoneUtils() { | ||
| val countryCandidates = listOf("US", "CA") | ||
| every { | ||
| phoneUtils.getCanonicalForEnteredPhoneNumber(PHONE_NUMBER, countryCandidates) | ||
| } returns CANONICAL_NUMBER | ||
|
|
||
| assertEquals( | ||
| CANONICAL_NUMBER, | ||
| formatter.getCanonicalForEnteredNumber(PHONE_NUMBER, countryCandidates), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun countryCandidates_warmsUpPhoneUtilsBeforeReadingCandidates() { | ||
| val countryCandidates = listOf("US", "CA") | ||
| every { phoneUtils.warmUp() } returns Unit | ||
| every { phoneUtils.countryCandidatesForEnteredPhoneNumber } returns countryCandidates | ||
|
|
||
| assertEquals(countryCandidates, formatter.countryCandidates()) | ||
| verify { | ||
| phoneUtils.warmUp() | ||
| phoneUtils.countryCandidatesForEnteredPhoneNumber | ||
| } | ||
| } | ||
|
|
||
| private companion object { | ||
| private const val PHONE_NUMBER = "+15551234" | ||
| private const val FORMATTED_PHONE_NUMBER = "+1 555-1234" | ||
| private const val CANONICAL_NUMBER = "+15551234" | ||
| } | ||
| } |
102 changes: 102 additions & 0 deletions
102
.../test/kotlin/com/android/messaging/data/secondaryuser/SecondaryUserMessageResolverTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.android.messaging.data.secondaryuser | ||
|
|
||
| import com.android.messaging.data.phone.formatter.PhoneNumberFormatter | ||
| import com.android.messaging.data.secondaryuser.model.SecondaryUserMessageInfo | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import io.mockk.verify | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Test | ||
|
|
||
| internal class SecondaryUserMessageResolverTest { | ||
|
|
||
| private val contactNameLookup = mockk<SmsContactNameLookup>() | ||
| private val phoneNumberFormatter = mockk<PhoneNumberFormatter>() | ||
|
|
||
| private val resolver = SecondaryUserMessageResolverImpl( | ||
| contactNameLookup = contactNameLookup, | ||
| phoneNumberFormatter = phoneNumberFormatter, | ||
| ) | ||
|
|
||
| @Test | ||
| fun resolve_contactFound_usesContactName() { | ||
| every { contactNameLookup.lookup("+15551234") } returns "Alice" | ||
|
|
||
| val info = resolver.resolve(address = "+15551234", body = "Hello there") | ||
| assertEquals( | ||
| SecondaryUserMessageInfo(sender = "Alice", body = "Hello there"), | ||
| info, | ||
| ) | ||
| verify(exactly = 0) { | ||
| phoneNumberFormatter.formatForDisplay(any()) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun resolve_noMatchingContact_fallsBackToFormattedNumber() { | ||
| every { contactNameLookup.lookup("+15551234") } returns null | ||
| every { phoneNumberFormatter.formatForDisplay("+15551234") } returns "+1 555-1234" | ||
|
|
||
| val info = resolver.resolve(address = "+15551234", body = "Hello there") | ||
| assertEquals( | ||
| SecondaryUserMessageInfo(sender = "+1 555-1234", body = "Hello there"), | ||
| info, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun resolve_blankContactName_fallsBackToFormattedNumber() { | ||
| every { contactNameLookup.lookup("+15551234") } returns "" | ||
| every { phoneNumberFormatter.formatForDisplay("+15551234") } returns "+1 555-1234" | ||
|
|
||
| val info = resolver.resolve(address = "+15551234", body = "Hello there") | ||
| assertEquals( | ||
| SecondaryUserMessageInfo(sender = "+1 555-1234", body = "Hello there"), | ||
| info, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun resolve_shortAddress_usesFormattedAddress() { | ||
| every { contactNameLookup.lookup("123") } returns null | ||
| every { phoneNumberFormatter.formatForDisplay("123") } returns "123" | ||
|
|
||
| val info = resolver.resolve(address = "123", body = "Hello there") | ||
| assertEquals( | ||
| SecondaryUserMessageInfo(sender = "123", body = "Hello there"), | ||
| info, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun resolve_nullBody_returnsNull() { | ||
| assertNull(resolver.resolve(address = "+15551234", body = null)) | ||
| verifyNoSenderResolution() | ||
| } | ||
|
|
||
| @Test | ||
| fun resolve_emptyBody_returnsNull() { | ||
| assertNull(resolver.resolve(address = "+15551234", body = "")) | ||
| verifyNoSenderResolution() | ||
| } | ||
|
|
||
| @Test | ||
| fun resolve_nullAddress_returnsNull() { | ||
| assertNull(resolver.resolve(address = null, body = "Hello there")) | ||
| verifyNoSenderResolution() | ||
| } | ||
|
|
||
| @Test | ||
| fun resolve_emptyAddress_returnsNull() { | ||
| assertNull(resolver.resolve(address = "", body = "Hello there")) | ||
| verifyNoSenderResolution() | ||
| } | ||
|
|
||
| private fun verifyNoSenderResolution() { | ||
| verify(exactly = 0) { | ||
| contactNameLookup.lookup(any()) | ||
| phoneNumberFormatter.formatForDisplay(any()) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage should be improved, currently tests are skipping lots of cases