Re-add the progress bar for storage preferences.

This re-adds the progress bar and unifies the
StorageItemPreference and its alternate.

Change-Id: Iefc12b4b554306c706c83be232175dd2b84227b7
Fixes: 36223433
Test: Settings robotest
This commit is contained in:
Daniel Nishi
2017-03-15 14:00:13 -07:00
parent 9392681afa
commit cf0e659a6c
14 changed files with 183 additions and 203 deletions

View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) 2017 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;
/**
* Convenience methods and constants for testing.
*/
public class TestUtils {
public static final long KILOBYTE = 1024L; // TODO: Change to 1000 in O Robolectric.
public static final long MEGABYTE = KILOBYTE * KILOBYTE;
public static final long GIGABYTE = KILOBYTE * MEGABYTE;
}

View File

@@ -13,11 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.settings.deviceinfo.storage;
package com.android.settings.deviceinfo;
import static com.android.settings.TestUtils.KILOBYTE;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.LayoutInflater;
import android.widget.ProgressBar;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
@@ -29,28 +34,41 @@ import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class StorageItemPreferenceAlternateTest {
public class StorageItemPreferenceTest {
private Context mContext;
private StorageItemPreference mPreference;
@Before
public void setUp() throws Exception {
mContext = RuntimeEnvironment.application;
mPreference = new StorageItemPreference(mContext);
}
@Test
public void testBeforeLoad() {
StorageItemPreferenceAlternate pref = new StorageItemPreferenceAlternate(mContext);
assertThat(((String) pref.getSummary())).isEqualTo(
assertThat(mPreference.getSummary()).isEqualTo(
mContext.getString(R.string.memory_calculating_size));
}
@Test
public void testAfterLoad() {
StorageItemPreferenceAlternate pref = new StorageItemPreferenceAlternate(mContext);
pref.setStorageSize(1024L);
assertThat(((String) pref.getSummary())).isEqualTo("1.00KB");
mPreference.setStorageSize(KILOBYTE, KILOBYTE * 10);
assertThat(((String) mPreference.getSummary())).isEqualTo("1.00KB");
}
@Test
public void testProgressBarPercentageSet() {
final PreferenceViewHolder holder = new PreferenceViewHolder(
LayoutInflater.from(mContext).inflate(R.layout.storage_item, null));
final ProgressBar progressBar =
(ProgressBar) holder.itemView.findViewById(android.R.id.progress);
mPreference.onBindViewHolder(holder);
mPreference.setStorageSize(KILOBYTE, KILOBYTE * 10);
assertThat(progressBar.getProgress()).isEqualTo(10);
}
}

View File

@@ -15,6 +15,8 @@
*/
package com.android.settings.deviceinfo.storage;
import static com.android.settings.TestUtils.KILOBYTE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
@@ -43,6 +45,7 @@ import com.android.settings.SubSettings;
import com.android.settings.TestConfig;
import com.android.settings.applications.ManageApplications;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
@@ -60,11 +63,6 @@ import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class StorageItemPreferenceControllerTest {
/**
* In O, this will change to 1000 instead of 1024 due to the formatter properly defining a
* kilobyte.
*/
private static long KILOBYTE = 1024L;
private Context mContext;
private VolumeInfo mVolume;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -72,7 +70,7 @@ public class StorageItemPreferenceControllerTest {
@Mock
private StorageVolumeProvider mSvp;
private StorageItemPreferenceController mController;
private StorageItemPreferenceAlternate mPreference;
private StorageItemPreference mPreference;
private FakeFeatureFactory mFakeFeatureFactory;
private MetricsFeatureProvider mMetricsFeatureProvider;
@@ -87,7 +85,7 @@ public class StorageItemPreferenceControllerTest {
// Note: null is passed as the Lifecycle because we are handling it outside of the normal
// Settings fragment lifecycle for test purposes.
mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp);
mPreference = new StorageItemPreferenceAlternate(mContext);
mPreference = new StorageItemPreference(mContext);
// Inflate the preference and the widget.
LayoutInflater inflater = LayoutInflater.from(mContext);
@@ -190,12 +188,12 @@ public class StorageItemPreferenceControllerTest {
@Test
public void testMeasurementCompletedUpdatesPreferences() {
StorageItemPreferenceAlternate audio = new StorageItemPreferenceAlternate(mContext);
StorageItemPreferenceAlternate image = new StorageItemPreferenceAlternate(mContext);
StorageItemPreferenceAlternate games = new StorageItemPreferenceAlternate(mContext);
StorageItemPreferenceAlternate apps = new StorageItemPreferenceAlternate(mContext);
StorageItemPreferenceAlternate system = new StorageItemPreferenceAlternate(mContext);
StorageItemPreferenceAlternate files = new StorageItemPreferenceAlternate(mContext);
StorageItemPreference audio = new StorageItemPreference(mContext);
StorageItemPreference image = new StorageItemPreference(mContext);
StorageItemPreference games = new StorageItemPreference(mContext);
StorageItemPreference apps = new StorageItemPreference(mContext);
StorageItemPreference system = new StorageItemPreference(mContext);
StorageItemPreference files = new StorageItemPreference(mContext);
PreferenceScreen screen = mock(PreferenceScreen.class);
when(screen.findPreference(
eq(StorageItemPreferenceController.AUDIO_KEY))).thenReturn(audio);

View File

@@ -52,12 +52,13 @@ import org.robolectric.annotation.Config;
import java.io.File;
import static com.android.settings.TestUtils.KILOBYTE;
import static com.android.settings.TestUtils.MEGABYTE;
import static com.android.settings.TestUtils.GIGABYTE;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class StorageSummaryDonutPreferenceControllerTest {
private static final long KILOBYTE = 1024; // Note: When O comes around, this value changes!
private static final long MEGABYTE = KILOBYTE * KILOBYTE;
private static final long GIGABYTE = KILOBYTE * MEGABYTE;
private Context mContext;
private StorageSummaryDonutPreferenceController mController;
private StorageSummaryDonutPreference mPreference;