Merge Screen Attention and Screen timeout Settings.
Bug: 155051311 Test: atest Change-Id: I6f6ee52618eab629a41b28982be32ead5f9ba08d
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.display;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ScreenTimeoutSettingsTest {
|
||||
private static final String[] TIMEOUT_ENTRIES = new String[]{"15 secs", "30 secs"};
|
||||
private static final String[] TIMEOUT_VALUES = new String[]{"15000", "30000"};
|
||||
|
||||
private ScreenTimeoutSettings mSettings;
|
||||
private Context mContext;
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(getApplicationContext());
|
||||
mSettings = spy(new ScreenTimeoutSettings());
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
|
||||
doReturn(TIMEOUT_ENTRIES).when(mResources).getStringArray(R.array.screen_timeout_entries);
|
||||
doReturn(TIMEOUT_VALUES).when(mResources).getStringArray(R.array.screen_timeout_entries);
|
||||
doReturn(mResources).when(mSettings).getResources();
|
||||
doReturn(mContext).when(mSettings).getContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
ScreenTimeoutSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||
mContext, true /* enabled */);
|
||||
|
||||
assertThat(indexRes).isNotNull();
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultKey_returnCurrentTimeout() {
|
||||
long timeout = Long.parseLong(TIMEOUT_VALUES[1]);
|
||||
Settings.System.putLong(mContentResolver, SCREEN_OFF_TIMEOUT, timeout);
|
||||
|
||||
String key = mSettings.getDefaultKey();
|
||||
|
||||
assertThat(key).isEqualTo(TIMEOUT_VALUES[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultKey_controlCurrentScreenTimeout() {
|
||||
mSettings.setDefaultKey(TIMEOUT_VALUES[0]);
|
||||
|
||||
long timeout = Settings.System.getLong(mContentResolver, SCREEN_OFF_TIMEOUT,
|
||||
30000 /* default */);
|
||||
|
||||
assertThat(Long.toString(timeout)).isEqualTo(TIMEOUT_VALUES[0]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user