Search in sources :

Example 66 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by LineageOS.

the class WebViewAppPickerTest method testDisabledPackageShownAsDisabled.

@Test
public void testDisabledPackageShownAsDisabled() {
    String disabledReason = "disabled";
    DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager, createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
    RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
    mPicker.bindPreference(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
    mPicker.bindPreferenceExtra(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
    verify(mockPreference, times(1)).setEnabled(eq(false));
    verify(mockPreference, never()).setEnabled(eq(true));
}
Also used : DefaultAppInfo(com.android.settings.applications.defaultapps.DefaultAppInfo) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 67 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by LineageOS.

the class NetworkScorerPickerTest method testOnRadioButtonClicked_currentScorer_doNothing.

@Test
public void testOnRadioButtonClicked_currentScorer_doNothing() {
    RadioButtonPreference pref = new RadioButtonPreference(mContext);
    pref.setKey(TEST_SCORER_PACKAGE_1);
    pref.setChecked(true);
    when(mPreferenceScreen.getPreference(anyInt())).thenReturn(pref);
    when(mPreferenceScreen.getPreferenceCount()).thenReturn(1);
    when(mNetworkScoreManager.setActiveScorer(TEST_SCORER_PACKAGE_1)).thenReturn(true);
    when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_1);
    mFragment.onRadioButtonClicked(pref);
    verify(mNetworkScoreManager, never()).setActiveScorer(any());
    assertThat(pref.isChecked()).isTrue();
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 68 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by LineageOS.

the class NetworkScorerPickerTest method testUpdateCandidates_validScorer.

@Test
public void testUpdateCandidates_validScorer() {
    ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE_1, TEST_SCORER_CLASS_1);
    NetworkScorerAppData scorerAppData = new NetworkScorerAppData(0, scorer, TEST_SCORER_LABEL_1, null, /* enableUseOpenWifiActivity */
    null);
    when(mNetworkScoreManager.getAllValidScorers()).thenReturn(Lists.newArrayList(scorerAppData));
    when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_1);
    ArgumentCaptor<RadioButtonPreference> arg = ArgumentCaptor.forClass(RadioButtonPreference.class);
    mFragment.updateCandidates();
    // The first preference added is the "none" preference and the second is the
    // pref for the test scorer.
    verify(mPreferenceScreen, times(2)).addPreference(arg.capture());
    // Returns the last captured value which is expected to be the test scorer pref.
    RadioButtonPreference pref = arg.getValue();
    assertThat(pref.getTitle()).isEqualTo(TEST_SCORER_LABEL_1);
    assertThat(pref.isChecked()).isTrue();
}
Also used : ComponentName(android.content.ComponentName) NetworkScorerAppData(android.net.NetworkScorerAppData) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 69 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.

the class DefaultAppPickerFragmentTest method clickPreference_hasConfirmation_shouldShowConfirmation.

@Test
public void clickPreference_hasConfirmation_shouldShowConfirmation() {
    mFragment.onAttach((Context) mActivity);
    final RadioButtonPreference pref = new RadioButtonPreference(RuntimeEnvironment.application);
    pref.setKey("TEST");
    doReturn("confirmation_text").when(mFragment).getConfirmationMessage(any(DefaultAppInfo.class));
    doReturn(mActivity).when(mFragment).getActivity();
    mFragment.onRadioButtonClicked(pref);
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 70 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.

the class NetworkScorerPickerTest method testOnRadioButtonClicked_success.

@Test
public void testOnRadioButtonClicked_success() {
    RadioButtonPreference pref = new RadioButtonPreference(mContext);
    pref.setKey(TEST_SCORER_PACKAGE_1);
    when(mPreferenceScreen.getPreference(anyInt())).thenReturn(pref);
    when(mPreferenceScreen.getPreferenceCount()).thenReturn(1);
    when(mNetworkScoreManager.setActiveScorer(TEST_SCORER_PACKAGE_1)).thenReturn(true);
    when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_2);
    mFragment.onRadioButtonClicked(pref);
    verify(mNetworkScoreManager).setActiveScorer(TEST_SCORER_PACKAGE_1);
    assertThat(pref.isChecked()).isTrue();
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Aggregations

RadioButtonPreference (com.android.settings.widget.RadioButtonPreference)122 Test (org.junit.Test)80 DefaultAppInfo (com.android.settings.applications.defaultapps.DefaultAppInfo)30 NetworkScorerAppData (android.net.NetworkScorerAppData)21 PreferenceScreen (android.support.v7.preference.PreferenceScreen)18 ComponentName (android.content.ComponentName)14 Preference (android.support.v7.preference.Preference)12 PackageInfo (android.content.pm.PackageInfo)6 PackageItemInfo (android.content.pm.PackageItemInfo)6 PackageManager (android.content.pm.PackageManager)6 VisibleForTesting (android.support.annotation.VisibleForTesting)6 DefaultAppInfo (com.android.settingslib.applications.DefaultAppInfo)6 PreferenceCategory (androidx.preference.PreferenceCategory)2 PreferenceScreen (androidx.preference.PreferenceScreen)2 Before (org.junit.Before)2 Resources (android.content.res.Resources)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 Preference (androidx.preference.Preference)1 PreferenceManager (androidx.preference.PreferenceManager)1 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)1