• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.phone.euicc;
17 
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertNull;
21 import static org.mockito.Mockito.when;
22 
23 import android.content.Context;
24 import android.content.Intent;
25 import android.content.pm.ActivityInfo;
26 import android.support.test.InstrumentationRegistry;
27 import android.support.test.runner.AndroidJUnit4;
28 import android.telephony.euicc.EuiccManager;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 
36 @RunWith(AndroidJUnit4.class)
37 public class EuiccUiDispatcherActivityTest {
38     private static final Intent MANAGE_INTENT =
39             new Intent(EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS);
40     private static final Intent PROVISION_INTENT =
41             new Intent(EuiccManager.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION);
42 
43     private static final ActivityInfo ACTIVITY_INFO = new ActivityInfo();
44     static {
45         ACTIVITY_INFO.packageName = "test.package";
46         ACTIVITY_INFO.name = "TestClass";
47     }
48 
49     @Mock private Context mMockContext;
50     @Mock private EuiccManager mMockEuiccManager;
51     private ActivityInfo mActivityInfo = ACTIVITY_INFO;
52     private Intent mIntent = MANAGE_INTENT;
53     private EuiccUiDispatcherActivity mActivity;
54 
55     @Before
setUp()56     public void setUp() {
57         MockitoAnnotations.initMocks(this);
58         when(mMockEuiccManager.isEnabled()).thenReturn(true);
59         when(mMockContext.getSystemService(Context.EUICC_SERVICE)).thenReturn(mMockEuiccManager);
60         InstrumentationRegistry.getInstrumentation().runOnMainSync(
61                 new Runnable() {
62                     @Override
63                     public void run() {
64                         mActivity = new TestEuiccUiDispatcherActivity();
65                     }
66                 }
67         );
68     }
69 
70     @Test
testResolveEuiccUiIntent_disabled()71     public void testResolveEuiccUiIntent_disabled() {
72         when(mMockEuiccManager.isEnabled()).thenReturn(false);
73         assertNull(mActivity.resolveEuiccUiIntent());
74     }
75 
76     @Test
testResolveEuiccUiIntent_unsupportedAction()77     public void testResolveEuiccUiIntent_unsupportedAction() {
78         mIntent = new Intent("fake.action");
79         assertNull(mActivity.resolveEuiccUiIntent());
80     }
81 
82     @Test
testResolveEuiccUiIntent_noImplementation()83     public void testResolveEuiccUiIntent_noImplementation() {
84         mActivityInfo = null;
85         assertNull(mActivity.resolveEuiccUiIntent());
86     }
87 
88     @Test
testResolveEuiccUiIntent_validManage()89     public void testResolveEuiccUiIntent_validManage() {
90         assertNotNull(mActivity.resolveEuiccUiIntent());
91     }
92 
93     @Test
testResolveEuiccUiIntent_validProvision()94     public void testResolveEuiccUiIntent_validProvision() {
95         assertNotNull(mActivity.resolveEuiccUiIntent());
96     }
97 
98     @Test
testExtrasPropagated()99     public void testExtrasPropagated() {
100         mIntent.putExtra("foo", "bar");
101 
102         Intent euiccUiIntent = mActivity.resolveEuiccUiIntent();
103         assertNotNull(euiccUiIntent);
104         assertEquals("bar", euiccUiIntent.getStringExtra("foo"));
105     }
106 
107     class TestEuiccUiDispatcherActivity extends EuiccUiDispatcherActivity {
TestEuiccUiDispatcherActivity()108         public TestEuiccUiDispatcherActivity() {
109             attachBaseContext(mMockContext);
110         }
111 
112         @Override
getIntent()113         public Intent getIntent() {
114             return mIntent;
115         }
116 
117         @Override
findBestActivity(Intent euiccUiIntent)118         ActivityInfo findBestActivity(Intent euiccUiIntent) {
119             return mActivityInfo;
120         }
121 
122         @Override
grantDefaultPermissionsToActiveLuiApp(ActivityInfo activityInfo)123         protected void grantDefaultPermissionsToActiveLuiApp(ActivityInfo activityInfo) {}
124 
125         @Override
revokePermissionFromLuiApps(Intent intent)126         protected void revokePermissionFromLuiApps(Intent intent) {}
127     }
128 }
129