Add erase eSIMs choice into factory reset

This CL add a check box for eSIM enabled devices to reset eSIM data
during factory reset of the phone.

Bug: 37255419
Test: Included
Change-Id: Ic98974726a515b0a350b73a33093460a63c1fb8a
This commit is contained in:
qingxi
2017-04-11 18:28:40 -07:00
parent 1562848a24
commit 072f28661d
5 changed files with 128 additions and 3 deletions

View File

@@ -17,36 +17,97 @@
package com.android.settings;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class MasterClearTest {
@Mock
private MasterClear mMasterClear;
@Mock
private ScrollView mScrollView;
@Mock
private LinearLayout mLinearLayout;
private ShadowActivity mShadowActivity;
private Activity mActivity;
private View mContentView;
private class ActivityForTest extends SettingsActivity {
private Bundle mArgs;
@Override
public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
mArgs = args;
}
public Bundle getArgs() {
return mArgs;
}
}
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mMasterClear = new MasterClear();
mMasterClear = spy(new MasterClear());
mActivity = Robolectric.setupActivity(Activity.class);
mShadowActivity = shadowOf(mActivity);
mContentView = LayoutInflater.from(mActivity).inflate(R.layout.master_clear, null);
// Make scrollView only have one child
when(mScrollView.getChildAt(0)).thenReturn(mLinearLayout);
when(mScrollView.getChildCount()).thenReturn(1);
}
@Test
public void testShowFinalConfirmation_EraseEsimChecked() {
ActivityForTest testActivity = new ActivityForTest();
when(mMasterClear.getActivity()).thenReturn(testActivity);
mMasterClear.mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
mMasterClear.mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
mMasterClear.mEsimStorage.setChecked(true);
mMasterClear.showFinalConfirmation();
assertThat(testActivity.getArgs().getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false))
.isTrue();
}
@Test
public void testShowFinalConfirmation_EraseEsimUnchecked() {
ActivityForTest testActivity = new ActivityForTest();
when(mMasterClear.getActivity()).thenReturn(testActivity);
mMasterClear.mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
mMasterClear.mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
mMasterClear.mEsimStorage.setChecked(false);
mMasterClear.showFinalConfirmation();
assertThat(testActivity.getArgs().getBoolean(MasterClear.ERASE_ESIMS_EXTRA, true))
.isFalse();
}
@Test
public void testHasReachedBottom_NotScrollDown_returnFalse() {
initScrollView(100, 0, 200);