Search in sources :

Example 96 with RadioButtonPreference

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

the class NetworkScorerPickerTest method testUpdateCandidates_validScorers_noActiveScorer.

@Test
public void testUpdateCandidates_validScorers_noActiveScorer() {
    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(null);
    ArgumentCaptor<RadioButtonPreference> arg = ArgumentCaptor.forClass(RadioButtonPreference.class);
    mFragment.updateCandidates();
    verify(mPreferenceScreen, times(2)).addPreference(arg.capture());
    final RadioButtonPreference nonePref = arg.getAllValues().get(0);
    assertThat(nonePref.getKey()).isNull();
    assertThat(nonePref.isChecked()).isTrue();
    final RadioButtonPreference testScorerPref = arg.getAllValues().get(1);
    assertThat(testScorerPref.getTitle()).isEqualTo(TEST_SCORER_LABEL_1);
    assertThat(testScorerPref.isChecked()).isFalse();
}
Also used : ComponentName(android.content.ComponentName) NetworkScorerAppData(android.net.NetworkScorerAppData) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 97 with RadioButtonPreference

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

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 98 with RadioButtonPreference

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

the class WebViewAppPickerTest method testWebViewVersionAddedAfterLabel.

/**
 * Ensure that the version name of a WebView package is displayed after its name in the
 * preference title.
 */
@Test
public void testWebViewVersionAddedAfterLabel() throws PackageManager.NameNotFoundException {
    PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
    mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
    when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
    DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager, mockPackageItemInfo, "");
    PackageInfo packageInfo = new PackageInfo();
    packageInfo.versionName = "myVersionName";
    PackageManager pm = mock(PackageManager.class);
    when(pm.getPackageInfo(eq(DEFAULT_PACKAGE_NAME), anyInt())).thenReturn(packageInfo);
    when(mPackageManager.getPackageManager()).thenReturn(pm);
    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)).setTitle(eq("myPackage myVersionName"));
    verify(mockPreference, times(1)).setTitle(any());
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) PackageItemInfo(android.content.pm.PackageItemInfo) DefaultAppInfo(com.android.settings.applications.defaultapps.DefaultAppInfo) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 99 with RadioButtonPreference

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

the class WebViewAppPickerTest method testSuccessfulClickChangesProvider.

private void testSuccessfulClickChangesProvider() {
    when(mWvusWrapper.getValidWebViewApplicationInfos(any())).thenReturn(Arrays.asList(createApplicationInfo(DEFAULT_PACKAGE_NAME)));
    when(mWvusWrapper.setWebViewProvider(eq(DEFAULT_PACKAGE_NAME))).thenReturn(true);
    RadioButtonPreference defaultPackagePref = mock(RadioButtonPreference.class);
    when(defaultPackagePref.getKey()).thenReturn(DEFAULT_PACKAGE_NAME);
    mPicker.onRadioButtonClicked(defaultPackagePref);
    verify(mWvusWrapper, times(1)).setWebViewProvider(eq(DEFAULT_PACKAGE_NAME));
    verify(mPicker, times(1)).updateCheckedState(DEFAULT_PACKAGE_NAME);
    verify(mWvusWrapper, never()).showInvalidChoiceToast(any());
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference)

Example 100 with RadioButtonPreference

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

the class WebViewAppPickerTest method testFailingClickUpdatesSetting.

private void testFailingClickUpdatesSetting() {
    when(mWvusWrapper.getValidWebViewApplicationInfos(any())).thenReturn(Arrays.asList(createApplicationInfo(DEFAULT_PACKAGE_NAME)));
    when(mWvusWrapper.setWebViewProvider(eq(DEFAULT_PACKAGE_NAME))).thenReturn(false);
    RadioButtonPreference defaultPackagePref = mock(RadioButtonPreference.class);
    when(defaultPackagePref.getKey()).thenReturn(DEFAULT_PACKAGE_NAME);
    mPicker.onRadioButtonClicked(defaultPackagePref);
    verify(mWvusWrapper, times(1)).setWebViewProvider(eq(DEFAULT_PACKAGE_NAME));
    // Ensure we update the list of packages when we click a non-valid package - the list must
    // have changed, otherwise this click wouldn't fail.
    verify(mPicker, times(1)).updateCandidates();
    verify(mWvusWrapper, times(1)).showInvalidChoiceToast(any());
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference)

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