Merge "Uses a custom state description for the Audio Balance seek bar." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
034e6db92e
@@ -28,23 +28,32 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.content.Context;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowSystemSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowSystemSettings.class,
|
||||
})
|
||||
public class BalanceSeekBarTest {
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
// Fix the maximum process value to 200 for testing the BalanceSeekBar.
|
||||
// It affects the SeekBar value of center(100) and snapThreshold(200 * SNAP_TO_PERCENTAGE).
|
||||
private static final int MAX_PROGRESS_VALUE = 200;
|
||||
@@ -143,6 +152,58 @@ public class BalanceSeekBarTest {
|
||||
assertThat(mSeekBar.getProgress()).isEqualTo(progressWithoutThreshold);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_AUDIO_BALANCE_STATE_DESCRIPTION)
|
||||
public void onProgressChanged_getStateDescription_centered_leftFirst() {
|
||||
// Seek bar centered
|
||||
int progress = (int) (0.50f * MAX_PROGRESS_VALUE);
|
||||
mSeekBar.setMax(MAX_PROGRESS_VALUE);
|
||||
|
||||
mProxySeekBarListener.onProgressChanged(mSeekBar, progress, true);
|
||||
|
||||
assertThat(mSeekBar.getStateDescription()).isEqualTo(
|
||||
mContext.getString(R.string.audio_seek_bar_state_left_first, 50, 50));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_AUDIO_BALANCE_STATE_DESCRIPTION)
|
||||
public void onProgressChanged_getStateDescription_centered_rtl_rightFirst() {
|
||||
// RTL layout
|
||||
mContext.getResources().getConfiguration().setLayoutDirection(new Locale("iw", "IL"));
|
||||
// Seek bar centered
|
||||
int progress = (int) (0.50f * MAX_PROGRESS_VALUE);
|
||||
mSeekBar.setMax(MAX_PROGRESS_VALUE);
|
||||
|
||||
mProxySeekBarListener.onProgressChanged(mSeekBar, progress, true);
|
||||
|
||||
assertThat(mSeekBar.getStateDescription()).isEqualTo(
|
||||
mContext.getString(R.string.audio_seek_bar_state_right_first, 50, 50));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_AUDIO_BALANCE_STATE_DESCRIPTION)
|
||||
public void onProgressChanged_getStateDescription_25percent_leftFirst() {
|
||||
// Seek bar 3/4th toward the left
|
||||
int progress = (int) (0.25f * MAX_PROGRESS_VALUE);
|
||||
mSeekBar.setMax(MAX_PROGRESS_VALUE);
|
||||
mProxySeekBarListener.onProgressChanged(mSeekBar, progress, true);
|
||||
|
||||
assertThat(mSeekBar.getStateDescription()).isEqualTo(
|
||||
mContext.getString(R.string.audio_seek_bar_state_left_first, 75, 25));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_AUDIO_BALANCE_STATE_DESCRIPTION)
|
||||
public void onProgressChanged_getStateDescription_75percent_rightFirst() {
|
||||
// Seek bar 3/4th toward the right
|
||||
int progress = (int) (0.75f * MAX_PROGRESS_VALUE);
|
||||
mSeekBar.setMax(MAX_PROGRESS_VALUE);
|
||||
mProxySeekBarListener.onProgressChanged(mSeekBar, progress, true);
|
||||
|
||||
assertThat(mSeekBar.getStateDescription()).isEqualTo(
|
||||
mContext.getString(R.string.audio_seek_bar_state_right_first, 75, 25));
|
||||
}
|
||||
|
||||
// method to get the center from BalanceSeekBar for testing setMax().
|
||||
private int getBalanceSeekBarCenter(BalanceSeekBar seekBar) {
|
||||
return seekBar.getMax() / 2;
|
||||
|
Reference in New Issue
Block a user