Add conent description for talkback to announce, if the progress bar is 50%, then before modification is "Progress bar", and after modification is "50% Progress bar". Bug: 146811265 Test: Add following unit test case to test if content description is correct or not: createPref_progressBarShouldSetPercentageContentDescription(). Change-Id: I71483df8e12f08c4c8c96ab3964666bf97872a83
105 lines
3.8 KiB
Java
105 lines
3.8 KiB
Java
/*
|
|
* 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.datausage;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import android.graphics.Color;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.widget.ProgressBar;
|
|
|
|
import androidx.preference.PreferenceViewHolder;
|
|
|
|
import com.android.settingslib.AppItem;
|
|
import com.android.settingslib.net.UidDetail;
|
|
import com.android.settingslib.net.UidDetailProvider;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.mockito.Mock;
|
|
import org.mockito.MockitoAnnotations;
|
|
import org.robolectric.RobolectricTestRunner;
|
|
import org.robolectric.RuntimeEnvironment;
|
|
|
|
@RunWith(RobolectricTestRunner.class)
|
|
public class AppDataUsagePreferenceTest {
|
|
private static final String FIFTY_PERCENT = "50%";
|
|
|
|
@Mock
|
|
private UidDetailProvider mUidDetailProvider;
|
|
private AppItem mAppItem;
|
|
private UidDetail mUidDetail;
|
|
|
|
private AppDataUsagePreference mPreference;
|
|
|
|
@Before
|
|
public void setUp() {
|
|
MockitoAnnotations.initMocks(this);
|
|
mAppItem = new AppItem(123);
|
|
mUidDetail = new UidDetail();
|
|
mUidDetail.icon = new ColorDrawable(Color.BLUE);
|
|
mUidDetail.label = "title";
|
|
}
|
|
|
|
@Test
|
|
public void createPref_hasCachedUidDetail_shouldSetAppInfo() {
|
|
when(mUidDetailProvider.getUidDetail(mAppItem.key, false /* blocking */))
|
|
.thenReturn(mUidDetail);
|
|
|
|
mPreference = new AppDataUsagePreference(RuntimeEnvironment.application, mAppItem,
|
|
50 /* percent */, mUidDetailProvider);
|
|
|
|
assertThat(mPreference.getTitle()).isEqualTo(mUidDetail.label);
|
|
assertThat(mPreference.getIcon()).isEqualTo(mUidDetail.icon);
|
|
}
|
|
|
|
@Test
|
|
public void createPref_noCachedUidDetail_shouldSetAppInfo() {
|
|
when(mUidDetailProvider.getUidDetail(mAppItem.key, true /* blocking */))
|
|
.thenReturn(mUidDetail);
|
|
|
|
mPreference = new AppDataUsagePreference(RuntimeEnvironment.application, mAppItem,
|
|
50 /* percent */, mUidDetailProvider);
|
|
|
|
assertThat(mPreference.getTitle()).isEqualTo(mUidDetail.label);
|
|
assertThat(mPreference.getIcon()).isEqualTo(mUidDetail.icon);
|
|
}
|
|
|
|
@Test
|
|
public void createPref_progressBarShouldSetPercentageContentDescription() {
|
|
when(mUidDetailProvider.getUidDetail(mAppItem.key, true /* blocking */))
|
|
.thenReturn(mUidDetail);
|
|
mPreference = new AppDataUsagePreference(RuntimeEnvironment.application, mAppItem,
|
|
50 /* percent */, mUidDetailProvider);
|
|
final View view = LayoutInflater.from(RuntimeEnvironment.application).inflate(
|
|
com.android.settingslib.R.layout.preference_app, null);
|
|
final PreferenceViewHolder preferenceViewHolder =
|
|
PreferenceViewHolder.createInstanceForTests(view);
|
|
final ProgressBar progressBar = (ProgressBar) preferenceViewHolder.findViewById(
|
|
android.R.id.progress);
|
|
|
|
mPreference.onBindViewHolder(preferenceViewHolder);
|
|
|
|
assertThat(progressBar.getContentDescription()).isEqualTo(FIFTY_PERCENT);
|
|
}
|
|
}
|