Merge "Remove Numbering System preference if no corresponding locale." into udc-dev

This commit is contained in:
Tom Hsu
2023-03-23 06:41:37 +00:00
committed by Android (Google) Code Review
6 changed files with 136 additions and 14 deletions

View File

@@ -19,18 +19,15 @@ package com.android.settings.regionalpreferences;
import static org.junit.Assert.assertEquals;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.os.Looper;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
public class NumberingPreferencesFragmentTest {
private Context mApplicationContext;
private NumberingPreferencesFragment mFragment;
@Before
@@ -39,7 +36,6 @@ public class NumberingPreferencesFragmentTest {
if (Looper.myLooper() == null) {
Looper.prepare();
}
mApplicationContext = ApplicationProvider.getApplicationContext();
mFragment = new NumberingPreferencesFragment();
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2023 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.regionalpreferences;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static org.junit.Assert.assertEquals;
import android.content.Context;
import android.os.LocaleList;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
public class NumberingSystemControllerTest {
private Context mApplicationContext;
private NumberingSystemController mController;
@Before
public void setUp() throws Exception {
mApplicationContext = ApplicationProvider.getApplicationContext();
}
@Test
public void getAvailabilityStatus_noLocale_unavailable() {
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW"));
mController = new NumberingSystemController(mApplicationContext, "key");
int result = mController.getAvailabilityStatus();
assertEquals(CONDITIONALLY_UNAVAILABLE, result);
}
@Test
public void getAvailabilityStatus_hasLocaleWithNumberingSystems_available() {
// ar-JO has different numbering system.
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW,ar-JO"));
mController = new NumberingSystemController(mApplicationContext, "key");
int result = mController.getAvailabilityStatus();
assertEquals(AVAILABLE, result);
}
}

View File

@@ -111,8 +111,8 @@ public class NumberingSystemItemControllerTest {
@Test
@UiThreadTest
public void displayPreference_languageOptAndHas2Locale_show2Options() {
LocaleList.setDefault(LocaleList.forLanguageTags("en-US, zh-TW"));
public void displayPreference_languageOptAndHas2LocaleWithSingleNu_showNothing() {
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW"));
Bundle bundle = new Bundle();
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT);
@@ -123,13 +123,31 @@ public class NumberingSystemItemControllerTest {
mController.displayPreference(mPreferenceScreen);
assertEquals(LocaleList.getDefault().size(), mPreferenceScreen.getPreferenceCount());
assertEquals(0, mPreferenceScreen.getPreferenceCount());
}
@Test
@UiThreadTest
public void displayPreference_languageOptAndHas2LocaleWithMultiNu_showLocaleWithMultiNuOnly() {
// ar-JO and dz-BT have multiple numbering systems.
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW,ar-JO,dz-BT"));
Bundle bundle = new Bundle();
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT);
bundle.putString(
NumberingSystemItemController.KEY_SELECTED_LANGUAGE, Locale.US.toLanguageTag());
mController = new NumberingSystemItemController(mApplicationContext, bundle);
mController.setParentFragment(mFragment);
mController.displayPreference(mPreferenceScreen);
assertEquals(2, mPreferenceScreen.getPreferenceCount());
}
@Test
@UiThreadTest
public void displayPreference_enUsNumbersOpt_show1Option() {
LocaleList.setDefault(LocaleList.forLanguageTags("en-US, zh-TW"));
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW"));
Bundle bundle = new Bundle();
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
NumberingSystemItemController.ARG_VALUE_NUMBERING_SYSTEM_SELECT);