• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 package com.android.emergency.edit;
17 
18 import android.app.Instrumentation;
19 import android.content.Intent;
20 import android.content.IntentFilter;
21 import android.preference.Preference;
22 import android.provider.ContactsContract;
23 import android.test.ActivityInstrumentationTestCase2;
24 import android.test.suitebuilder.annotation.MediumTest;
25 
26 import com.android.emergency.PreferenceKeys;
27 
28 /**
29  * Tests for {@link EditEmergencyContactsFragment}.
30  */
31 @MediumTest
32 public class EditEmergencyContactsFragmentTest
33         extends ActivityInstrumentationTestCase2<EditInfoActivity> {
34     private EditEmergencyContactsFragment mEditEmergencyContactsFragment;
35     private Preference mAddContactPreference;
36 
EditEmergencyContactsFragmentTest()37     public EditEmergencyContactsFragmentTest() {
38         super(EditInfoActivity.class);
39     }
40 
41     @Override
setUp()42     protected void setUp() throws Exception {
43         super.setUp();
44         mEditEmergencyContactsFragment = (EditEmergencyContactsFragment)
45                 getActivity().getFragments().get(1).second;
46         mAddContactPreference =
47                 mEditEmergencyContactsFragment.findPreference(PreferenceKeys.KEY_ADD_CONTACT);
48     }
49 
testAddContactPreference()50     public void testAddContactPreference() throws Throwable {
51         assertNotNull(mAddContactPreference);
52 
53         IntentFilter intentFilter = new IntentFilter(Intent.ACTION_PICK);
54         intentFilter.addDataType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
55 
56         Instrumentation.ActivityMonitor activityMonitor =
57                 getInstrumentation().addMonitor(intentFilter, null, true /* block */);
58 
59         runTestOnUiThread(new Runnable() {
60             @Override
61             public void run() {
62                 mAddContactPreference
63                         .getOnPreferenceClickListener().onPreferenceClick(mAddContactPreference);
64             }
65         });
66 
67         assertEquals(true, getInstrumentation().checkMonitorHit(activityMonitor, 1 /* minHits */));
68     }
69 }
70