1 /* 2 * Copyright (C) 2015 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 17 package android.provider.cts.contacts; 18 19 import android.content.ContentUris; 20 import android.content.Context; 21 import android.content.ContextWrapper; 22 import android.content.Intent; 23 import android.graphics.Rect; 24 import android.net.Uri; 25 import android.os.Bundle; 26 import android.os.UserHandle; 27 import android.provider.Contacts; 28 import android.provider.ContactsContract; 29 import android.provider.ContactsContract.QuickContact; 30 import android.test.InstrumentationTestCase; 31 import android.test.UiThreadTest; 32 import android.view.View; 33 34 import java.util.Arrays; 35 import java.util.concurrent.CountDownLatch; 36 import java.util.concurrent.TimeUnit; 37 38 public class ContactsContract_QuickContactsTest extends InstrumentationTestCase { 39 40 final String EXCLUDED_MIME_TYPES[] = {"exclude1", "exclude2"}; 41 final String PLAIN_MIME_TYPE = "text/plain"; 42 final Uri FAKE_CONTACT_URI = ContentUris.withAppendedId(Contacts.CONTENT_URI, 0); 43 44 @UiThreadTest 45 public void testPrioritizedMimeTypeAndExcludedMimeTypes() throws InterruptedException { 46 final CountDownLatch latch = new CountDownLatch(2); 47 Context context = new ContextWrapper(getInstrumentation().getContext()) { 48 @Override 49 public void startActivity(Intent intent) { 50 testCallback(intent); 51 } 52 53 public void startActivityAsUser(Intent intent, UserHandle user) { 54 testCallback(intent); 55 } 56 57 public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { 58 testCallback(intent); 59 } 60 61 private void testCallback(Intent intent) { 62 assertEquals(PLAIN_MIME_TYPE, intent.getStringExtra( 63 QuickContact.EXTRA_PRIORITIZED_MIMETYPE)); 64 String excludedMimeTypes[] 65 = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); 66 assertTrue(Arrays.equals(excludedMimeTypes, EXCLUDED_MIME_TYPES)); 67 latch.countDown(); 68 } 69 }; 70 71 // Execute 72 ContactsContract.QuickContact.showQuickContact(context, new View(context), 73 FAKE_CONTACT_URI, EXCLUDED_MIME_TYPES, PLAIN_MIME_TYPE); 74 ContactsContract.QuickContact.showQuickContact(context, (Rect) null, 75 FAKE_CONTACT_URI, EXCLUDED_MIME_TYPES, PLAIN_MIME_TYPE); 76 77 // Verify: the start activity call sets the prioritized mimetype and excludes mimetypes. 78 // We don't know which method will be used to start the activity, so we check all options. 79 assertTrue(latch.await(1, TimeUnit.SECONDS)); 80 } 81 }