Add click behavior to the storage item preferences.
This currently imitates the previous implementation behavior. The new mocks have a new intermediate view for some of these behaviors, but this view isn't ready yet. This patch should bring parity for the click functionality for the storage line item preferences. Bug: 33199077 Test: Settings Robo Tests Change-Id: I4f654d30add92e4eec721c36b2801f9af9824e78
This commit is contained in:
@@ -17,63 +17,129 @@ package com.android.settings.deviceinfo.storage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.deviceinfo.StorageItemPreference;
|
||||
import com.android.settings.applications.ManageApplications;
|
||||
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class StorageItemPreferenceControllerTest {
|
||||
private static final String KEY = "pref";
|
||||
private Context mContext;
|
||||
private VolumeInfo mVolume;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Fragment mFragment;
|
||||
@Mock
|
||||
private StorageVolumeProvider mSvp;
|
||||
private StorageItemPreferenceController mController;
|
||||
private PreferenceViewHolder mHolder;
|
||||
private StorageItemPreferenceAlternate mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mVolume = new VolumeInfo("id", 0, null, "id");
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new StorageItemPreferenceController(mContext, KEY);
|
||||
mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp);
|
||||
mPreference = new StorageItemPreferenceAlternate(mContext);
|
||||
|
||||
// Inflate the preference and the widget.
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(mContext), false);
|
||||
|
||||
mHolder = new PreferenceViewHolder(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetKey() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo(KEY);
|
||||
inflater.inflate(mPreference.getLayoutResource(), new LinearLayout(mContext), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStateWithInitialState() {
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Calculating…");
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||
mContext.getString(R.string.memory_calculating_size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceShouldUpdateAfterPopulatingData() {
|
||||
mController.setStorageSize(1024L);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("1.00KB");
|
||||
public void testClickPhotos() {
|
||||
mPreference.setKey("pref_photos_videos");
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(DocumentsContract.ACTION_BROWSE);
|
||||
assertThat(intent.getData()).isEqualTo(DocumentsContract.buildRootUri(
|
||||
"com.android.providers.media.documents",
|
||||
"images_root"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickAudio() {
|
||||
mPreference.setKey("pref_music_audio");
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(DocumentsContract.ACTION_BROWSE);
|
||||
assertThat(intent.getData()).isEqualTo(DocumentsContract.buildRootUri(
|
||||
"com.android.providers.media.documents",
|
||||
"audio_root"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickApps() {
|
||||
mPreference.setKey("pref_other_apps");
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
|
||||
ManageApplications.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickFiles() {
|
||||
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
|
||||
mPreference.setKey("pref_files");
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
Intent browseIntent = mVolume.buildBrowseIntent();
|
||||
assertThat(intent.getAction()).isEqualTo(browseIntent.getAction());
|
||||
assertThat(intent.getData()).isEqualTo(browseIntent.getData());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user