diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9f6cdb50487..651ef48eb5b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -620,8 +620,7 @@ + android:label="@string/assist_and_voice_input_title"> @@ -795,7 +794,8 @@ + android:icon="@drawable/ic_wallpaper" + android:exported="true"> @@ -2454,6 +2454,18 @@ android:value="true" /> + + + + + + + + - + diff --git a/res/layout-land/wifi_dpp_qrcode_scanner_fragment.xml b/res/layout-land/wifi_dpp_qrcode_scanner_fragment.xml index c408a977106..887d0fbfe91 100644 --- a/res/layout-land/wifi_dpp_qrcode_scanner_fragment.xml +++ b/res/layout-land/wifi_dpp_qrcode_scanner_fragment.xml @@ -43,7 +43,7 @@ android:layout_marginBottom="8dp" style="?android:attr/progressBarStyleHorizontal"/> - - + - + + android:layout_height="0dp" + app:layout_constraintDimensionRatio="1:1"/> - + android:layout_height="0dp" + app:layout_constraintDimensionRatio="1:1"/> + @android:color/black - #dadce0 #82000000 @android:color/black #783BE5 diff --git a/res/values-night/themes.xml b/res/values-night/themes.xml index 8deae1cb359..2227b889bb3 100644 --- a/res/values-night/themes.xml +++ b/res/values-night/themes.xml @@ -29,9 +29,7 @@ ?android:attr/colorAccent - + @@ -103,6 +103,7 @@ @color/switchbar_switch_track_tint @color/switchbar_switch_thumb_tint @dimen/min_tap_target_size + @dimen/min_tap_target_size diff --git a/tests/robotests/src/com/android/settings/SetupWizardUtilsTest.java b/tests/robotests/src/com/android/settings/SetupWizardUtilsTest.java index f718a67412c..b965d788338 100644 --- a/tests/robotests/src/com/android/settings/SetupWizardUtilsTest.java +++ b/tests/robotests/src/com/android/settings/SetupWizardUtilsTest.java @@ -31,24 +31,27 @@ import org.robolectric.RobolectricTestRunner; @RunWith(RobolectricTestRunner.class) public class SetupWizardUtilsTest { + private static final String EXTRA_IS_SETUP_FLOW = "isSetupFlow"; + private static final String EXTRA_IS_FIRST_RUN = "firstRun"; + @Test public void testCopySetupExtras() { Intent fromIntent = new Intent(); final String theme = "TEST_THEME"; fromIntent.putExtra(WizardManagerHelper.EXTRA_THEME, theme); - fromIntent.putExtra(WizardManagerHelper.EXTRA_USE_IMMERSIVE_MODE, true); + fromIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true); Intent toIntent = new Intent(); SetupWizardUtils.copySetupExtras(fromIntent, toIntent); assertThat(theme).isEqualTo(toIntent.getStringExtra(WizardManagerHelper.EXTRA_THEME)); - assertThat(toIntent.getBooleanExtra(WizardManagerHelper.EXTRA_USE_IMMERSIVE_MODE, false)) + assertThat(toIntent.getBooleanExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, false)) .isTrue(); } @Test public void testGetTheme_withIntentExtra_shouldReturnExtraTheme() { SetupWizardProperties.theme(ThemeHelper.THEME_GLIF); - Intent intent = new Intent(); + Intent intent = createSetupWizardIntent(); intent.putExtra(WizardManagerHelper.EXTRA_THEME, ThemeHelper.THEME_GLIF_V2); assertThat(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV2Theme); @@ -57,7 +60,7 @@ public class SetupWizardUtilsTest { @Test public void testGetTheme_withEmptyIntent_shouldReturnSystemProperty() { SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V2_LIGHT); - Intent intent = new Intent(); + Intent intent = createSetupWizardIntent(); assertThat(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV2Theme_Light); } @@ -65,10 +68,26 @@ public class SetupWizardUtilsTest { @Test public void testGetTheme_glifV3Light_shouldReturnThemeResource() { SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V3_LIGHT); - Intent intent = new Intent(); + Intent intent = createSetupWizardIntent(); assertThat(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV3Theme_Light); assertThat(SetupWizardUtils.getTransparentTheme(intent)) .isEqualTo(R.style.GlifV3Theme_Light_Transparent); } + + @Test + public void testGetTheme_nonSuw_shouldReturnDayNightTheme() { + SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V3_LIGHT); + Intent intent = new Intent(); + + assertThat(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV3Theme); + assertThat(SetupWizardUtils.getTransparentTheme(intent)) + .isEqualTo(R.style.GlifV3Theme_Transparent); + } + + private Intent createSetupWizardIntent() { + return new Intent() + .putExtra(EXTRA_IS_SETUP_FLOW, true) + .putExtra(EXTRA_IS_FIRST_RUN, true); + } } diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java index 8c53019eebb..0cc9dc43375 100644 --- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java @@ -156,7 +156,7 @@ public class AccessibilitySettingsTest { @Test public void testDarkUIModePreferenceSummary_shouldUpdateSummary() { - final ListPreference darkUIModePreference = new ListPreference(mContext); + final Preference darkUIModePreference = new Preference(mContext); final DarkUIPreferenceController mController; doReturn(darkUIModePreference).when(mSettings).findPreference( DARK_UI_MODE_PREFERENCE); diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java index 59aea3de99c..6d9430ccd26 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java @@ -119,7 +119,6 @@ public class AppButtonsPreferenceControllerTest { mController = spy(new AppButtonsPreferenceController(mSettingsActivity, mFragment, mLifecycle, PACKAGE_NAME, mState, REQUEST_UNINSTALL, REQUEST_REMOVE_DEVICE_ADMIN)); - doReturn(false).when(mController).isFallbackPackage(anyString()); mAppEntry.info = mAppInfo; mAppInfo.packageName = PACKAGE_NAME; diff --git a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java index c01ef3fa56e..ff3a36f2574 100644 --- a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java @@ -20,6 +20,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import android.app.Activity; import android.app.admin.DevicePolicyManager; @@ -33,6 +38,8 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.TextView; +import androidx.appcompat.app.AlertDialog; + import com.android.settings.R; import com.android.settings.Settings; import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd; @@ -179,5 +186,28 @@ public class ActionDisabledByAdminDialogHelperTest { mHelper.setAdminSupportDetails(mActivity, null, admin); assertNull(admin.component); } -} + @Test + public void testMaybeSetLearnMoreButton() { + final UserManager userManager = RuntimeEnvironment.application.getSystemService( + UserManager.class); + final ShadowUserManager userManagerShadow = Shadow.extract(userManager); + final ComponentName component = new ComponentName("some.package.name", + "some.package.name.SomeClass"); + mHelper.mEnforcedAdmin = new EnforcedAdmin(component, UserHandle.of(123)); + + // Set up for shadow call. + userManagerShadow.getSameProfileGroupIds().put(123, 0); + + // Test that the button is shown when user IDs are in the same profile group + AlertDialog.Builder builder = mock(AlertDialog.Builder.class); + mHelper.maybeSetLearnMoreButton(builder); + verify(builder).setNeutralButton(anyInt(), any()); + + // Test that the button is not shown when user IDs are not in the same profile group + userManagerShadow.getSameProfileGroupIds().clear(); + builder = mock(AlertDialog.Builder.class); + mHelper.maybeSetLearnMoreButton(builder); + verify(builder, never()).setNeutralButton(anyInt(), any()); + } +} diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsControllerTest.java index 6012dbb4dc8..8654a4e5a7b 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsControllerTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsControllerTest.java @@ -7,6 +7,7 @@ import android.content.Context; import android.os.PowerManager; import android.provider.Settings; import android.provider.Settings.Global; +import android.provider.Settings.Secure; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -54,4 +55,13 @@ public class BatterySaverScheduleRadioButtonsControllerTest { assertThat(mController.getDefaultKey()) .isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE); } + + @Test + public void setDefaultKey_any_defaultsToNoScheduleIfWarningNotSeen() { + Secure.putString( + mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, "null"); + mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE); + assertThat(mController.getDefaultKey()) + .isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE); + } } diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java index a744e68a64c..12513f67e1a 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java @@ -16,6 +16,7 @@ package com.android.settings.homepage.contextualcards.slices; +import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.slice.Slice.HINT_LIST_ITEM; import static android.app.slice.SliceItem.FORMAT_SLICE; @@ -116,7 +117,8 @@ public class NotificationChannelSliceTest { public void getSlice_hasSuggestedApp_shouldHaveNotificationChannelTitle() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */); + mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -130,7 +132,8 @@ public class NotificationChannelSliceTest { public void getSlice_hasSuggestedApp_shouldSortByNotificationSentCount() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */); + mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -157,7 +160,8 @@ public class NotificationChannelSliceTest { public void getSlice_noRecentlyInstalledApp_shouldHaveNoSuggestedAppTitle() { addMockPackageToPackageManager(false /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */); + mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -169,7 +173,8 @@ public class NotificationChannelSliceTest { public void getSlice_noMultiChannelApp_shouldHaveNoSuggestedAppTitle() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(1 /* channelCount */, NOTIFICATION_COUNT, false /* banned */); + mockNotificationBackend(1 /* channelCount */, NOTIFICATION_COUNT, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -178,10 +183,12 @@ public class NotificationChannelSliceTest { } @Test + @Config(shadows = ShadowRestrictedLockUtilsInternal.class) public void getSlice_insufficientNotificationSentCount_shouldHaveNoSuggestedAppTitle() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(CHANNEL_COUNT, 1 /* notificationCount */, false /* banned */); + mockNotificationBackend(CHANNEL_COUNT, 1 /* notificationCount */, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -192,7 +199,8 @@ public class NotificationChannelSliceTest { @Test public void getSlice_isSystemApp_shouldHaveNoSuggestedAppTitle() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_SYSTEM); - mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */); + mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -204,7 +212,8 @@ public class NotificationChannelSliceTest { public void getSlice_isNotificationBanned_shouldHaveNoSuggestedAppTitle() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, true /* banned */); + mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, true /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -218,7 +227,7 @@ public class NotificationChannelSliceTest { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); mockNotificationBackend(NotificationChannelSlice.DEFAULT_EXPANDED_ROW_COUNT * 2, - NOTIFICATION_COUNT, false /* banned */); + NOTIFICATION_COUNT, false /* banned */, false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -234,7 +243,8 @@ public class NotificationChannelSliceTest { public void getSlice_channelCountIsLessThanDefaultRows_subTitleShouldNotHaveTapToManagerAll() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(CHANNEL_COUNT - 1, NOTIFICATION_COUNT, false /* banned */); + mockNotificationBackend(CHANNEL_COUNT - 1, NOTIFICATION_COUNT, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -249,7 +259,8 @@ public class NotificationChannelSliceTest { public void getSlice_channelCountIsEqualToDefaultRows_subTitleShouldNotHaveTapToManagerAll() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */); + mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -263,7 +274,8 @@ public class NotificationChannelSliceTest { public void getSlice_channelCountIsMoreThanDefaultRows_subTitleShouldHaveTapToManagerAll() { addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_INSTALLED); - mockNotificationBackend(CHANNEL_COUNT + 1, NOTIFICATION_COUNT, false /* banned */); + mockNotificationBackend(CHANNEL_COUNT + 1, NOTIFICATION_COUNT, false /* banned */, + false /* isChannelBlocked */); final Slice slice = mNotificationChannelSlice.getSlice(); @@ -273,6 +285,20 @@ public class NotificationChannelSliceTest { CHANNEL_COUNT + 1)); } + @Test + @Config(shadows = ShadowRestrictedLockUtilsInternal.class) + public void getSlice_isAllDisplayableChannelBlocked_shouldHaveNoSuggestedAppTitle() { + addMockPackageToPackageManager(true /* isRecentlyInstalled */, + ApplicationInfo.FLAG_INSTALLED); + mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */, + true /* isChannelBlocked */); + + final Slice slice = mNotificationChannelSlice.getSlice(); + + final SliceMetadata metadata = SliceMetadata.from(mContext, slice); + assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.no_suggested_app)); + } + private void addMockPackageToPackageManager(boolean isRecentlyInstalled, int flags) { final ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.name = APP_LABEL; @@ -294,8 +320,10 @@ public class NotificationChannelSliceTest { return System.currentTimeMillis(); } - private void mockNotificationBackend(int channelCount, int notificationCount, boolean banned) { - final List channels = buildNotificationChannel(channelCount); + private void mockNotificationBackend(int channelCount, int notificationCount, boolean banned, + boolean isChannelBlocked) { + final List channels = buildNotificationChannel(channelCount, + isChannelBlocked); final AppRow appRow = buildAppRow(channelCount, notificationCount, banned); doReturn(buildNotificationChannelGroups(channels)).when(mNotificationBackend).getGroups( @@ -308,6 +336,8 @@ public class NotificationChannelSliceTest { private AppRow buildAppRow(int channelCount, int sentCount, boolean banned) { final AppRow appRow = new AppRow(); + appRow.pkg = PACKAGE_NAME; + appRow.uid = UID; appRow.banned = banned; appRow.channelCount = channelCount; appRow.sentByApp = new NotificationsSentState(); @@ -317,11 +347,12 @@ public class NotificationChannelSliceTest { return appRow; } - private List buildNotificationChannel(int channelCount) { + private List buildNotificationChannel(int channelCount, + boolean isChannelBlock) { final List channels = new ArrayList<>(); for (int i = 0; i < channelCount; i++) { channels.add(new NotificationChannel(CHANNEL_NAME_PREFIX + i, CHANNEL_NAME_PREFIX + i, - IMPORTANCE_NONE)); + isChannelBlock ? IMPORTANCE_NONE : IMPORTANCE_LOW)); } return channels; @@ -369,4 +400,4 @@ public class NotificationChannelSliceTest { // Index 0: title; Index 1: summary. return rowSliceItems.get(1).getText(); } -} \ No newline at end of file +} diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java index e08d845196e..706f2386372 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java @@ -16,13 +16,11 @@ package com.android.settings.homepage.contextualcards.slices; -import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP; import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH; 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 android.app.Activity; @@ -118,34 +116,25 @@ public class SliceContextualCardRendererTest { } @Test - public void longClick_shouldFlipCard() { + public void bindView_isPendingDismiss_shouldFlipToDismissalView() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - final View card = viewHolder.itemView.findViewById(R.id.slice_view); final ViewFlipper viewFlipper = viewHolder.itemView.findViewById(R.id.view_flipper); final View dismissalView = viewHolder.itemView.findViewById(R.id.dismissal_view); - mRenderer.bindView(viewHolder, buildContextualCard(TEST_SLICE_URI)); + final ContextualCard card = buildContextualCard( + TEST_SLICE_URI).mutate().setIsPendingDismiss(true).build(); - card.performLongClick(); + mRenderer.bindView(viewHolder, card); assertThat(viewFlipper.getCurrentView()).isEqualTo(dismissalView); } @Test - public void longClick_deferredSetupCard_shouldNotBeClickable() { - final RecyclerView.ViewHolder viewHolder = getDeferredSetupViewHolder(); - final View contentView = viewHolder.itemView.findViewById(R.id.content); - mRenderer.bindView(viewHolder, buildContextualCard(TEST_SLICE_URI)); - - assertThat(contentView.isLongClickable()).isFalse(); - } - - @Test - public void longClick_shouldAddViewHolderToSet() { + public void bindView_isPendingDismiss_shouldAddViewHolderToSet() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - final View card = viewHolder.itemView.findViewById(R.id.slice_view); - mRenderer.bindView(viewHolder, buildContextualCard(TEST_SLICE_URI)); + final ContextualCard card = buildContextualCard( + TEST_SLICE_URI).mutate().setIsPendingDismiss(true).build(); - card.performLongClick(); + mRenderer.bindView(viewHolder, card); assertThat(mRenderer.mFlippedCardSet).contains(viewHolder); } @@ -153,12 +142,11 @@ public class SliceContextualCardRendererTest { @Test public void viewClick_keepCard_shouldFlipBackToSlice() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - final View card = viewHolder.itemView.findViewById(R.id.slice_view); final Button btnKeep = viewHolder.itemView.findViewById(R.id.keep); final ViewFlipper viewFlipper = viewHolder.itemView.findViewById(R.id.view_flipper); mRenderer.bindView(viewHolder, buildContextualCard(TEST_SLICE_URI)); + viewFlipper.setDisplayedChild(1); - card.performLongClick(); btnKeep.performClick(); assertThat(viewFlipper.getCurrentView()).isInstanceOf(SliceView.class); @@ -167,11 +155,10 @@ public class SliceContextualCardRendererTest { @Test public void viewClick_keepCard_shouldRemoveViewHolderFromSet() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - final View card = viewHolder.itemView.findViewById(R.id.slice_view); final Button btnKeep = viewHolder.itemView.findViewById(R.id.keep); mRenderer.bindView(viewHolder, buildContextualCard(TEST_SLICE_URI)); + mRenderer.mFlippedCardSet.add(viewHolder); - card.performLongClick(); btnKeep.performClick(); assertThat(mRenderer.mFlippedCardSet).doesNotContain(viewHolder); @@ -180,14 +167,13 @@ public class SliceContextualCardRendererTest { @Test public void viewClick_removeCard_shouldRemoveViewHolderFromSet() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - final View card = viewHolder.itemView.findViewById(R.id.slice_view); final Button btnRemove = viewHolder.itemView.findViewById(R.id.remove); final ContextualCard contextualCard = buildContextualCard(TEST_SLICE_URI); mRenderer.bindView(viewHolder, contextualCard); doReturn(mController).when(mControllerRendererPool).getController(mActivity, ContextualCard.CardType.SLICE); + mRenderer.mFlippedCardSet.add(viewHolder); - card.performLongClick(); btnRemove.performClick(); assertThat(mRenderer.mFlippedCardSet).doesNotContain(viewHolder); @@ -196,7 +182,6 @@ public class SliceContextualCardRendererTest { @Test public void viewClick_removeCard_sliceLiveDataShouldRemoveObservers() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - final View card = viewHolder.itemView.findViewById(R.id.slice_view); final Button btnRemove = viewHolder.itemView.findViewById(R.id.remove); final ContextualCard contextualCard = buildContextualCard(TEST_SLICE_URI); mRenderer.mSliceLiveDataMap.put(TEST_SLICE_URI, mSliceLiveData); @@ -204,7 +189,6 @@ public class SliceContextualCardRendererTest { doReturn(mController).when(mControllerRendererPool).getController(mActivity, ContextualCard.CardType.SLICE); - card.performLongClick(); btnRemove.performClick(); assertThat(mRenderer.mSliceLiveDataMap.get(TEST_SLICE_URI).hasObservers()).isFalse(); @@ -213,11 +197,11 @@ public class SliceContextualCardRendererTest { @Test public void onStop_cardIsFlipped_shouldFlipBack() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - final View card = viewHolder.itemView.findViewById(R.id.slice_view); final ViewFlipper viewFlipper = viewHolder.itemView.findViewById(R.id.view_flipper); mRenderer.bindView(viewHolder, buildContextualCard(TEST_SLICE_URI)); + viewFlipper.setDisplayedChild(1); + mRenderer.mFlippedCardSet.add(viewHolder); - card.performLongClick(); mRenderer.onStop(); assertThat(viewFlipper.getCurrentView()).isInstanceOf(SliceView.class); @@ -232,18 +216,6 @@ public class SliceContextualCardRendererTest { return mRenderer.createViewHolder(view, VIEW_TYPE_FULL_WIDTH); } - private RecyclerView.ViewHolder getDeferredSetupViewHolder() { - final RecyclerView recyclerView = new RecyclerView(mActivity); - recyclerView.setLayoutManager(new LinearLayoutManager(mActivity)); - final View view = LayoutInflater.from(mActivity).inflate(VIEW_TYPE_DEFERRED_SETUP, - recyclerView, false); - final RecyclerView.ViewHolder viewHolder = spy( - mRenderer.createViewHolder(view, VIEW_TYPE_DEFERRED_SETUP)); - doReturn(VIEW_TYPE_DEFERRED_SETUP).when(viewHolder).getItemViewType(); - - return viewHolder; - } - private ContextualCard buildContextualCard(Uri sliceUri) { return new ContextualCard.Builder() .setName("test_name") diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceFullCardRendererHelperTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceFullCardRendererHelperTest.java index 88820096fce..395748bc0fb 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceFullCardRendererHelperTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceFullCardRendererHelperTest.java @@ -78,7 +78,7 @@ public class SliceFullCardRendererHelperTest { public void bindView_shouldSetScrollableToFalse() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - mHelper.bindView(viewHolder, buildContextualCard(), buildSlice(), Collections.emptySet()); + mHelper.bindView(viewHolder, buildContextualCard(), buildSlice()); assertThat(((SliceViewHolder) viewHolder).sliceView.isScrollable()).isFalse(); } @@ -88,7 +88,7 @@ public class SliceFullCardRendererHelperTest { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); final ContextualCard card = buildContextualCard(); - mHelper.bindView(viewHolder, card, buildSlice(), Collections.emptySet()); + mHelper.bindView(viewHolder, card, buildSlice()); assertThat(((SliceViewHolder) viewHolder).sliceView.getTag()).isEqualTo(card.getSliceUri()); } @@ -97,7 +97,7 @@ public class SliceFullCardRendererHelperTest { public void bindView_shouldSetModeToLarge() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - mHelper.bindView(viewHolder, buildContextualCard(), buildSlice(), Collections.emptySet()); + mHelper.bindView(viewHolder, buildContextualCard(), buildSlice()); assertThat(((SliceViewHolder) viewHolder).sliceView.getMode()).isEqualTo( SliceView.MODE_LARGE); @@ -107,7 +107,7 @@ public class SliceFullCardRendererHelperTest { public void bindView_shouldSetSlice() { final RecyclerView.ViewHolder viewHolder = getSliceViewHolder(); - mHelper.bindView(viewHolder, buildContextualCard(), buildSlice(), Collections.emptySet()); + mHelper.bindView(viewHolder, buildContextualCard(), buildSlice()); assertThat(((SliceViewHolder) viewHolder).sliceView.getSlice().getUri()).isEqualTo( TEST_SLICE_URI); diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SwipeDismissalDelegateTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SwipeDismissalDelegateTest.java new file mode 100644 index 00000000000..00b7815745b --- /dev/null +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SwipeDismissalDelegateTest.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2019 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.homepage.contextualcards.slices; + +import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +import android.app.Activity; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ViewFlipper; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.android.settings.R; +import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardRenderer; +import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardRenderer.ConditionalCardHolder; +import com.android.settings.homepage.contextualcards.slices.SliceDeferredSetupCardRendererHelper.DeferredSetupCardViewHolder; +import com.android.settings.homepage.contextualcards.slices.SliceFullCardRendererHelper.SliceViewHolder; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.android.controller.ActivityController; + +@RunWith(RobolectricTestRunner.class) +public class SwipeDismissalDelegateTest { + + @Mock + private SwipeDismissalDelegate.Listener mDismissalDelegateListener; + + private Activity mActivity; + private RecyclerView mRecyclerView; + private SwipeDismissalDelegate mDismissalDelegate; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + final ActivityController activityController = Robolectric.buildActivity( + Activity.class); + mActivity = activityController.get(); + mActivity.setTheme(R.style.Theme_Settings_Home); + activityController.create(); + mRecyclerView = new RecyclerView(mActivity); + mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity)); + mDismissalDelegate = new SwipeDismissalDelegate(mActivity, mDismissalDelegateListener); + } + + @Test + public void getMovementFlags_conditionalViewHolder_shouldDisableSwipe() { + assertThat(mDismissalDelegate.getMovementFlags(mRecyclerView, getConditionalViewHolder())) + .isEqualTo(0); + } + + @Test + public void getMovementFlags_deferredSetupViewHolder_shouldDisableSwipe() { + assertThat(mDismissalDelegate.getMovementFlags(mRecyclerView, getDeferredSetupViewHolder())) + .isEqualTo(0); + } + + @Test + public void getMovementFlags_dismissalView_shouldDisableSwipe() { + final RecyclerView.ViewHolder holder = getSliceViewHolder(); + final ViewFlipper viewFlipper = holder.itemView.findViewById(R.id.view_flipper); + viewFlipper.showNext(); + final View dismissalView = holder.itemView.findViewById(R.id.dismissal_view); + + assertThat(viewFlipper.getCurrentView()).isEqualTo(dismissalView); + assertThat(mDismissalDelegate.getMovementFlags(mRecyclerView, holder)).isEqualTo(0); + } + + @Test + public void getMovementFlags_SliceViewHolder_shouldEnableSwipe() { + final RecyclerView.ViewHolder holder = getSliceViewHolder(); + final ViewFlipper viewFlipper = holder.itemView.findViewById(R.id.view_flipper); + viewFlipper.setDisplayedChild(0); + final View sliceView = holder.itemView.findViewById(R.id.slice_view); + + assertThat(viewFlipper.getCurrentView()).isEqualTo(sliceView); + assertThat(mDismissalDelegate.getMovementFlags(mRecyclerView, getSliceViewHolder())) + .isNotEqualTo(0); + } + + @Test + public void onSwipe_shouldNotifyListener() { + mDismissalDelegate.onSwiped(getSliceViewHolder(), 1); + + verify(mDismissalDelegateListener).onSwiped(anyInt()); + } + + private RecyclerView.ViewHolder getSliceViewHolder() { + final View view = LayoutInflater.from(mActivity) + .inflate(SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH, mRecyclerView, false); + final RecyclerView.ViewHolder viewHolder = spy(new SliceViewHolder(view)); + doReturn(SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH).when( + viewHolder).getItemViewType(); + + return viewHolder; + } + + private RecyclerView.ViewHolder getConditionalViewHolder() { + final View view = LayoutInflater.from(mActivity) + .inflate(ConditionContextualCardRenderer.VIEW_TYPE_FULL_WIDTH, mRecyclerView, + false); + final RecyclerView.ViewHolder viewHolder = spy(new ConditionalCardHolder(view)); + doReturn(ConditionContextualCardRenderer.VIEW_TYPE_FULL_WIDTH).when( + viewHolder).getItemViewType(); + + return viewHolder; + } + + private RecyclerView.ViewHolder getDeferredSetupViewHolder() { + final View view = LayoutInflater.from(mActivity) + .inflate(VIEW_TYPE_DEFERRED_SETUP, mRecyclerView, false); + final RecyclerView.ViewHolder viewHolder = spy(new DeferredSetupCardViewHolder(view)); + doReturn(VIEW_TYPE_DEFERRED_SETUP).when(viewHolder).getItemViewType(); + + return viewHolder; + } +} diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java index c5519601ae7..b39f77ed732 100644 --- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java +++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java @@ -17,35 +17,29 @@ package com.android.settings.media; -import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI; - import static com.google.common.truth.Truth.assertThat; -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.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothManager; import android.content.Context; -import android.content.Intent; import androidx.slice.Slice; -import androidx.slice.SliceItem; import androidx.slice.SliceMetadata; import androidx.slice.SliceProvider; -import androidx.slice.core.SliceAction; import androidx.slice.widget.SliceLiveData; import com.android.settings.R; -import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; -import com.android.settingslib.media.LocalMediaManager; -import com.android.settingslib.media.MediaDevice; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settings.testutils.shadow.ShadowBluetoothUtils; +import com.android.settingslib.bluetooth.A2dpProfile; +import com.android.settingslib.bluetooth.HearingAidProfile; +import com.android.settingslib.bluetooth.LocalBluetoothManager; +import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -53,59 +47,108 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; -import org.robolectric.shadow.api.Shadow; import java.util.ArrayList; import java.util.List; @RunWith(RobolectricTestRunner.class) -@Config(shadows = {ShadowBluetoothAdapter.class}) -@Ignore("b/129292771") +@Config(shadows = {ShadowBluetoothUtils.class}) public class MediaOutputIndicatorSliceTest { - private static final String TEST_DEVICE_NAME = "test_device_name"; - private static final int TEST_DEVICE_1_ICON = - com.android.internal.R.drawable.ic_bt_headphones_a2dp; + private static final String TEST_A2DP_DEVICE_NAME = "Test_A2DP_BT_Device_NAME"; + private static final String TEST_HAP_DEVICE_NAME = "Test_HAP_BT_Device_NAME"; + private static final String TEST_A2DP_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1"; + private static final String TEST_HAP_DEVICE_ADDRESS = "00:B2:B2:B2:B2:B2"; @Mock - private LocalMediaManager mLocalMediaManager; - - private final List mDevices = new ArrayList<>(); + private A2dpProfile mA2dpProfile; + @Mock + private HearingAidProfile mHearingAidProfile; + @Mock + private LocalBluetoothManager mLocalBluetoothManager; + @Mock + private LocalBluetoothProfileManager mLocalBluetoothProfileManager; + private BluetoothAdapter mBluetoothAdapter; + private BluetoothDevice mA2dpDevice; + private BluetoothDevice mHapDevice; + private BluetoothManager mBluetoothManager; private Context mContext; + private List mDevicesList; private MediaOutputIndicatorSlice mMediaOutputIndicatorSlice; - private MediaOutputIndicatorWorker mMediaOutputIndicatorWorker; - private ShadowBluetoothAdapter mShadowBluetoothAdapter; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); - // Set-up specs for SliceMetadata. SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS); + // Setup Bluetooth environment + ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager; + mBluetoothManager = new BluetoothManager(mContext); + mBluetoothAdapter = mBluetoothManager.getAdapter(); + when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager); + when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); + when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile); + + // Setup A2dp device + mA2dpDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_A2DP_DEVICE_ADDRESS)); + when(mA2dpDevice.getName()).thenReturn(TEST_A2DP_DEVICE_NAME); + when(mA2dpDevice.isConnected()).thenReturn(true); + // Setup HearingAid device + mHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_HAP_DEVICE_ADDRESS)); + when(mHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME); + when(mHapDevice.isConnected()).thenReturn(true); + mMediaOutputIndicatorSlice = new MediaOutputIndicatorSlice(mContext); - mMediaOutputIndicatorWorker = spy(new MediaOutputIndicatorWorker( - mContext, MEDIA_OUTPUT_INDICATOR_SLICE_URI)); - mMediaOutputIndicatorSlice.mWorker = mMediaOutputIndicatorWorker; + mDevicesList = new ArrayList<>(); } @Test - public void getSlice_invisible_returnNull() { - when(mMediaOutputIndicatorWorker.isVisible()).thenReturn(false); + public void getSlice_noConnectableDevice_returnNull() { + mDevicesList.clear(); + when(mA2dpProfile.getConnectableDevices()).thenReturn(mDevicesList); assertThat(mMediaOutputIndicatorSlice.getSlice()).isNull(); } @Test - public void getSlice_withActiveDevice_checkContent() { - when(mMediaOutputIndicatorWorker.isVisible()).thenReturn(true); - when(mMediaOutputIndicatorWorker.findActiveDeviceName()).thenReturn(TEST_DEVICE_NAME); + public void getSlice_noActiveDevice_verifyDefaultName() { + mDevicesList.add(mA2dpDevice); + when(mA2dpProfile.getConnectableDevices()).thenReturn(mDevicesList); + when(mA2dpProfile.getActiveDevice()).thenReturn(null); + + // Verify slice title and subtitle final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice(); final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice); - // Verify slice title and subtitle assertThat(metadata.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title)); - assertThat(metadata.getSubtitle()).isEqualTo(TEST_DEVICE_NAME); + assertThat(metadata.getSubtitle()).isEqualTo(mContext.getText( + R.string.media_output_default_summary)); + } + + @Test + public void getSlice_A2dpDeviceActive_verifyName() { + mDevicesList.add(mA2dpDevice); + when(mA2dpProfile.getConnectableDevices()).thenReturn(mDevicesList); + when(mA2dpProfile.getActiveDevice()).thenReturn(mA2dpDevice); + + final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice(); + final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice); + assertThat(metadata.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title)); + assertThat(metadata.getSubtitle()).isEqualTo(TEST_A2DP_DEVICE_NAME); + } + + @Test + public void getSlice_HADeviceActive_verifyName() { + mDevicesList.add(mHapDevice); + when(mHearingAidProfile.getConnectableDevices()).thenReturn(mDevicesList); + when(mHearingAidProfile.getActiveDevices()).thenReturn(mDevicesList); + + // Verify slice title and subtitle + final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice(); + final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice); + assertThat(metadata.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title)); + assertThat(metadata.getSubtitle()).isEqualTo(TEST_HAP_DEVICE_NAME); } } diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java index ed93258346b..3671d819f83 100644 --- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java +++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorWorkerTest.java @@ -16,28 +16,18 @@ package com.android.settings.media; -import static com.google.common.truth.Truth.assertThat; - import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothManager; import android.content.Context; import android.net.Uri; -import com.android.settings.R; -import com.android.settings.bluetooth.Utils; import com.android.settings.testutils.shadow.ShadowBluetoothUtils; -import com.android.settingslib.bluetooth.A2dpProfile; import com.android.settingslib.bluetooth.BluetoothEventManager; -import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; -import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -45,119 +35,38 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; -import org.robolectric.shadows.ShadowBluetoothDevice; - -import java.util.ArrayList; -import java.util.List; @RunWith(RobolectricTestRunner.class) -@Config(shadows = {ShadowBluetoothUtils.class, - ShadowBluetoothDevice.class}) -@Ignore("b/129292771") +@Config(shadows = {ShadowBluetoothUtils.class}) public class MediaOutputIndicatorWorkerTest { - - private static final String TEST_A2DP_DEVICE_NAME = "Test_A2DP_BT_Device_NAME"; - private static final String TEST_HAP_DEVICE_NAME = "Test_HAP_BT_Device_NAME"; - private static final String TEST_A2DP_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1"; - private static final String TEST_HAP_DEVICE_ADDRESS = "00:B2:B2:B2:B2:B2"; private static final Uri URI = Uri.parse("content://com.android.settings.slices/test"); - @Mock - private A2dpProfile mA2dpProfile; - @Mock - private HearingAidProfile mHearingAidProfile; - @Mock - private LocalBluetoothManager mLocalManager; @Mock private BluetoothEventManager mBluetoothEventManager; @Mock - private LocalBluetoothProfileManager mLocalBluetoothProfileManager; - - private BluetoothAdapter mBluetoothAdapter; - private BluetoothDevice mA2dpDevice; - private BluetoothDevice mHapDevice; - private BluetoothManager mBluetoothManager; - private Context mContext; - private List mDevicesList; private LocalBluetoothManager mLocalBluetoothManager; + private Context mContext; private MediaOutputIndicatorWorker mMediaDeviceUpdateWorker; @Before public void setUp() { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); - ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager; - mLocalBluetoothManager = Utils.getLocalBtManager(mContext); + ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager; when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager); - when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager); - when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); - when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile); - mBluetoothManager = new BluetoothManager(mContext); - mBluetoothAdapter = mBluetoothManager.getAdapter(); - - // Setup A2dp device - mA2dpDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_A2DP_DEVICE_ADDRESS)); - when(mA2dpDevice.getName()).thenReturn(TEST_A2DP_DEVICE_NAME); - when(mA2dpDevice.isConnected()).thenReturn(true); - // Setup HearingAid device - mHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_HAP_DEVICE_ADDRESS)); - when(mHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME); - when(mHapDevice.isConnected()).thenReturn(true); - mMediaDeviceUpdateWorker = new MediaOutputIndicatorWorker(mContext, URI); - mDevicesList = new ArrayList<>(); } @Test - public void isVisible_noConnectableDevice_returnFalse() { - mDevicesList.clear(); - when(mA2dpProfile.getConnectableDevices()).thenReturn(mDevicesList); - - assertThat(mMediaDeviceUpdateWorker.isVisible()).isFalse(); + public void onSlicePinned_registerCallback() { + mMediaDeviceUpdateWorker.onSlicePinned(); + verify(mBluetoothEventManager).registerCallback(mMediaDeviceUpdateWorker); } @Test - public void isVisible_withConnectableA2dpDevice_returnTrue() { - mDevicesList.clear(); - mDevicesList.add(mA2dpDevice); - when(mHearingAidProfile.getConnectableDevices()).thenReturn(mDevicesList); - - assertThat(mMediaDeviceUpdateWorker.isVisible()).isTrue(); - } - - @Test - public void isVisible_withConnectableHADevice_returnTrue() { - mDevicesList.clear(); - mDevicesList.add(mHapDevice); - when(mA2dpProfile.getConnectableDevices()).thenReturn(mDevicesList); - - assertThat(mMediaDeviceUpdateWorker.isVisible()).isTrue(); - } - - @Test - public void findActiveDeviceName_A2dpDeviceActive_verifyName() { - when(mA2dpProfile.getActiveDevice()).thenReturn(mA2dpDevice); - - assertThat(mMediaDeviceUpdateWorker.findActiveDeviceName()) - .isEqualTo(mA2dpDevice.getAliasName()); - } - - @Test - public void findActiveDeviceName_HADeviceActive_verifyName() { - mDevicesList.add(mHapDevice); - when(mHearingAidProfile.getActiveDevices()).thenReturn(mDevicesList); - - assertThat(mMediaDeviceUpdateWorker.findActiveDeviceName()) - .isEqualTo(mHapDevice.getAliasName()); - } - - @Test - public void findActiveDeviceName_noActiveDevice_verifyDefaultName() { - when(mA2dpProfile.getActiveDevice()).thenReturn(null); - mDevicesList.clear(); - when(mHearingAidProfile.getActiveDevices()).thenReturn(mDevicesList); - - assertThat(mMediaDeviceUpdateWorker.findActiveDeviceName()) - .isEqualTo(mContext.getText(R.string.media_output_default_summary)); + public void onSliceUnpinned_unRegisterCallback() { + mMediaDeviceUpdateWorker.onSlicePinned(); + mMediaDeviceUpdateWorker.onSliceUnpinned(); + verify(mBluetoothEventManager).unregisterCallback(mMediaDeviceUpdateWorker); } } diff --git a/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java index 99787d824bc..6d13798bd27 100644 --- a/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java @@ -23,6 +23,7 @@ import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -223,6 +224,7 @@ public class BubblePreferenceControllerTest { @Test public void testUpdateState_app() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.label = "App!"; appRow.allowBubbles = true; mController.onResume(appRow, null, null, null); @@ -235,6 +237,9 @@ public class BubblePreferenceControllerTest { mController.updateState(pref); assertFalse(pref.isChecked()); + + assertNotNull(pref.getSummary()); + assertTrue(pref.getSummary().toString().contains(appRow.label)); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/BubbleSummaryNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BubbleSummaryNotificationPreferenceControllerTest.java new file mode 100644 index 00000000000..4bdb2cca72a --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/BubbleSummaryNotificationPreferenceControllerTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2019 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.notification; + +import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; + +import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF; +import static com.android.settings.notification.BadgingNotificationPreferenceController.ON; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.provider.Settings; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + +import androidx.preference.Preference; + +@RunWith(RobolectricTestRunner.class) +public class BubbleSummaryNotificationPreferenceControllerTest { + + private Context mContext; + + private BubbleSummaryNotificationPreferenceController mController; + private Preference mPreference; + + private static final String KEY_NOTIFICATION_BUBBLES = "notification_bubbles"; + + @Before + public void setUp() { + mContext = RuntimeEnvironment.application; + mController = new BubbleSummaryNotificationPreferenceController(mContext, + KEY_NOTIFICATION_BUBBLES); + mPreference = new Preference(RuntimeEnvironment.application); + } + + @Test + public void display_shouldDisplay() { + assertThat(mPreference.isVisible()).isTrue(); + } + + @Test + public void getSummary() { + Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF); + + assertThat(mController.getSummary()).isEqualTo("Off"); + + Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON); + + assertThat(mController.getSummary()).isEqualTo("On"); + } +} diff --git a/tests/robotests/src/com/android/settings/notification/BubbleSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BubbleSummaryPreferenceControllerTest.java new file mode 100644 index 00000000000..5158e82e3b4 --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/BubbleSummaryPreferenceControllerTest.java @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2019 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.notification; + +import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID; +import static android.app.NotificationManager.IMPORTANCE_HIGH; +import static android.app.NotificationManager.IMPORTANCE_LOW; +import static android.app.NotificationManager.IMPORTANCE_NONE; +import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; + +import static junit.framework.TestCase.assertEquals; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +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.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.os.UserManager; +import android.provider.Settings; + +import com.android.settingslib.RestrictedLockUtils; +import com.android.settingslib.RestrictedSwitchPreference; + +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.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.shadows.ShadowApplication; + +import androidx.preference.Preference; +import androidx.preference.PreferenceScreen; + +@RunWith(RobolectricTestRunner.class) +public class BubbleSummaryPreferenceControllerTest { + + private Context mContext; + @Mock + private NotificationBackend mBackend; + + private BubbleSummaryPreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + ShadowApplication shadowApplication = ShadowApplication.getInstance(); + mContext = RuntimeEnvironment.application; + mController = spy(new BubbleSummaryPreferenceController(mContext, mBackend)); + } + + @Test + public void testNoCrashIfNoOnResume() { + mController.isAvailable(); + mController.updateState(mock(Preference.class)); + } + + @Test + public void testIsAvailable_notIfAppBlocked() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.banned = true; + mController.onResume(appRow, mock(NotificationChannel.class), null, null); + assertFalse(mController.isAvailable()); + } + + @Test + public void testIsAvailable_notIfOffGlobally() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); + mController.onResume(appRow, channel, null, null); + Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 0); + + assertFalse(mController.isAvailable()); + } + + @Test + public void testIsAvailable_app() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + mController.onResume(appRow, null, null, null); + Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1); + + assertTrue(mController.isAvailable()); + } + + @Test + public void testIsAvailable_defaultChannel() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.allowBubbles = true; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); + when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID); + mController.onResume(appRow, channel, null, null); + Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1); + + assertTrue(mController.isAvailable()); + } + + @Test + public void testUpdateState() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.allowBubbles = true; + mController.onResume(appRow, null, null, null); + + Preference pref = new Preference(mContext); + mController.updateState(pref); + assertNotNull(pref.getIntent()); + } + + @Test + public void testGetSummary() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.allowBubbles = true; + mController.onResume(appRow, null, null, null); + + assertEquals("On", mController.getSummary()); + + appRow.allowBubbles = false; + mController.onResume(appRow, null, null, null); + + assertEquals("Off", mController.getSummary()); + } +} diff --git a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java index 2368af5f94b..9c53a7bfec0 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java @@ -317,6 +317,30 @@ public class NotificationPreferenceControllerTest { assertTrue(mController.isChannelGroupBlockable()); } + @Test + public void testIsChannelBlockable_oemLocked() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.systemApp = false; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.isImportanceLockedByOEM()).thenReturn(true); + when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT); + + mController.onResume(appRow, channel, null, null); + assertFalse(mController.isChannelBlockable()); + } + + @Test + public void testIsChannelBlockable_criticalDeviceFunction() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.systemApp = false; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); + when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT); + + mController.onResume(appRow, channel, null, null); + assertFalse(mController.isChannelBlockable()); + } + @Test public void testIsChannelGroupBlockable_SystemNotBlockable() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); diff --git a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java index 1b4ede5b14f..866f8668a21 100644 --- a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java @@ -39,6 +39,8 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; +import android.media.AudioAttributes; +import android.media.RingtoneManager; import android.net.Uri; import android.os.UserManager; import android.provider.Settings; @@ -54,6 +56,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; +import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.Robolectric; @@ -230,6 +233,69 @@ public class SoundPreferenceControllerTest { verify(mFragment, times(1)).startActivityForResult(any(), anyInt()); } + @Test + public void testOnPreferenceTreeClick_alarmSound() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); + channel.setSound(null, new AudioAttributes.Builder().setUsage( + AudioAttributes.USAGE_ALARM).build()); + mController.onResume(appRow, channel, null, null); + + AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); + NotificationSoundPreference pref = + spy(new NotificationSoundPreference(mContext, attributeSet)); + pref.setKey(mController.getPreferenceKey()); + mController.handlePreferenceTreeClick(pref); + + ArgumentCaptor intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); + verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); + assertEquals(RingtoneManager.TYPE_ALARM, + intentArgumentCaptor.getValue().getIntExtra( + RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); + } + + @Test + public void testOnPreferenceTreeClick_ringtoneSound() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); + channel.setSound(null, new AudioAttributes.Builder().setUsage( + AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build()); + mController.onResume(appRow, channel, null, null); + + AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); + NotificationSoundPreference pref = + spy(new NotificationSoundPreference(mContext, attributeSet)); + pref.setKey(mController.getPreferenceKey()); + mController.handlePreferenceTreeClick(pref); + + ArgumentCaptor intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); + verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); + assertEquals(RingtoneManager.TYPE_RINGTONE, + intentArgumentCaptor.getValue().getIntExtra( + RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); + } + + @Test + public void testOnPreferenceTreeClick_otherSound() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); + channel.setSound(null, new AudioAttributes.Builder().setUsage( + AudioAttributes.USAGE_UNKNOWN).build()); + mController.onResume(appRow, channel, null, null); + + AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); + NotificationSoundPreference pref = + spy(new NotificationSoundPreference(mContext, attributeSet)); + pref.setKey(mController.getPreferenceKey()); + mController.handlePreferenceTreeClick(pref); + + ArgumentCaptor intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); + verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); + assertEquals(RingtoneManager.TYPE_NOTIFICATION, + intentArgumentCaptor.getValue().getIntExtra( + RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); + } + @Test public void testOnActivityResult() { NotificationSoundPreference pref = mock(NotificationSoundPreference.class); diff --git a/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java index 332156e8b9a..988816897a7 100644 --- a/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java @@ -16,6 +16,14 @@ package com.android.settings.privacy; +import static android.Manifest.permission_group.CALENDAR; +import static android.Manifest.permission_group.CAMERA; +import static android.Manifest.permission_group.CONTACTS; +import static android.Manifest.permission_group.LOCATION; +import static android.Manifest.permission_group.MICROPHONE; +import static android.Manifest.permission_group.PHONE; +import static android.Manifest.permission_group.SMS; + import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE; import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; @@ -221,4 +229,27 @@ public class PermissionBarChartPreferenceControllerTest { verify(mFragment).setLoadingEnabled(false /* enabled */); verify(mPreference).updateLoadingState(false /* isLoading */); } + + @Test + public void onPermissionUsageResult_shouldBeSorted() { + final List infos = new ArrayList<>(); + infos.add(new RuntimePermissionUsageInfo(PHONE, 10)); + infos.add(new RuntimePermissionUsageInfo(LOCATION, 10)); + infos.add(new RuntimePermissionUsageInfo(CAMERA, 10)); + infos.add(new RuntimePermissionUsageInfo(SMS, 1)); + infos.add(new RuntimePermissionUsageInfo(MICROPHONE, 10)); + infos.add(new RuntimePermissionUsageInfo(CONTACTS, 42)); + infos.add(new RuntimePermissionUsageInfo(CALENDAR, 10)); + mController.displayPreference(mScreen); + + mController.onPermissionUsageResult(infos); + + assertThat(infos.get(0).getName()).isEqualTo(CONTACTS); + assertThat(infos.get(1).getName()).isEqualTo(LOCATION); + assertThat(infos.get(2).getName()).isEqualTo(MICROPHONE); + assertThat(infos.get(3).getName()).isEqualTo(CAMERA); + assertThat(infos.get(4).getName()).isEqualTo(CALENDAR); + assertThat(infos.get(5).getName()).isEqualTo(PHONE); + assertThat(infos.get(6).getName()).isEqualTo(SMS); + } } diff --git a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java index 75cd552ab01..7bdc368364b 100644 --- a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java @@ -18,8 +18,17 @@ package com.android.settings.system; import static com.google.common.truth.Truth.assertThat; -import android.content.Context; +import static org.mockito.ArgumentMatchers.any; +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.os.Bundle; + +import com.android.settings.aware.AwareFeatureProvider; +import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.ShadowUserManager; @@ -38,11 +47,17 @@ import java.util.List; @Config(shadows = {SettingsShadowResources.class, ShadowUserManager.class}) public class SystemDashboardFragmentTest { + private Context mContext; + private SystemDashboardFragment mFragment; + @Before public void setup() { SettingsShadowResources.overrideResource( com.android.internal.R.bool.config_supportSystemNavigationKeys, true); ShadowUserManager.getShadow().setIsAdminUser(true); + mContext = RuntimeEnvironment.application; + mFragment = spy(new SystemDashboardFragment()); + when(mFragment.getContext()).thenReturn(mContext); } @After @@ -52,13 +67,35 @@ public class SystemDashboardFragmentTest { @Test public void testNonIndexableKeys_existInXmlLayout() { - final Context context = RuntimeEnvironment.application; final List niks = SystemDashboardFragment.SEARCH_INDEX_DATA_PROVIDER - .getNonIndexableKeys(context); + .getNonIndexableKeys(mContext); final int xmlId = (new SystemDashboardFragment()).getPreferenceScreenResId(); - final List keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); + final List keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId); assertThat(keys).containsAllIn(niks); } + + @Test + public void showRestrictionDialog_hasValidExtra_shouldShowDialog() { + final AwareFeatureProvider mProvider = + FakeFeatureFactory.setupForTest().mAwareFeatureProvider; + final Bundle bundle = new Bundle(); + bundle.putBoolean(SystemDashboardFragment.EXTRA_SHOW_AWARE_DISABLED, true); + when(mFragment.getArguments()).thenReturn(bundle); + + mFragment.showRestrictionDialog(); + + verify(mProvider).showRestrictionDialog(any()); + } + + @Test + public void showRestrictionDialog_hasInvalidExtra_shouldNotShowDialog() { + final AwareFeatureProvider mProvider = + FakeFeatureFactory.setupForTest().mAwareFeatureProvider; + + mFragment.showRestrictionDialog(); + + verify(mProvider, never()).showRestrictionDialog(any()); + } } diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java index bceba3c9864..a85fe107b3c 100644 --- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java +++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java @@ -22,6 +22,8 @@ import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager.EnforcingUser; +import com.google.android.collect.Maps; + import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; @@ -48,6 +50,7 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager private boolean mIsQuietModeEnabled = false; private int[] profileIdsForUser = new int[0]; private boolean mUserSwitchEnabled; + private final Map mSameProfileGroupIds = Maps.newHashMap(); public void addProfile(UserInfo userInfo) { mUserProfileInfos.add(userInfo); @@ -138,6 +141,18 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager return sIsSupportsMultipleUsers; } + @Implementation + protected boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) { + return mSameProfileGroupIds.containsKey(userId) + && mSameProfileGroupIds.get(userId) == otherUserId + || mSameProfileGroupIds.containsKey(otherUserId) + && mSameProfileGroupIds.get(otherUserId) == userId; + } + + public Map getSameProfileGroupIds() { + return mSameProfileGroupIds; + } + public void setSupportsMultipleUsers(boolean supports) { sIsSupportsMultipleUsers = supports; } diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java index 0a565cd2ff8..f177b5ea87a 100644 --- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java @@ -105,6 +105,7 @@ public class WifiDetailPreferenceControllerTest { private static final int RSSI = -55; private static final int TX_LINK_SPEED = 123; private static final int RX_LINK_SPEED = 54; + private static final String SSID = "ssid"; private static final String MAC_ADDRESS = WifiInfo.DEFAULT_MAC_ADDRESS; private static final String SECURITY = "None"; @@ -154,6 +155,8 @@ public class WifiDetailPreferenceControllerTest { @Mock private Preference mockSecurityPref; @Mock + private Preference mockSsidPref; + @Mock private Preference mockMacAddressPref; @Mock private Preference mockIpAddressPref; @@ -245,6 +248,7 @@ public class WifiDetailPreferenceControllerTest { when(mockAccessPoint.getConfig()).thenReturn(mockWifiConfig); when(mockAccessPoint.getLevel()).thenReturn(LEVEL); when(mockAccessPoint.getSecurityString(false)).thenReturn(SECURITY); + when(mockAccessPoint.getSsidStr()).thenReturn(SSID); when(mockConnectivityManager.getNetworkInfo(any(Network.class))) .thenReturn(mockNetworkInfo); doNothing().when(mockConnectivityManager).registerNetworkCallback( @@ -314,6 +318,8 @@ public class WifiDetailPreferenceControllerTest { .thenReturn(mockFrequencyPref); when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_SECURITY_PREF)) .thenReturn(mockSecurityPref); + when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_SSID_PREF)) + .thenReturn(mockSsidPref); when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_MAC_ADDRESS_PREF)) .thenReturn(mockMacAddressPref); when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_IP_ADDRESS_PREF)) @@ -462,6 +468,50 @@ public class WifiDetailPreferenceControllerTest { verify(mockRxLinkSpeedPref).setVisible(false); } + @Test + public void ssidPref_shouldHaveDetailTextSet() { + when(mockAccessPoint.isPasspoint()).thenReturn(true); + when(mockAccessPoint.isOsuProvider()).thenReturn(false); + + displayAndResume(); + + verify(mockSsidPref, times(1)).setSummary(SSID); + + when(mockAccessPoint.isPasspoint()).thenReturn(false); + when(mockAccessPoint.isOsuProvider()).thenReturn(true); + + displayAndResume(); + + verify(mockSsidPref, times(2)).setSummary(SSID); + } + + @Test + public void ssidPref_shouldShowIfPasspointOrOsu() { + when(mockAccessPoint.isPasspoint()).thenReturn(true); + when(mockAccessPoint.isOsuProvider()).thenReturn(false); + + displayAndResume(); + + verify(mockSsidPref, times(1)).setVisible(true); + + when(mockAccessPoint.isPasspoint()).thenReturn(false); + when(mockAccessPoint.isOsuProvider()).thenReturn(true); + + displayAndResume(); + + verify(mockSsidPref, times(2)).setVisible(true); + } + + @Test + public void ssidPref_shouldNotShowIfNotPasspoint() { + when(mockAccessPoint.isPasspoint()).thenReturn(false); + when(mockAccessPoint.isOsuProvider()).thenReturn(false); + + displayAndResume(); + + verify(mockSsidPref).setVisible(false); + } + @Test public void macAddressPref_shouldHaveDetailTextSet() { displayAndResume(); diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiPrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiPrivacyPreferenceControllerTest.java index a1af8bf272c..2e588b54a69 100644 --- a/tests/robotests/src/com/android/settings/wifi/details/WifiPrivacyPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/details/WifiPrivacyPreferenceControllerTest.java @@ -109,4 +109,20 @@ public class WifiPrivacyPreferenceControllerTest { assertThat(mDropDownPreference.isSelectable()).isFalse(); } + + @Test + public void testUpdateState_isNotPasspointNetwork_shouldBeSelectable() { + mPreferenceController.setIsPasspoint(false); + mPreferenceController.updateState(mDropDownPreference); + + assertThat(mDropDownPreference.isSelectable()).isTrue(); + } + + @Test + public void testUpdateState_isPasspointNetwork_shouldNotSelectable() { + mPreferenceController.setIsPasspoint(true); + mPreferenceController.updateState(mDropDownPreference); + + assertThat(mDropDownPreference.isSelectable()).isFalse(); + } }