Merge "Go to the correct subscription in WifiCallingSettings" into qt-dev
am: 3b7cdfb708
Change-Id: I1405532c1c400a2c7d7af1397dea701bb424239a
This commit is contained in:
@@ -24,7 +24,9 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -88,6 +90,8 @@ public class WifiCallingPreferenceControllerTest {
|
||||
when(mPreferenceScreen.findPreference(
|
||||
WifiCallingPreferenceController.KEY_PREFERENCE_CATEGORY)).thenReturn(
|
||||
mPreferenceCategory);
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
|
||||
mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,6 +162,15 @@ public class WifiCallingPreferenceControllerTest {
|
||||
assertThat(mPreferenceCategory.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_available_setsSubscriptionIdOnIntent() {
|
||||
Intent intent = new Intent();
|
||||
mPreference.setIntent(intent);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID,
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(SUB_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noWiFiCalling_shouldReturnUnsupported() {
|
||||
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.calling;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.widget.RtlCompatibleViewPager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.shadows.androidx.fragment.FragmentController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiCallingSettingsTest {
|
||||
|
||||
private WifiCallingSettings mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFragment = spy(new WifiCallingSettings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupFragment_noSubscriptions_noCrash() {
|
||||
FragmentController.setupFragment(mFragment, FragmentActivity.class, 0 /* containerViewId*/,
|
||||
null /* bundle */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupFragment_oneSubscription_noCrash() {
|
||||
SubscriptionInfo info = mock(SubscriptionInfo.class);
|
||||
when(info.getSubscriptionId()).thenReturn(111);
|
||||
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
|
||||
Collections.singletonList(info)));
|
||||
doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class));
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
|
||||
FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
|
||||
null /* bundle */).start().resume().visible().get();
|
||||
|
||||
View view = mFragment.getView();
|
||||
RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
|
||||
WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
|
||||
(WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
|
||||
assertThat(adapter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupFragment_twoSubscriptions_correctSelection() {
|
||||
SubscriptionInfo info1 = mock(SubscriptionInfo.class);
|
||||
SubscriptionInfo info2 = mock(SubscriptionInfo.class);
|
||||
when(info1.getSubscriptionId()).thenReturn(111);
|
||||
when(info2.getSubscriptionId()).thenReturn(222);
|
||||
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
|
||||
Arrays.asList(info1, info2)));
|
||||
doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class));
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Settings.EXTRA_SUB_ID, info2.getSubscriptionId());
|
||||
FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
|
||||
null /* bundle */).start().resume().visible().get();
|
||||
|
||||
View view = mFragment.getView();
|
||||
RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
|
||||
assertThat(pager.getCurrentItem()).isEqualTo(1);
|
||||
|
||||
WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
|
||||
(WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
|
||||
assertThat(adapter.getCount()).isEqualTo(2);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user