1 /* 2 * Copyright (C) 2019 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 com.android.settings; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.spy; 22 import static org.mockito.Mockito.when; 23 import static org.robolectric.Shadows.shadowOf; 24 25 import android.app.Activity; 26 import android.content.Intent; 27 import android.view.View; 28 import android.widget.CheckBox; 29 30 import com.android.settings.network.SubscriptionUtil; 31 import com.android.settings.network.telephony.EuiccRacConnectivityDialogActivity; 32 33 import org.junit.Before; 34 import org.junit.Ignore; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.robolectric.Robolectric; 38 import org.robolectric.RobolectricTestRunner; 39 40 @RunWith(RobolectricTestRunner.class) 41 public class ResetNetworkTest { 42 private Activity mActivity; 43 private ResetNetwork mResetNetwork; 44 45 @Before setUp()46 public void setUp() { 47 mActivity = Robolectric.setupActivity(Activity.class); 48 mResetNetwork = spy(new ResetNetwork()); 49 when(mResetNetwork.getContext()).thenReturn(mActivity); 50 mResetNetwork.mEsimContainer = new View(mActivity); 51 mResetNetwork.mEsimCheckbox = new CheckBox(mActivity); 52 } 53 54 @Test 55 @Ignore showFinalConfirmation_checkboxVisible_eraseEsimChecked()56 public void showFinalConfirmation_checkboxVisible_eraseEsimChecked() { 57 SubscriptionUtil.setEnableRacDialogForTesting(true); 58 mResetNetwork.mEsimContainer.setVisibility(View.VISIBLE); 59 mResetNetwork.mEsimCheckbox.setChecked(true); 60 61 mResetNetwork.showFinalConfirmation(); 62 63 Intent intent = shadowOf(mActivity).getNextStartedActivity(); 64 assertThat(intent.getStringExtra(ResetNetworkRequest.KEY_ESIM_PACKAGE)) 65 .isNotNull(); 66 } 67 68 @Test showFinalConfirmation_checkboxVisible_eraseEsimChecked_showRacWarningDialog()69 public void showFinalConfirmation_checkboxVisible_eraseEsimChecked_showRacWarningDialog() { 70 SubscriptionUtil.setEnableRacDialogForTesting(true); 71 mResetNetwork.mEsimContainer.setVisibility(View.VISIBLE); 72 mResetNetwork.mEsimCheckbox.setChecked(true); 73 74 mResetNetwork.showFinalConfirmation(); 75 76 Intent intent = shadowOf(mActivity).getNextStartedActivity(); 77 78 assertThat(intent).isNotNull(); 79 assertThat(intent.getComponent().getClassName()).isEqualTo( 80 EuiccRacConnectivityDialogActivity.class.getName()); 81 } 82 83 @Test showFinalConfirmation_checkboxVisible_eraseEsimUnchecked()84 public void showFinalConfirmation_checkboxVisible_eraseEsimUnchecked() { 85 mResetNetwork.mEsimContainer.setVisibility(View.VISIBLE); 86 mResetNetwork.mEsimCheckbox.setChecked(false); 87 88 mResetNetwork.showFinalConfirmation(); 89 90 Intent intent = shadowOf(mActivity).getNextStartedActivity(); 91 assertThat(intent.getStringExtra(ResetNetworkRequest.KEY_ESIM_PACKAGE)) 92 .isNull(); 93 } 94 95 @Test showFinalConfirmation_checkboxGone_eraseEsimChecked()96 public void showFinalConfirmation_checkboxGone_eraseEsimChecked() { 97 mResetNetwork.mEsimContainer.setVisibility(View.GONE); 98 mResetNetwork.mEsimCheckbox.setChecked(true); 99 100 mResetNetwork.showFinalConfirmation(); 101 102 Intent intent = shadowOf(mActivity).getNextStartedActivity(); 103 assertThat(intent.getStringExtra(ResetNetworkRequest.KEY_ESIM_PACKAGE)) 104 .isNull(); 105 } 106 107 @Test showFinalConfirmation_checkboxGone_eraseEsimUnchecked()108 public void showFinalConfirmation_checkboxGone_eraseEsimUnchecked() { 109 mResetNetwork.mEsimContainer.setVisibility(View.GONE); 110 mResetNetwork.mEsimCheckbox.setChecked(false); 111 112 mResetNetwork.showFinalConfirmation(); 113 114 Intent intent = shadowOf(mActivity).getNextStartedActivity(); 115 assertThat(intent.getStringExtra(ResetNetworkRequest.KEY_ESIM_PACKAGE)) 116 .isNull(); 117 } 118 } 119