Files
app_Settings/tests/robotests/src/com/android/settings/accessibility/LockScreenRotationPreferenceControllerTest.java
Mill Chen dce601db84 Pull out a PreferenceController of lock screen from accessibility
To reduce the complexity of AccessibilitySettings, we are planning to
create a bunch of preference controllers. First of all, we are converting
lock screen preference to a preference controller. The rest part will be
uploaded soon.

Bug: 135056871
Test: robotest, manual
Change-Id: I6079136f3d08934c9a5363eb4d0e0ade29f8ba99
2019-06-19 16:44:42 +08:00

108 lines
3.6 KiB
Java

/*
* 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.accessibility;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.SwitchPreference;
import com.android.internal.view.RotationPolicy;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
public class LockScreenRotationPreferenceControllerTest {
private Context mContext;
private SwitchPreference mPreference;
private LockScreenRotationPreferenceController mController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mPreference = new SwitchPreference(mContext);
mController = new LockScreenRotationPreferenceController(mContext, "lock_screen");
}
@Test
@Config(shadows = {ShadowRotationPolicy.class})
public void getAvailabilityStatus_supportedRotation_shouldReturnAvailable() {
ShadowRotationPolicy.setRotationSupported(true /* supported */);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
@Config(shadows = {ShadowRotationPolicy.class})
public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
ShadowRotationPolicy.setRotationSupported(false /* supported */);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
@Config(shadows = {ShadowRotationPolicy.class})
public void setChecked_enabled() {
mController.setChecked(true /* isChecked */);
assertThat(mController.isChecked()).isTrue();
assertThat(RotationPolicy.isRotationLocked(mContext)).isFalse();
}
@Test
@Config(shadows = {ShadowRotationPolicy.class})
public void setChecked_disabled() {
mController.setChecked(false /* isChecked */);
assertThat(mController.isChecked()).isFalse();
assertThat(RotationPolicy.isRotationLocked(mContext)).isTrue();
}
@Test
public void updateState_settingIsOn_shouldTurnOnToggle() {
Settings.System.putIntForUser(mContext.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, 1, UserHandle.USER_CURRENT);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void updateState_settingIsOff_shouldTurnOffToggle() {
Settings.System.putIntForUser(mContext.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
}
}