Bug: 237628564 Test: make RunSettingsRoboTests ROBOTEST_FILTER=CameraFlashNotificationPreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=ColorSelectorLayoutTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreferenceFragmentTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreviewPreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreviewPreferenceTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsUtilTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=ScreenFlashNotificationColorDialogFragmentTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=ScreenFlashNotificationColorTest Change-Id: I0987590ddfcfd0873ec419db263f6a7eade81844 Signed-off-by: yw.bae <yw.bae@samsung.corp-partner.google.com> Signed-off-by: Angela Wang <angelala@google.com>
208 lines
7.5 KiB
Java
208 lines
7.5 KiB
Java
/*
|
|
* Copyright (C) 2023 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.accessibility;
|
|
|
|
import static com.android.settings.accessibility.FlashNotificationsUtil.DEFAULT_SCREEN_FLASH_COLOR;
|
|
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION;
|
|
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR;
|
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.graphics.Color;
|
|
import android.provider.Settings;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import androidx.fragment.app.FragmentManager;
|
|
import androidx.preference.Preference;
|
|
import androidx.preference.PreferenceScreen;
|
|
|
|
import com.android.settings.R;
|
|
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.mockito.Mock;
|
|
import org.mockito.MockitoAnnotations;
|
|
import org.mockito.junit.MockitoJUnit;
|
|
import org.mockito.junit.MockitoRule;
|
|
import org.robolectric.Robolectric;
|
|
import org.robolectric.RobolectricTestRunner;
|
|
import org.robolectric.annotation.Config;
|
|
import org.robolectric.annotation.Implementation;
|
|
import org.robolectric.annotation.Implements;
|
|
import org.robolectric.annotation.Resetter;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
@RunWith(RobolectricTestRunner.class)
|
|
@Config(shadows = {
|
|
ScreenFlashNotificationPreferenceControllerTest
|
|
.ShadowScreenFlashNotificationColorDialogFragment.class,
|
|
ShadowFlashNotificationsUtils.class,
|
|
})
|
|
public class ScreenFlashNotificationPreferenceControllerTest {
|
|
private static final String PREFERENCE_KEY = "preference_key";
|
|
private static final String COLOR_DESCRIPTION_TEXT = "Colorful";
|
|
|
|
@Rule
|
|
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
|
|
|
@Mock
|
|
private PreferenceScreen mPreferenceScreen;
|
|
@Mock
|
|
private Preference mPreference;
|
|
@Mock
|
|
private Fragment mParentFragment;
|
|
@Mock
|
|
private FragmentManager mFragmentManager;
|
|
@Mock
|
|
private ScreenFlashNotificationColorDialogFragment mDialogFragment;
|
|
|
|
private ScreenFlashNotificationPreferenceController mController;
|
|
private ContentResolver mContentResolver;
|
|
|
|
@Before
|
|
public void setUp() {
|
|
MockitoAnnotations.initMocks(this);
|
|
FragmentActivity fragmentActivity = Robolectric.setupActivity(FragmentActivity.class);
|
|
Context context = fragmentActivity.getApplicationContext();
|
|
ShadowScreenFlashNotificationColorDialogFragment.setInstance(mDialogFragment);
|
|
ShadowFlashNotificationsUtils.setColorDescriptionText(COLOR_DESCRIPTION_TEXT);
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
mController = new ScreenFlashNotificationPreferenceController(context, PREFERENCE_KEY);
|
|
when(mPreferenceScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
|
|
when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
|
|
mController.setParentFragment(mParentFragment);
|
|
when(mParentFragment.getParentFragmentManager()).thenReturn(mFragmentManager);
|
|
}
|
|
|
|
@After
|
|
public void tearDown() {
|
|
ShadowScreenFlashNotificationColorDialogFragment.reset();
|
|
}
|
|
|
|
@Test
|
|
public void getAvailabilityStatus() {
|
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
|
}
|
|
|
|
@Test
|
|
public void isChecked_setOff_assertFalse() {
|
|
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 0);
|
|
assertThat(mController.isChecked()).isFalse();
|
|
}
|
|
|
|
@Test
|
|
public void isChecked_setOn_assertTrue() {
|
|
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 1);
|
|
assertThat(mController.isChecked()).isTrue();
|
|
}
|
|
|
|
@Test
|
|
public void setChecked_whenTransparentColor_setTrue_assertNotTransparentColor() {
|
|
Settings.System.putInt(mContentResolver,
|
|
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, Color.TRANSPARENT);
|
|
mController.setChecked(true);
|
|
assertThat(Settings.System.getInt(mContentResolver,
|
|
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, 0))
|
|
.isEqualTo(DEFAULT_SCREEN_FLASH_COLOR);
|
|
}
|
|
|
|
@Test
|
|
public void setChecked_whenNotTransparent_setTrue_assertSameColor() {
|
|
Settings.System.putInt(mContentResolver,
|
|
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, 0x4D0000FF);
|
|
mController.setChecked(true);
|
|
assertThat(Settings.System.getInt(mContentResolver,
|
|
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, 0))
|
|
.isEqualTo(0x4D0000FF);
|
|
}
|
|
|
|
@Test
|
|
public void setChecked_setTrue_assertOn() {
|
|
mController.setChecked(true);
|
|
assertThat(Settings.System.getInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION,
|
|
0)).isEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
public void setChecked_setFalse_assertOff() {
|
|
mController.setChecked(false);
|
|
assertThat(Settings.System.getInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION,
|
|
1)).isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
public void getSliceHighlightMenuRes() {
|
|
assertThat(mController.getSliceHighlightMenuRes())
|
|
.isEqualTo(R.string.menu_key_accessibility);
|
|
}
|
|
|
|
@Test
|
|
public void getSummary() {
|
|
assertThat(mController.getSummary()).isEqualTo(COLOR_DESCRIPTION_TEXT);
|
|
}
|
|
|
|
@Test
|
|
public void displayPreference() {
|
|
mController.displayPreference(mPreferenceScreen);
|
|
verify(mPreference).setSummary(COLOR_DESCRIPTION_TEXT);
|
|
}
|
|
|
|
@Test
|
|
public void handlePreferenceTreeClick() {
|
|
mController.handlePreferenceTreeClick(mPreference);
|
|
verify(mDialogFragment).show(any(FragmentManager.class), anyString());
|
|
}
|
|
|
|
/**
|
|
* Note: Actually, shadow of ScreenFlashNotificationColorDialogFragment will not be used.
|
|
* Instance that returned with {@link #getInstance} should be set with {@link #setInstance}
|
|
*/
|
|
@Implements(ScreenFlashNotificationColorDialogFragment.class)
|
|
public static class ShadowScreenFlashNotificationColorDialogFragment {
|
|
static ScreenFlashNotificationColorDialogFragment sInstance = null;
|
|
|
|
@Implementation
|
|
protected static ScreenFlashNotificationColorDialogFragment getInstance(
|
|
int initialColor, Consumer<Integer> colorConsumer) {
|
|
return sInstance;
|
|
}
|
|
|
|
public static void setInstance(ScreenFlashNotificationColorDialogFragment instance) {
|
|
sInstance = instance;
|
|
}
|
|
|
|
@Resetter
|
|
public static void reset() {
|
|
sInstance = null;
|
|
}
|
|
}
|
|
}
|