Change base fragment to InstrumentedFragment
- Modify PrivateVolumeForget, PrivateVolumeFormat, PrivateVolumeUnmount - Add ShadowStorageManager - Add test cases Test: manual Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo Change-Id: I6883dd12cec00abbc3099bf31d285e6fe455eba6
This commit is contained in:
@@ -18,13 +18,13 @@ package com.android.settings.deviceinfo;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.VolumeRecord;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -35,11 +35,13 @@ import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.search.actionbar.SearchMenuController;
|
||||
|
||||
public class PrivateVolumeForget extends SettingsPreferenceFragment {
|
||||
private static final String TAG_FORGET_CONFIRM = "forget_confirm";
|
||||
public class PrivateVolumeForget extends InstrumentedFragment {
|
||||
@VisibleForTesting
|
||||
static final String TAG_FORGET_CONFIRM = "forget_confirm";
|
||||
|
||||
private VolumeRecord mRecord;
|
||||
|
||||
@@ -48,6 +50,13 @@ public class PrivateVolumeForget extends SettingsPreferenceFragment {
|
||||
return MetricsEvent.DEVICEINFO_STORAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setHasOptionsMenu(true);
|
||||
SearchMenuController.init(this /* host */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
@@ -116,12 +125,12 @@ public class PrivateVolumeForget extends SettingsPreferenceFragment {
|
||||
|
||||
builder.setPositiveButton(R.string.storage_menu_forget,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
storage.forgetVolume(fsUuid);
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
storage.forgetVolume(fsUuid);
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
|
||||
return builder.create();
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static android.os.storage.DiskInfo.EXTRA_DISK_ID;
|
||||
|
||||
import static com.android.settings.deviceinfo.StorageWizardBase.EXTRA_FORMAT_FORGET_UUID;
|
||||
import static com.android.settings.deviceinfo.StorageWizardBase.EXTRA_FORMAT_PRIVATE;
|
||||
|
||||
@@ -36,9 +35,9 @@ import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
|
||||
public class PrivateVolumeFormat extends InstrumentedPreferenceFragment {
|
||||
public class PrivateVolumeFormat extends InstrumentedFragment {
|
||||
private VolumeInfo mVolume;
|
||||
private DiskInfo mDisk;
|
||||
|
||||
|
@@ -30,10 +30,11 @@ import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
import com.android.settings.deviceinfo.StorageSettings.UnmountTask;
|
||||
import com.android.settings.search.actionbar.SearchMenuController;
|
||||
|
||||
public class PrivateVolumeUnmount extends SettingsPreferenceFragment {
|
||||
public class PrivateVolumeUnmount extends InstrumentedFragment {
|
||||
private VolumeInfo mVolume;
|
||||
private DiskInfo mDisk;
|
||||
|
||||
@@ -42,6 +43,13 @@ public class PrivateVolumeUnmount extends SettingsPreferenceFragment {
|
||||
return MetricsEvent.DEVICEINFO_STORAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setHasOptionsMenu(true);
|
||||
SearchMenuController.init(this /* host */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
@@ -1,5 +1,4 @@
|
||||
com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment
|
||||
com.android.settings.deviceinfo.PrivateVolumeForget
|
||||
com.android.settings.inputmethod.SpellCheckersSettings
|
||||
com.android.settings.fuelgauge.InactiveApps
|
||||
com.android.settings.accessibility.CaptionPropertiesFragment
|
||||
@@ -43,7 +42,6 @@ com.android.settings.accessibility.ToggleAccessibilityServicePreferenceFragment
|
||||
com.android.settings.print.PrintServiceSettingsFragment
|
||||
com.android.settings.deviceinfo.PrivateVolumeSettings
|
||||
com.android.settings.users.AppRestrictionsFragment
|
||||
com.android.settings.deviceinfo.PrivateVolumeUnmount
|
||||
com.android.settings.notification.ZenAccessSettings
|
||||
com.android.settings.accessibility.ToggleFontSizePreferenceFragment
|
||||
com.android.settings.applications.PremiumSmsAccess
|
||||
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.deviceinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.storage.VolumeRecord;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.deviceinfo.PrivateVolumeForget.ForgetConfirmFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowStorageManager;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowStorageManager.class)
|
||||
public class PrivateVolumeForgetTest {
|
||||
|
||||
private PrivateVolumeForget mFragment;
|
||||
private Activity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(VolumeRecord.EXTRA_FS_UUID, "id");
|
||||
mFragment = Robolectric.buildFragment(PrivateVolumeForget.class,
|
||||
bundle).create().start().resume().get();
|
||||
mActivity = mFragment.getActivity();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowStorageManager.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void OnClickListener_shouldCallForget() {
|
||||
assertThat(ShadowStorageManager.isForgetCalled()).isFalse();
|
||||
|
||||
final Button confirm = mFragment.getView().findViewById(R.id.confirm);
|
||||
|
||||
confirm.performClick();
|
||||
final ForgetConfirmFragment confirmFragment =
|
||||
(ForgetConfirmFragment) mActivity.getFragmentManager().findFragmentByTag(
|
||||
PrivateVolumeForget.TAG_FORGET_CONFIRM);
|
||||
|
||||
assertThat(confirmFragment).isNotNull();
|
||||
|
||||
final AlertDialog dialog = (AlertDialog) confirmFragment.getDialog();
|
||||
final Button forget = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
|
||||
forget.performClick();
|
||||
|
||||
assertThat(ShadowStorageManager.isForgetCalled()).isTrue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.deviceinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowStorageManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowStorageManager.class)
|
||||
public class PrivateVolumeFormatTest {
|
||||
|
||||
private PrivateVolumeFormat mFragment;
|
||||
private ShadowActivity mShadowActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(VolumeInfo.EXTRA_VOLUME_ID, "id");
|
||||
mFragment = Robolectric.buildFragment(PrivateVolumeFormat.class,
|
||||
bundle).create().start().resume().get();
|
||||
mShadowActivity = shadowOf(mFragment.getActivity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void OnClickListener_shouldStartStorageWizardFormatProgress() {
|
||||
final Button confirm = mFragment.getView().findViewById(R.id.confirm);
|
||||
|
||||
confirm.performClick();
|
||||
final Intent intent = mShadowActivity.getNextStartedActivity();
|
||||
|
||||
assertThat(intent.getComponent()).isEqualTo(
|
||||
new ComponentName(RuntimeEnvironment.application.getPackageName(),
|
||||
StorageWizardFormatProgress.class.getName()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.deviceinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowStorageManager;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowStorageManager.class)
|
||||
public class PrivateVolumeUnmountTest {
|
||||
|
||||
private PrivateVolumeUnmount mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(VolumeInfo.EXTRA_VOLUME_ID, "id");
|
||||
mFragment = Robolectric.buildFragment(PrivateVolumeUnmount.class,
|
||||
bundle).create().start().resume().get();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowStorageManager.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void OnClickListener_shouldCallUnmount() {
|
||||
assertThat(ShadowStorageManager.isUnmountCalled()).isFalse();
|
||||
|
||||
Button confirm = (Button) mFragment.getView().findViewById(R.id.confirm);
|
||||
|
||||
confirm.performClick();
|
||||
|
||||
assertThat(ShadowStorageManager.isUnmountCalled()).isTrue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.testutils.shadow;
|
||||
|
||||
import android.os.storage.DiskInfo;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.os.storage.VolumeRecord;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@Implements(StorageManager.class)
|
||||
public class ShadowStorageManager {
|
||||
|
||||
private static boolean sIsUnmountCalled;
|
||||
private static boolean sIsForgetCalled;
|
||||
|
||||
public static boolean isUnmountCalled() {
|
||||
return sIsUnmountCalled;
|
||||
}
|
||||
|
||||
public static boolean isForgetCalled() {
|
||||
return sIsForgetCalled;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sIsUnmountCalled = false;
|
||||
sIsForgetCalled = false;
|
||||
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public VolumeInfo findVolumeById(String id) {
|
||||
return createVolumeInfo(id);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public DiskInfo findDiskById(String id) {
|
||||
return new DiskInfo(id, DiskInfo.FLAG_SD);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public VolumeRecord findRecordByUuid(String fsUuid) {
|
||||
return createVolumeRecord(fsUuid);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public void unmount(String volId) {
|
||||
sIsUnmountCalled = true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public void forgetVolume(String fsUuid) {
|
||||
sIsForgetCalled = true;
|
||||
}
|
||||
|
||||
private VolumeInfo createVolumeInfo(String volumeId) {
|
||||
final DiskInfo disk = new DiskInfo("fakeid", 0);
|
||||
return new VolumeInfo(volumeId, 0, disk, "guid");
|
||||
}
|
||||
|
||||
private VolumeRecord createVolumeRecord(String fsUuid) {
|
||||
VolumeRecord record = new VolumeRecord(VolumeRecord.USER_FLAG_INITED, fsUuid);
|
||||
record.nickname = "nickname";
|
||||
return record;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user