1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.contacts.detail; 18 19import com.android.contacts.detail.ContactDetailFragment.DetailViewEntry; 20 21import android.content.ContentValues; 22import android.content.Intent; 23import android.net.Uri; 24import android.provider.ContactsContract.CommonDataKinds.Email; 25import android.provider.ContactsContract.CommonDataKinds.Im; 26import android.test.AndroidTestCase; 27import android.test.suitebuilder.annotation.SmallTest; 28 29/** 30 * Tests for {@link ContactDetailFragment}. 31 */ 32@SmallTest 33public class ContactDetailFragmentTests extends AndroidTestCase { 34 private static final String TEST_ADDRESS = "user@example.org"; 35 private static final String TEST_PROTOCOL = "prot%col"; 36 37 public void testImIntent() throws Exception { 38 // Test GTalk XMPP URI. No chat capabilities provided 39 final ContentValues values = new ContentValues(); 40 values.put(Im.MIMETYPE, Im.CONTENT_ITEM_TYPE); 41 values.put(Im.TYPE, Im.TYPE_HOME); 42 values.put(Im.PROTOCOL, Im.PROTOCOL_GOOGLE_TALK); 43 values.put(Im.DATA, TEST_ADDRESS); 44 45 DetailViewEntry entry = new ContactDetailFragment.DetailViewEntry(); 46 ContactDetailFragment.buildImActions(mContext, entry, values); 47 assertEquals(Intent.ACTION_SENDTO, entry.intent.getAction()); 48 assertEquals("xmpp:" + TEST_ADDRESS + "?message", entry.intent.getData().toString()); 49 50 assertNull(entry.secondaryIntent); 51 } 52 53 public void testImIntentWithAudio() throws Exception { 54 // Test GTalk XMPP URI. Audio chat capabilities provided 55 final ContentValues values = new ContentValues(); 56 values.put(Im.MIMETYPE, Im.CONTENT_ITEM_TYPE); 57 values.put(Im.TYPE, Im.TYPE_HOME); 58 values.put(Im.PROTOCOL, Im.PROTOCOL_GOOGLE_TALK); 59 values.put(Im.DATA, TEST_ADDRESS); 60 values.put(Im.CHAT_CAPABILITY, Im.CAPABILITY_HAS_VOICE | Im.CAPABILITY_HAS_VIDEO); 61 62 DetailViewEntry entry = new ContactDetailFragment.DetailViewEntry(); 63 ContactDetailFragment.buildImActions(mContext, entry, values); 64 assertEquals(Intent.ACTION_SENDTO, entry.intent.getAction()); 65 assertEquals("xmpp:" + TEST_ADDRESS + "?message", entry.intent.getData().toString()); 66 67 assertEquals(Intent.ACTION_SENDTO, entry.secondaryIntent.getAction()); 68 assertEquals("xmpp:" + TEST_ADDRESS + "?call", entry.secondaryIntent.getData().toString()); 69 } 70 71 public void testImIntentWithVideo() throws Exception { 72 // Test GTalk XMPP URI. Video chat capabilities provided 73 final ContentValues values = new ContentValues(); 74 values.put(Im.MIMETYPE, Im.CONTENT_ITEM_TYPE); 75 values.put(Im.TYPE, Im.TYPE_HOME); 76 values.put(Im.PROTOCOL, Im.PROTOCOL_GOOGLE_TALK); 77 values.put(Im.DATA, TEST_ADDRESS); 78 values.put(Im.CHAT_CAPABILITY, Im.CAPABILITY_HAS_VOICE | Im.CAPABILITY_HAS_VIDEO | 79 Im.CAPABILITY_HAS_VOICE); 80 81 DetailViewEntry entry = new ContactDetailFragment.DetailViewEntry(); 82 ContactDetailFragment.buildImActions(mContext, entry, values); 83 assertEquals(Intent.ACTION_SENDTO, entry.intent.getAction()); 84 assertEquals("xmpp:" + TEST_ADDRESS + "?message", entry.intent.getData().toString()); 85 86 assertEquals(Intent.ACTION_SENDTO, entry.secondaryIntent.getAction()); 87 assertEquals("xmpp:" + TEST_ADDRESS + "?call", entry.secondaryIntent.getData().toString()); 88 } 89 90 public void testImIntentCustom() throws Exception { 91 // Custom IM types have encoded authority. We send the imto Intent here, because 92 // legacy third party apps might not accept xmpp yet 93 final ContentValues values = new ContentValues(); 94 values.put(Im.MIMETYPE, Im.CONTENT_ITEM_TYPE); 95 values.put(Im.TYPE, Im.TYPE_HOME); 96 values.put(Im.PROTOCOL, Im.PROTOCOL_CUSTOM); 97 values.put(Im.CUSTOM_PROTOCOL, TEST_PROTOCOL); 98 values.put(Im.DATA, TEST_ADDRESS); 99 100 DetailViewEntry entry = new ContactDetailFragment.DetailViewEntry(); 101 ContactDetailFragment.buildImActions(mContext, entry, values); 102 assertEquals(Intent.ACTION_SENDTO, entry.intent.getAction()); 103 104 final Uri data = entry.intent.getData(); 105 assertEquals("imto", data.getScheme()); 106 assertEquals(TEST_PROTOCOL, data.getAuthority()); 107 assertEquals(TEST_ADDRESS, data.getPathSegments().get(0)); 108 109 assertNull(entry.secondaryIntent); 110 } 111 112 public void testImEmailIntent() throws Exception { 113 // Email addresses are treated as Google Talk entries 114 // This test only tests the VIDEO+CAMERA case. The other cases have been addressed by the 115 // Im tests 116 final ContentValues values = new ContentValues(); 117 values.put(Email.MIMETYPE, Email.CONTENT_ITEM_TYPE); 118 values.put(Email.TYPE, Email.TYPE_HOME); 119 values.put(Email.DATA, TEST_ADDRESS); 120 values.put(Email.CHAT_CAPABILITY, Im.CAPABILITY_HAS_VOICE | Im.CAPABILITY_HAS_VIDEO | 121 Im.CAPABILITY_HAS_VOICE); 122 123 DetailViewEntry entry = new ContactDetailFragment.DetailViewEntry(); 124 ContactDetailFragment.buildImActions(mContext, entry, values); 125 assertEquals(Intent.ACTION_SENDTO, entry.intent.getAction()); 126 assertEquals("xmpp:" + TEST_ADDRESS + "?message", entry.intent.getData().toString()); 127 128 assertEquals(Intent.ACTION_SENDTO, entry.secondaryIntent.getAction()); 129 assertEquals("xmpp:" + TEST_ADDRESS + "?call", entry.secondaryIntent.getData().toString()); 130 } 131} 132