Fix broken test testImIntentCustom
Decouple the logic that generates the custom IM intent
from the logic that determines whether or not to actually
assign the intent to the entry (based on whether or not the
intent is registered), so that we can test if the intent is
correctly generated even if there is no application installed
that can handle that custom IM protocol.
Change-Id: If5ce0cd7639a6c05bc89777684cdac45cd7bb6cd
diff --git a/src/com/android/contacts/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java
index c47040d..f836139 100644
--- a/src/com/android/contacts/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailFragment.java
@@ -999,25 +999,35 @@
}
} else {
// Build an IM Intent
- String host = im.getCustomProtocol();
-
- if (protocol != Im.PROTOCOL_CUSTOM) {
- // Try bringing in a well-known host for specific protocols
- host = ContactsUtils.lookupProviderNameFromId(protocol);
- }
-
- if (!TextUtils.isEmpty(host)) {
- final String authority = host.toLowerCase();
- final Uri imUri = new Uri.Builder().scheme(CallUtil.SCHEME_IMTO).authority(
- authority).appendPath(data).build();
- final Intent intent = new Intent(Intent.ACTION_SENDTO, imUri);
- if (PhoneCapabilityTester.isIntentRegistered(context, intent)) {
- entry.intent = intent;
- }
+ final Intent imIntent = getCustomIMIntent(im, protocol);
+ if (imIntent != null &&
+ PhoneCapabilityTester.isIntentRegistered(context, imIntent)) {
+ entry.intent = imIntent;
}
}
}
+ @VisibleForTesting
+ public static Intent getCustomIMIntent(ImDataItem im, int protocol) {
+ String host = im.getCustomProtocol();
+ final String data = im.getData();
+ if (TextUtils.isEmpty(data)) {
+ return null;
+ }
+ if (protocol != Im.PROTOCOL_CUSTOM) {
+ // Try bringing in a well-known host for specific protocols
+ host = ContactsUtils.lookupProviderNameFromId(protocol);
+ }
+ if (TextUtils.isEmpty(host)) {
+ return null;
+ }
+ final String authority = host.toLowerCase();
+ final Uri imUri = new Uri.Builder().scheme(CallUtil.SCHEME_IMTO).authority(
+ authority).appendPath(data).build();
+ final Intent intent = new Intent(Intent.ACTION_SENDTO, imUri);
+ return intent;
+ }
+
/**
* Show a list popup. Used for "popup-able" entry, such as "More networks".
*/
diff --git a/tests/src/com/android/contacts/detail/ContactDetailFragmentTests.java b/tests/src/com/android/contacts/detail/ContactDetailFragmentTests.java
index 0b86912..1747add 100644
--- a/tests/src/com/android/contacts/detail/ContactDetailFragmentTests.java
+++ b/tests/src/com/android/contacts/detail/ContactDetailFragmentTests.java
@@ -105,10 +105,11 @@
ImDataItem im = (ImDataItem) DataItem.createFrom(values);
DetailViewEntry entry = new ContactDetailFragment.DetailViewEntry();
- ContactDetailFragment.buildImActions(mContext, entry, im);
- assertEquals(Intent.ACTION_SENDTO, entry.intent.getAction());
+ final Intent imIntent =
+ ContactDetailFragment.getCustomIMIntent(im, Im.PROTOCOL_CUSTOM);
+ assertEquals(Intent.ACTION_SENDTO, imIntent.getAction());
- final Uri data = entry.intent.getData();
+ final Uri data = imIntent.getData();
assertEquals("imto", data.getScheme());
assertEquals(TEST_PROTOCOL, data.getAuthority());
assertEquals(TEST_ADDRESS, data.getPathSegments().get(0));