1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.notification; 18 19 import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES; 20 21 import static com.android.settings.core.BasePreferenceController.AVAILABLE; 22 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; 23 import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF; 24 import static com.android.settings.notification.BadgingNotificationPreferenceController.ON; 25 26 import static com.google.common.truth.Truth.assertThat; 27 28 import android.app.ActivityManager; 29 import android.content.Context; 30 import android.provider.Settings; 31 32 import androidx.preference.Preference; 33 34 import com.android.settings.R; 35 36 import org.junit.Before; 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 import org.robolectric.RobolectricTestRunner; 40 import org.robolectric.RuntimeEnvironment; 41 import org.robolectric.shadow.api.Shadow; 42 import org.robolectric.shadows.ShadowActivityManager; 43 44 @RunWith(RobolectricTestRunner.class) 45 public class BubbleSummaryNotificationPreferenceControllerTest { 46 47 private Context mContext; 48 49 private BubbleSummaryNotificationPreferenceController mController; 50 private Preference mPreference; 51 52 private static final String KEY_NOTIFICATION_BUBBLES = "notification_bubbles"; 53 54 @Before setUp()55 public void setUp() { 56 mContext = RuntimeEnvironment.application; 57 mController = new BubbleSummaryNotificationPreferenceController(mContext, 58 KEY_NOTIFICATION_BUBBLES); 59 mPreference = new Preference(RuntimeEnvironment.application); 60 } 61 62 @Test getSummary_NOTIFICATION_BUBBLESIsOff_returnOffString()63 public void getSummary_NOTIFICATION_BUBBLESIsOff_returnOffString() { 64 Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF); 65 66 assertThat(mController.getSummary()).isEqualTo("Off"); 67 } 68 69 @Test getSummary_NOTIFICATION_BUBBLESIsOff_returnOnString()70 public void getSummary_NOTIFICATION_BUBBLESIsOff_returnOnString() { 71 Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON); 72 73 String onString = mContext.getString(R.string.notifications_bubble_setting_on_summary); 74 assertThat(mController.getSummary()).isEqualTo(onString); 75 } 76 77 @Test isAvailable_lowRam_returnsUnsupported()78 public void isAvailable_lowRam_returnsUnsupported() { 79 final ShadowActivityManager activityManager = 80 Shadow.extract(mContext.getSystemService(ActivityManager.class)); 81 activityManager.setIsLowRamDevice(true); 82 assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); 83 } 84 85 @Test isAvailable_notLowRam_returnsAvailable()86 public void isAvailable_notLowRam_returnsAvailable() { 87 final ShadowActivityManager activityManager = 88 Shadow.extract(mContext.getSystemService(ActivityManager.class)); 89 activityManager.setIsLowRamDevice(false); 90 assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); 91 } 92 } 93