Merge "Add controllers for iinstant app related preferences."
This commit is contained in:
committed by
Android (Google) Code Review
commit
fb72d22784
@@ -23,13 +23,10 @@ import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -37,16 +34,10 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
@@ -246,101 +237,6 @@ public final class AppInfoDashboardFragmentTest {
|
||||
verify(mAppDetail.mActionButtons).setButton2Visible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantApps_buttonControllerHandlesDialog() {
|
||||
InstantAppButtonsController mockController = mock(InstantAppButtonsController.class);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mInstantAppButtonsController", mockController);
|
||||
// Make sure first that button controller is not called for supported dialog id
|
||||
AlertDialog mockDialog = mock(AlertDialog.class);
|
||||
when(mockController.createDialog(InstantAppButtonsController.DLG_CLEAR_APP))
|
||||
.thenReturn(mockDialog);
|
||||
assertThat(mAppDetail.createDialog(InstantAppButtonsController.DLG_CLEAR_APP, 0))
|
||||
.isEqualTo(mockDialog);
|
||||
verify(mockController).createDialog(InstantAppButtonsController.DLG_CLEAR_APP);
|
||||
}
|
||||
|
||||
// A helper class for testing the InstantAppButtonsController - it lets us look up the
|
||||
// preference associated with a key for instant app buttons and get back a mock
|
||||
// LayoutPreference (to avoid a null pointer exception).
|
||||
public static class InstalledAppDetailsWithMockInstantButtons extends InstalledAppDetails {
|
||||
@Mock
|
||||
private LayoutPreference mInstantButtons;
|
||||
|
||||
public InstalledAppDetailsWithMockInstantButtons() {
|
||||
super();
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preference findPreference(CharSequence key) {
|
||||
if (key == "instant_app_buttons") {
|
||||
return mInstantButtons;
|
||||
}
|
||||
return super.findPreference(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantApps_instantSpecificButtons() {
|
||||
// Make this app appear to be instant.
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
|
||||
final InstalledAppDetailsWithMockInstantButtons
|
||||
fragment = new InstalledAppDetailsWithMockInstantButtons();
|
||||
ReflectionHelpers.setField(fragment, "mPackageInfo", packageInfo);
|
||||
ReflectionHelpers.setField(fragment, "mApplicationFeatureProvider",
|
||||
mFeatureFactory.applicationFeatureProvider);
|
||||
|
||||
final InstantAppButtonsController buttonsController =
|
||||
mock(InstantAppButtonsController.class);
|
||||
when(buttonsController.setPackageName(nullable(String.class)))
|
||||
.thenReturn(buttonsController);
|
||||
when(mFeatureFactory.applicationFeatureProvider.newInstantAppButtonsController(
|
||||
nullable(Fragment.class), nullable(View.class), nullable(ShowDialogDelegate.class)))
|
||||
.thenReturn(buttonsController);
|
||||
|
||||
fragment.maybeAddInstantAppButtons();
|
||||
verify(buttonsController).setPackageName(nullable(String.class));
|
||||
verify(buttonsController).show();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantApps_removeCorrectPref() {
|
||||
PreferenceScreen mockPreferenceScreen = mock(PreferenceScreen.class);
|
||||
PreferenceManager mockPreferenceManager = mock(PreferenceManager.class);
|
||||
AppDomainsPreference mockAppDomainsPref = mock(AppDomainsPreference.class);
|
||||
PackageInfo mockPackageInfo = mock(PackageInfo.class);
|
||||
PackageManager mockPackageManager = mock(PackageManager.class);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mInstantAppDomainsPreference", mockAppDomainsPref);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mPreferenceManager", mockPreferenceManager);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mPackageInfo", mockPackageInfo);
|
||||
ReflectionHelpers.setField(
|
||||
mAppDetail, "mPm", mockPackageManager);
|
||||
when(mockPreferenceManager.getPreferenceScreen()).thenReturn(mockPreferenceScreen);
|
||||
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> false));
|
||||
mAppDetail.prepareInstantAppPrefs();
|
||||
|
||||
// For the non instant case we remove the app domain pref, and leave the launch pref
|
||||
verify(mockPreferenceScreen).removePreference(mockAppDomainsPref);
|
||||
|
||||
// For the instant app case we remove the launch preff, and leave the app domain pref
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
|
||||
mAppDetail.prepareInstantAppPrefs();
|
||||
// Will be 1 still due to above call
|
||||
verify(mockPreferenceScreen, times(1))
|
||||
.removePreference(mockAppDomainsPref);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_uninstalledUpdates_shouldInvalidateOptionsMenu() {
|
||||
doReturn(true).when(mAppDetail).refreshUi();
|
||||
|
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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.applications.appinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.AppInfoDashboardFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AppInstallerInfoPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private ApplicationInfo mAppInfo;
|
||||
@Mock
|
||||
private AppInfoDashboardFragment mFragment;
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
|
||||
private Context mContext;
|
||||
private AppInstallerInfoPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws PackageManager.NameNotFoundException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
final String installerPackage = "Installer1";
|
||||
when(mPackageManager.getInstallerPackageName(anyString())).thenReturn(installerPackage);
|
||||
when(mPackageManager.getApplicationInfo(eq(installerPackage), anyInt()))
|
||||
.thenReturn(mAppInfo);
|
||||
mController = new AppInstallerInfoPreferenceController(mContext, mFragment, "Package1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_managedProfile_shouldReturnDisabled() {
|
||||
when(mUserManager.isManagedProfile()).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noAppLabel_shouldReturnDisabled() {
|
||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hasAppLabel_shouldReturnAvailable() {
|
||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||
when(mAppInfo.loadLabel(mPackageManager)).thenReturn("Label1");
|
||||
mController = new AppInstallerInfoPreferenceController(mContext, mFragment, "Package1");
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldSetSummary() {
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
packageInfo.applicationInfo = mAppInfo;
|
||||
when(mFragment.getPackageInfo()).thenReturn(packageInfo);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setSummary(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_noAppStoreLink_shouldDisablePreference() {
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
packageInfo.applicationInfo = mAppInfo;
|
||||
when(mFragment.getPackageInfo()).thenReturn(packageInfo);
|
||||
when(mPackageManager.resolveActivity(any(), anyInt())).thenReturn(null);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_hasAppStoreLink_shouldSetPreferenceIntent() {
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
packageInfo.applicationInfo = mAppInfo;
|
||||
when(mFragment.getPackageInfo()).thenReturn(packageInfo);
|
||||
final ResolveInfo resolveInfo = new ResolveInfo();
|
||||
resolveInfo.activityInfo = new ActivityInfo();
|
||||
resolveInfo.activityInfo.packageName = "Pkg1";
|
||||
resolveInfo.activityInfo.name = "Name1";
|
||||
when(mPackageManager.resolveActivity(any(), anyInt())).thenReturn(resolveInfo);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference, never()).setEnabled(false);
|
||||
verify(mPreference).setIntent(any(Intent.class));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.applications.appinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.AppInfoDashboardFragment;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class InstantAppButtonsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private ApplicationInfo mAppInfo;
|
||||
@Mock
|
||||
private AppInfoDashboardFragment mFragment;
|
||||
|
||||
private Context mContext;
|
||||
private InstantAppButtonsPreferenceController mController;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() throws PackageManager.NameNotFoundException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
packageInfo.applicationInfo = mAppInfo;
|
||||
when(mFragment.getPackageInfo()).thenReturn(packageInfo);
|
||||
mController =
|
||||
spy(new InstantAppButtonsPreferenceController(mContext, mFragment, "Package1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_notInstantApp_shouldReturnDisabled() {
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> false));
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_isInstantApp_shouldReturnAvailable() {
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_shouldSetPreferenceTitle() {
|
||||
final PreferenceScreen screen = mock(PreferenceScreen.class);
|
||||
final LayoutPreference preference = mock(LayoutPreference.class);
|
||||
when(screen.findPreference(mController.getPreferenceKey())).thenReturn(preference);
|
||||
when(mController.getApplicationFeatureProvider())
|
||||
.thenReturn(mFeatureFactory.applicationFeatureProvider);
|
||||
final InstantAppButtonsController buttonsController =
|
||||
mock(InstantAppButtonsController.class);
|
||||
when(buttonsController.setPackageName(nullable(String.class)))
|
||||
.thenReturn(buttonsController);
|
||||
when(mFeatureFactory.applicationFeatureProvider.newInstantAppButtonsController(
|
||||
nullable(Fragment.class), nullable(View.class),
|
||||
nullable(InstantAppButtonsController.ShowDialogDelegate.class)))
|
||||
.thenReturn(buttonsController);
|
||||
|
||||
mController.displayPreference(screen);
|
||||
|
||||
verify(buttonsController).setPackageName(nullable(String.class));
|
||||
verify(buttonsController).show();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDialog_shouldReturnDialogFromButtonController() {
|
||||
final InstantAppButtonsController buttonsController =
|
||||
mock(InstantAppButtonsController.class);
|
||||
ReflectionHelpers.setField(
|
||||
mController, "mInstantAppButtonsController", buttonsController);
|
||||
final AlertDialog mockDialog = mock(AlertDialog.class);
|
||||
when(buttonsController.createDialog(InstantAppButtonsController.DLG_CLEAR_APP))
|
||||
.thenReturn(mockDialog);
|
||||
|
||||
assertThat(mController.createDialog(InstantAppButtonsController.DLG_CLEAR_APP))
|
||||
.isEqualTo(mockDialog);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.applications.appinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IntentFilterVerificationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.AppDomainsPreference;
|
||||
import com.android.settings.applications.AppInfoDashboardFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class InstantAppDomainsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private ApplicationInfo mAppInfo;
|
||||
@Mock
|
||||
private AppInfoDashboardFragment mFragment;
|
||||
@Mock
|
||||
private AppDomainsPreference mPreference;
|
||||
|
||||
private Context mContext;
|
||||
private InstantAppDomainsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws PackageManager.NameNotFoundException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
packageInfo.applicationInfo = mAppInfo;
|
||||
packageInfo.packageName = "Package1";
|
||||
when(mFragment.getPackageInfo()).thenReturn(packageInfo);
|
||||
mController = new InstantAppDomainsPreferenceController(mContext, mFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_notInstantApp_shouldReturnDisabled() {
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> false));
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_isInstantApp_shouldReturnAvailable() {
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (i -> true));
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldSetPreferenceTitle() {
|
||||
final String[] domain = { "Domain1" };
|
||||
final ArraySet<String> domains = new ArraySet<>();
|
||||
domains.add(domain[0]);
|
||||
final List<IntentFilterVerificationInfo> infoList = new ArrayList<>();
|
||||
final IntentFilterVerificationInfo info =
|
||||
new IntentFilterVerificationInfo("Package1", domains);
|
||||
infoList.add(info);
|
||||
|
||||
when(mPackageManager.getIntentFilterVerifications("Package1")).thenReturn(infoList);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setTitles(domain);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user