Merge "Refactor DefaultAppPicker to a general radio button picker"
This commit is contained in:
committed by
Android (Google) Code Review
commit
bc27c06c5b
@@ -61,12 +61,12 @@ public class DefaultAssistPickerTest {
|
||||
final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
|
||||
assistants.add(new DefaultAssistPicker.Info(TEST_ASSIST));
|
||||
ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
|
||||
mPicker.setDefaultAppKey(TEST_ASSIST.flattenToString());
|
||||
mPicker.setDefaultKey(TEST_ASSIST.flattenToString());
|
||||
|
||||
assertThat(Settings.Secure.getString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT))
|
||||
.isEqualTo(TEST_ASSIST.flattenToString());
|
||||
assertThat(mPicker.getDefaultAppKey())
|
||||
assertThat(mPicker.getDefaultKey())
|
||||
.isEqualTo(TEST_ASSIST.flattenToString());
|
||||
}
|
||||
|
||||
@@ -74,12 +74,12 @@ public class DefaultAssistPickerTest {
|
||||
public void setDefaultAppKey_noAvaialbleAssit_shouldClearDefaultAssist() {
|
||||
final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
|
||||
ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
|
||||
mPicker.setDefaultAppKey(TEST_ASSIST.flattenToString());
|
||||
mPicker.setDefaultKey(TEST_ASSIST.flattenToString());
|
||||
|
||||
assertThat(Settings.Secure.getString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT))
|
||||
.isEmpty();
|
||||
assertThat(mPicker.getDefaultAppKey())
|
||||
assertThat(mPicker.getDefaultKey())
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@@ -88,12 +88,12 @@ public class DefaultAssistPickerTest {
|
||||
final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
|
||||
assistants.add(new DefaultAssistPicker.Info(TEST_ASSIST));
|
||||
ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
|
||||
mPicker.setDefaultAppKey(null);
|
||||
mPicker.setDefaultKey(null);
|
||||
|
||||
assertThat(Settings.Secure.getString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT))
|
||||
.isEmpty();
|
||||
assertThat(mPicker.getDefaultAppKey())
|
||||
assertThat(mPicker.getDefaultKey())
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
|
@@ -17,13 +17,17 @@
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageItemInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -32,60 +36,44 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultAppInfoTest {
|
||||
|
||||
@Mock
|
||||
private ActivityInfo mActivityInfo;
|
||||
@Mock
|
||||
private ApplicationInfo mApplicationInfo;
|
||||
private PackageItemInfo mPackageItemInfo;
|
||||
@Mock
|
||||
private ComponentName mComponentName;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private PackageManagerWrapper mPackageManagerWrapper;
|
||||
|
||||
private DefaultAppInfo mInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mPackageManagerWrapper.getPackageManager()).thenReturn(mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoWithActivityInfo_shouldLoadInfo() {
|
||||
mActivityInfo.packageName = "test";
|
||||
mInfo = new DefaultAppInfo(mActivityInfo);
|
||||
mInfo.loadLabel(mPackageManager);
|
||||
mInfo.loadIcon(mPackageManager);
|
||||
mPackageItemInfo.packageName = "test";
|
||||
mInfo = new DefaultAppInfo(mPackageManagerWrapper, mPackageItemInfo);
|
||||
mInfo.loadLabel();
|
||||
mInfo.loadIcon();
|
||||
|
||||
assertThat(mInfo.getKey()).isEqualTo(mActivityInfo.packageName);
|
||||
verify(mActivityInfo).loadLabel(mPackageManager);
|
||||
verify(mActivityInfo).loadIcon(mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoWithApplicationInfo_shouldLoadInfo() {
|
||||
mApplicationInfo.packageName = "test";
|
||||
|
||||
mInfo = new DefaultAppInfo(mApplicationInfo);
|
||||
mInfo.loadLabel(mPackageManager);
|
||||
mInfo.loadIcon(mPackageManager);
|
||||
|
||||
assertThat(mInfo.getKey()).isEqualTo(mApplicationInfo.packageName);
|
||||
verify(mApplicationInfo).loadLabel(mPackageManager);
|
||||
verify(mApplicationInfo).loadIcon(mPackageManager);
|
||||
assertThat(mInfo.getKey()).isEqualTo(mPackageItemInfo.packageName);
|
||||
verify(mPackageItemInfo).loadLabel(mPackageManager);
|
||||
verify(mPackageItemInfo).loadIcon(mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoWithComponent_shouldLoadInfo() {
|
||||
when(mComponentName.getPackageName()).thenReturn("com.android.settings");
|
||||
|
||||
mInfo = new DefaultAppInfo(0 /* uid */, mComponentName);
|
||||
mInfo = new DefaultAppInfo(mPackageManagerWrapper, 0 /* uid */, mComponentName);
|
||||
mInfo.getKey();
|
||||
|
||||
verify(mComponentName).flattenToString();
|
||||
|
@@ -17,11 +17,15 @@
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
@@ -40,13 +44,6 @@ import org.robolectric.annotation.Config;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultAppPickerFragmentTest {
|
||||
@@ -57,8 +54,6 @@ public class DefaultAppPickerFragmentTest {
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private FragmentManager mFragmentManager;
|
||||
|
||||
private TestFragment mFragment;
|
||||
|
||||
@@ -66,9 +61,6 @@ public class DefaultAppPickerFragmentTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFragment = spy(new TestFragment());
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(DefaultAppPickerFragment.EXTRA_FOR_WORK, false);
|
||||
mFragment.setArguments(bundle);
|
||||
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
doReturn(mActivity).when(mFragment).getContext();
|
||||
@@ -76,26 +68,7 @@ public class DefaultAppPickerFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAttach_userIsInitialized() {
|
||||
mFragment.onAttach((Context) mActivity);
|
||||
|
||||
verify(mActivity).getPackageManager();
|
||||
verify(mActivity).getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickPreference_noCofirmation_shouldDirectlyConfirm() {
|
||||
final RadioButtonPreference pref =
|
||||
new RadioButtonPreference(RuntimeEnvironment.application);
|
||||
pref.setKey("TEST");
|
||||
|
||||
mFragment.onRadioButtonClicked(pref);
|
||||
|
||||
assertThat(mFragment.setDefaultAppKeyCalled).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickPreference_hasCofirmation_shouldShowConfirmation() {
|
||||
public void clickPreference_hasConfirmation_shouldShowConfirmation() {
|
||||
final RadioButtonPreference pref =
|
||||
new RadioButtonPreference(RuntimeEnvironment.application);
|
||||
pref.setKey("TEST");
|
||||
@@ -106,18 +79,6 @@ public class DefaultAppPickerFragmentTest {
|
||||
mFragment.onRadioButtonClicked(pref);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displaySingleOption_shouldSelectRadioButton() {
|
||||
final RadioButtonPreference pref =
|
||||
new RadioButtonPreference(RuntimeEnvironment.application);
|
||||
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||
when(mScreen.getPreference(0)).thenReturn(pref);
|
||||
|
||||
mFragment.mayCheckOnlyRadioButton();
|
||||
|
||||
assertThat(pref.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
public static class TestFragment extends DefaultAppPickerFragment {
|
||||
|
||||
boolean setDefaultAppKeyCalled;
|
||||
@@ -133,12 +94,12 @@ public class DefaultAppPickerFragmentTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
protected String getDefaultKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String key) {
|
||||
protected boolean setDefaultKey(String key) {
|
||||
setDefaultAppKeyCalled = true;
|
||||
return true;
|
||||
}
|
||||
|
@@ -17,6 +17,10 @@
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -33,10 +37,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultAppPreferenceControllerTest {
|
||||
@@ -62,7 +62,7 @@ public class DefaultAppPreferenceControllerTest {
|
||||
public void updateState_hasDefaultApp_shouldUpdateAppName() {
|
||||
mController = new TestPreferenceController(mContext);
|
||||
|
||||
when(mController.mAppInfo.loadLabel(mContext.getPackageManager()))
|
||||
when(mController.mAppInfo.loadLabel())
|
||||
.thenReturn(TEST_APP_NAME);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
@@ -16,9 +16,14 @@
|
||||
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
@@ -36,13 +41,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@@ -73,14 +71,14 @@ public class DefaultAutofillPickerTest {
|
||||
|
||||
@Test
|
||||
public void setAndGetDefaultAppKey_shouldUpdateDefaultAutoFill() {
|
||||
assertThat(mPicker.setDefaultAppKey(TEST_APP_KEY)).isTrue();
|
||||
assertThat(mPicker.getDefaultAppKey()).isEqualTo(TEST_APP_KEY);
|
||||
assertThat(mPicker.setDefaultKey(TEST_APP_KEY)).isTrue();
|
||||
assertThat(mPicker.getDefaultKey()).isEqualTo(TEST_APP_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConfirmationMessage_shouldNotBeNull() {
|
||||
final DefaultAppInfo info = mock(DefaultAppInfo.class);
|
||||
when(info.loadLabel(any(PackageManager.class))).thenReturn("test_app_name");
|
||||
when(info.loadLabel()).thenReturn("test_app_name");
|
||||
assertThat(mPicker.getConfirmationMessage(info)).isNotNull();
|
||||
}
|
||||
|
||||
|
@@ -67,14 +67,14 @@ public class DefaultBrowserPickerTest {
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_shouldUpdateDefaultBrowser() {
|
||||
mPicker.setDefaultAppKey(TEST_APP_KEY);
|
||||
mPicker.setDefaultKey(TEST_APP_KEY);
|
||||
verify(mPackageManager)
|
||||
.setDefaultBrowserPackageNameAsUser(eq(TEST_APP_KEY), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultAppKey_shouldReturnDefaultBrowser() {
|
||||
mPicker.getDefaultAppKey();
|
||||
mPicker.getDefaultKey();
|
||||
verify(mPackageManager)
|
||||
.getDefaultBrowserPackageNameAsUser(anyInt());
|
||||
}
|
||||
|
@@ -70,8 +70,8 @@ public class DefaultEmergencyPickerTest {
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_shouldUpdateDefault() {
|
||||
assertThat(mPicker.setDefaultAppKey(TEST_APP_KEY)).isTrue();
|
||||
assertThat(mPicker.getDefaultAppKey()).isEqualTo(TEST_APP_KEY);
|
||||
assertThat(mPicker.setDefaultKey(TEST_APP_KEY)).isTrue();
|
||||
assertThat(mPicker.getDefaultKey()).isEqualTo(TEST_APP_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,6 +80,6 @@ public class DefaultEmergencyPickerTest {
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION,
|
||||
TEST_APP_KEY);
|
||||
|
||||
assertThat(mPicker.getDefaultAppKey()).isEqualTo(TEST_APP_KEY);
|
||||
assertThat(mPicker.getDefaultKey()).isEqualTo(TEST_APP_KEY);
|
||||
}
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ public class DefaultHomePickerTest {
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_shouldUpdateDefault() {
|
||||
assertThat(mPicker.setDefaultAppKey(TEST_APP_KEY)).isTrue();
|
||||
assertThat(mPicker.setDefaultKey(TEST_APP_KEY)).isTrue();
|
||||
|
||||
verify(mPackageManager).replacePreferredActivity(any(IntentFilter.class),
|
||||
anyInt(), any(ComponentName[].class), any(ComponentName.class));
|
||||
@@ -83,7 +83,7 @@ public class DefaultHomePickerTest {
|
||||
final ComponentName cn = mock(ComponentName.class);
|
||||
when(mPackageManager.getHomeActivities(anyList()))
|
||||
.thenReturn(cn);
|
||||
mPicker.getDefaultAppKey();
|
||||
mPicker.getDefaultKey();
|
||||
verify(cn).flattenToString();
|
||||
}
|
||||
|
||||
|
@@ -70,9 +70,9 @@ public class DefaultNotificationAssistantPickerTest {
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_shouldUpdateDefault() {
|
||||
mPicker.setDefaultAppKey(TEST_APP_KEY);
|
||||
mPicker.setDefaultKey(TEST_APP_KEY);
|
||||
|
||||
assertThat(mPicker.getDefaultAppKey()).isEqualTo(TEST_APP_KEY);
|
||||
assertThat(mPicker.getDefaultKey()).isEqualTo(TEST_APP_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,6 +81,6 @@ public class DefaultNotificationAssistantPickerTest {
|
||||
Settings.Secure.ENABLED_NOTIFICATION_ASSISTANT,
|
||||
TEST_APP_KEY);
|
||||
|
||||
assertThat(mPicker.getDefaultAppKey()).isEqualTo(TEST_APP_KEY);
|
||||
assertThat(mPicker.getDefaultKey()).isEqualTo(TEST_APP_KEY);
|
||||
}
|
||||
}
|
||||
|
@@ -75,14 +75,14 @@ public class DefaultPhonePickerTest {
|
||||
|
||||
@Test
|
||||
public void getSystemDefaultPackage_shouldAskDefaultKeyUpdater() {
|
||||
mPicker.getSystemDefaultAppKey();
|
||||
mPicker.getSystemDefaultKey();
|
||||
|
||||
verify(mDefaultKeyUpdater).getSystemDialerPackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_shouldUpdateDefault() {
|
||||
mPicker.setDefaultAppKey(TEST_APP_KEY);
|
||||
mPicker.setDefaultKey(TEST_APP_KEY);
|
||||
|
||||
verify(mDefaultKeyUpdater).setDefaultDialerApplication(
|
||||
any(Context.class), eq(TEST_APP_KEY), anyInt());
|
||||
@@ -90,7 +90,7 @@ public class DefaultPhonePickerTest {
|
||||
|
||||
@Test
|
||||
public void getDefaultAppKey_shouldReturnDefault() {
|
||||
mPicker.getDefaultAppKey();
|
||||
mPicker.getDefaultKey();
|
||||
verify(mDefaultKeyUpdater).getDefaultDialerApplication(any(Context.class), anyInt());
|
||||
}
|
||||
}
|
||||
|
@@ -73,14 +73,14 @@ public class DefaultSmsPickerTest {
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_shouldUpdateDefault() {
|
||||
mPicker.setDefaultAppKey(TEST_APP_KEY);
|
||||
mPicker.setDefaultKey(TEST_APP_KEY);
|
||||
|
||||
verify(mDefaultKeyUpdater).setDefaultApplication(any(Context.class), eq(TEST_APP_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultAppKey_shouldReturnDefault() {
|
||||
mPicker.getDefaultAppKey();
|
||||
mPicker.getDefaultKey();
|
||||
|
||||
verify(mDefaultKeyUpdater).getDefaultApplication(any(Context.class));
|
||||
}
|
||||
|
@@ -46,8 +46,6 @@ import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.applications.defaultapps.DefaultAppInfo;
|
||||
import com.android.settings.widget.RadioButtonPreference;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -58,6 +56,8 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class WebViewAppPickerTest {
|
||||
@@ -162,13 +162,14 @@ public class WebViewAppPickerTest {
|
||||
@Test
|
||||
public void testDisabledPackageShownAsDisabled() {
|
||||
String disabledReason = "disabled";
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager,
|
||||
createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
|
||||
|
||||
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
|
||||
mPicker.configurePreferenceFromAppInfo(mockPreference,
|
||||
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));
|
||||
}
|
||||
@@ -176,13 +177,14 @@ public class WebViewAppPickerTest {
|
||||
@Test
|
||||
public void testEnabledPackageShownAsEnabled() {
|
||||
String disabledReason = "";
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager,
|
||||
createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
|
||||
|
||||
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
|
||||
mPicker.configurePreferenceFromAppInfo(mockPreference,
|
||||
mPicker.bindPreference(mockPreference,
|
||||
DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
|
||||
mPicker.bindPreferenceExtra(mockPreference,
|
||||
DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
|
||||
|
||||
verify(mockPreference, times(1)).setEnabled(eq(true));
|
||||
verify(mockPreference, never()).setEnabled(eq(false));
|
||||
}
|
||||
@@ -190,13 +192,14 @@ public class WebViewAppPickerTest {
|
||||
@Test
|
||||
public void testDisabledPackageShowsDisabledReasonSummary() {
|
||||
String disabledReason = "disabled";
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager,
|
||||
createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
|
||||
|
||||
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
|
||||
mPicker.configurePreferenceFromAppInfo(mockPreference,
|
||||
mPicker.bindPreference(mockPreference,
|
||||
DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
|
||||
mPicker.bindPreferenceExtra(mockPreference,
|
||||
DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
|
||||
|
||||
verify(mockPreference, times(1)).setSummary(eq(disabledReason));
|
||||
// Ensure we haven't called setSummary several times.
|
||||
verify(mockPreference, times(1)).setSummary(any());
|
||||
@@ -205,13 +208,14 @@ public class WebViewAppPickerTest {
|
||||
@Test
|
||||
public void testEnabledPackageShowsEmptySummary() {
|
||||
String disabledReason = null;
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager,
|
||||
createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
|
||||
|
||||
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
|
||||
mPicker.configurePreferenceFromAppInfo(mockPreference,
|
||||
mPicker.bindPreference(mockPreference,
|
||||
DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
|
||||
mPicker.bindPreferenceExtra(mockPreference,
|
||||
DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
|
||||
|
||||
verify(mockPreference, never()).setSummary(any());
|
||||
}
|
||||
|
||||
@@ -242,7 +246,7 @@ public class WebViewAppPickerTest {
|
||||
WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
|
||||
when(wvusWrapper.getPackageInfosAllUsers(
|
||||
any(), eq(DEFAULT_PACKAGE_NAME))).thenReturn(
|
||||
Arrays.asList(packageForFirstUser, packageForSecondUser));
|
||||
Arrays.asList(packageForFirstUser, packageForSecondUser));
|
||||
|
||||
assertThat(mPicker.getDisabledReason(wvusWrapper, mContext, DEFAULT_PACKAGE_NAME)).isNull();
|
||||
}
|
||||
@@ -255,8 +259,8 @@ public class WebViewAppPickerTest {
|
||||
when(packageForFirstUser.getUserInfo()).thenReturn(FIRST_USER);
|
||||
|
||||
WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
|
||||
when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)
|
||||
)).thenReturn(Arrays.asList(packageForFirstUser));
|
||||
when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)))
|
||||
.thenReturn(Arrays.asList(packageForFirstUser));
|
||||
|
||||
final String EXPECTED_DISABLED_REASON = String.format(
|
||||
"(disabled for user %s)", FIRST_USER.name);
|
||||
@@ -272,8 +276,8 @@ public class WebViewAppPickerTest {
|
||||
when(packageForFirstUser.getUserInfo()).thenReturn(FIRST_USER);
|
||||
|
||||
WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
|
||||
when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)
|
||||
)).thenReturn(Arrays.asList(packageForFirstUser));
|
||||
when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)))
|
||||
.thenReturn(Arrays.asList(packageForFirstUser));
|
||||
|
||||
final String EXPECTED_DISABLED_REASON = String.format(
|
||||
"(uninstalled for user %s)", FIRST_USER.name);
|
||||
@@ -294,13 +298,13 @@ public class WebViewAppPickerTest {
|
||||
when(packageForSecondUser.getUserInfo()).thenReturn(SECOND_USER);
|
||||
|
||||
WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
|
||||
when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)
|
||||
)).thenReturn(Arrays.asList(packageForFirstUser, packageForSecondUser));
|
||||
when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)))
|
||||
.thenReturn(Arrays.asList(packageForFirstUser, packageForSecondUser));
|
||||
|
||||
final String EXPECTED_DISABLED_REASON = String.format(
|
||||
"(disabled for user %s)", FIRST_USER.name);
|
||||
assertThat(mPicker.getDisabledReason(
|
||||
wvusWrapper, mContext,DEFAULT_PACKAGE_NAME)).isEqualTo(EXPECTED_DISABLED_REASON);
|
||||
wvusWrapper, mContext, DEFAULT_PACKAGE_NAME)).isEqualTo(EXPECTED_DISABLED_REASON);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,8 +324,8 @@ public class WebViewAppPickerTest {
|
||||
when(packageForSecondUser.getUserInfo()).thenReturn(SECOND_USER);
|
||||
|
||||
WebViewUpdateServiceWrapper wvusWrapper = mock(WebViewUpdateServiceWrapper.class);
|
||||
when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)
|
||||
)).thenReturn(Arrays.asList(packageForFirstUser, packageForSecondUser));
|
||||
when(wvusWrapper.getPackageInfosAllUsers(any(), eq(DEFAULT_PACKAGE_NAME)))
|
||||
.thenReturn(Arrays.asList(packageForFirstUser, packageForSecondUser));
|
||||
|
||||
final String EXPECTED_DISABLED_REASON = String.format(
|
||||
"(uninstalled for user %s)", FIRST_USER.name);
|
||||
@@ -338,7 +342,7 @@ public class WebViewAppPickerTest {
|
||||
PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
|
||||
mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
|
||||
when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
|
||||
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager,
|
||||
mockPackageItemInfo, "" /* disabledReason */);
|
||||
|
||||
PackageInfo packageInfo = new PackageInfo();
|
||||
@@ -348,9 +352,10 @@ public class WebViewAppPickerTest {
|
||||
when(mPackageManager.getPackageManager()).thenReturn(pm);
|
||||
|
||||
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
|
||||
mPicker.configurePreferenceFromAppInfo(mockPreference,
|
||||
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());
|
||||
}
|
||||
|
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.defaultapps.DefaultAppInfo;
|
||||
import com.android.settings.applications.defaultapps.DefaultAppPickerFragment;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class RadioButtonPickerFragmentTest {
|
||||
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
private TestFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFragment = spy(new TestFragment());
|
||||
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
doReturn(mActivity).when(mFragment).getContext();
|
||||
doReturn(mScreen).when(mFragment).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAttach_userIsInitialized() {
|
||||
mFragment.onAttach((Context) mActivity);
|
||||
|
||||
verify(mActivity).getPackageManager();
|
||||
verify(mActivity).getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displaySingleOption_shouldSelectRadioButton() {
|
||||
final RadioButtonPreference pref =
|
||||
new RadioButtonPreference(RuntimeEnvironment.application);
|
||||
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||
when(mScreen.getPreference(0)).thenReturn(pref);
|
||||
|
||||
mFragment.mayCheckOnlyRadioButton();
|
||||
|
||||
assertThat(pref.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickPreference_shouldConfirm() {
|
||||
final RadioButtonPreference pref =
|
||||
new RadioButtonPreference(RuntimeEnvironment.application);
|
||||
pref.setKey("TEST");
|
||||
|
||||
mFragment.onRadioButtonClicked(pref);
|
||||
|
||||
assertThat(mFragment.setDefaultKeyCalled).isTrue();
|
||||
}
|
||||
|
||||
public static class TestFragment extends DefaultAppPickerFragment {
|
||||
|
||||
boolean setDefaultKeyCalled;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultAppInfo> getCandidates() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
setDefaultKeyCalled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return RuntimeEnvironment.application;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user