Loading tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java +25 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.display; import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_LOCKED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; Loading @@ -39,6 +41,10 @@ import java.util.List; @RunWith(RobolectricTestRunner.class) public class DeviceStateAutoRotateDetailsFragmentTest { private static final int FOLDED_STATE = 0; private static final int HALF_FOLDED_STATE = 1; private static final int UNFOLDED_STATE = 2; private static final int REAR_DISPLAY_STATE = 3; private final DeviceStateAutoRotateDetailsFragment mFragment = spy(new DeviceStateAutoRotateDetailsFragment()); Loading @@ -51,6 +57,7 @@ public class DeviceStateAutoRotateDetailsFragmentTest { when(mContext.getApplicationContext()).thenReturn(mContext); when(mFragment.getContext()).thenReturn(mContext); when(mFragment.getResources()).thenReturn(mResources); setUpPostureMappings(); } @Test Loading @@ -67,7 +74,9 @@ public class DeviceStateAutoRotateDetailsFragmentTest { @Test public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() { enableDeviceStateSettableRotationStates(new String[]{"0:1", "1:1"}, enableDeviceStateSettableRotationStates( new String[]{FOLDED_STATE + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED, UNFOLDED_STATE + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED}, new String[]{"Folded", "Unfolded"}); List<AbstractPreferenceController> preferenceControllers = Loading Loading @@ -102,4 +111,19 @@ public class DeviceStateAutoRotateDetailsFragmentTest { DeviceStateRotationLockSettingsManager.getInstance(mContext) .resetStateForTesting(mResources); } private void setUpPostureMappings() { when(mResources.getIntArray( com.android.internal.R.array.config_foldedDeviceStates)).thenReturn( new int[]{FOLDED_STATE}); when(mResources.getIntArray( com.android.internal.R.array.config_halfFoldedDeviceStates)).thenReturn( new int[]{HALF_FOLDED_STATE}); when(mResources.getIntArray( com.android.internal.R.array.config_openDeviceStates)).thenReturn( new int[]{UNFOLDED_STATE}); when(mResources.getIntArray( com.android.internal.R.array.config_rearDisplayDeviceStates)).thenReturn( new int[]{REAR_DISPLAY_STATE}); } } tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java +7 −8 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; @RunWith(RobolectricTestRunner.class) @Config(shadows = ShadowSensorPrivacyManager.class) Loading Loading @@ -171,16 +172,14 @@ public class SmartAutoRotateControllerTest { } private void lockDeviceStateRotation() { mDeviceStateAutoRotateSettingsManager.updateSetting( /* deviceState= */0, /* rotationLocked= */ true); mDeviceStateAutoRotateSettingsManager.updateSetting( /* deviceState= */1, /* rotationLocked= */ true); ShadowDeviceStateRotationLockSettingsManager shadowManager = Shadow.extract(mDeviceStateAutoRotateSettingsManager); shadowManager.setRotationLockedForAllStates(true); } private void unlockDeviceStateRotation() { mDeviceStateAutoRotateSettingsManager.updateSetting( /* deviceState= */0, /* rotationLocked= */ false); mDeviceStateAutoRotateSettingsManager.updateSetting( /* deviceState= */1, /* rotationLocked= */ true); ShadowDeviceStateRotationLockSettingsManager shadowManager = Shadow.extract(mDeviceStateAutoRotateSettingsManager); shadowManager.setRotationLockedForAllStates(false); } } tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateRotationLockSettingsManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import org.robolectric.annotation.Implements; public class ShadowDeviceStateRotationLockSettingsManager { private static boolean sDeviceStateRotationLockEnabled; private boolean mIsRotationLockedForAllStates; @Implementation public static boolean isDeviceStateRotationLockEnabled(Context context) { Loading @@ -36,4 +37,13 @@ public class ShadowDeviceStateRotationLockSettingsManager { public static void setDeviceStateRotationLockEnabled(boolean enabled) { sDeviceStateRotationLockEnabled = enabled; } @Implementation public boolean isRotationLockedForAllStates() { return mIsRotationLockedForAllStates; } public void setRotationLockedForAllStates(boolean value) { mIsRotationLockedForAllStates = value; } } Loading
tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java +25 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.display; import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_LOCKED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; Loading @@ -39,6 +41,10 @@ import java.util.List; @RunWith(RobolectricTestRunner.class) public class DeviceStateAutoRotateDetailsFragmentTest { private static final int FOLDED_STATE = 0; private static final int HALF_FOLDED_STATE = 1; private static final int UNFOLDED_STATE = 2; private static final int REAR_DISPLAY_STATE = 3; private final DeviceStateAutoRotateDetailsFragment mFragment = spy(new DeviceStateAutoRotateDetailsFragment()); Loading @@ -51,6 +57,7 @@ public class DeviceStateAutoRotateDetailsFragmentTest { when(mContext.getApplicationContext()).thenReturn(mContext); when(mFragment.getContext()).thenReturn(mContext); when(mFragment.getResources()).thenReturn(mResources); setUpPostureMappings(); } @Test Loading @@ -67,7 +74,9 @@ public class DeviceStateAutoRotateDetailsFragmentTest { @Test public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() { enableDeviceStateSettableRotationStates(new String[]{"0:1", "1:1"}, enableDeviceStateSettableRotationStates( new String[]{FOLDED_STATE + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED, UNFOLDED_STATE + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED}, new String[]{"Folded", "Unfolded"}); List<AbstractPreferenceController> preferenceControllers = Loading Loading @@ -102,4 +111,19 @@ public class DeviceStateAutoRotateDetailsFragmentTest { DeviceStateRotationLockSettingsManager.getInstance(mContext) .resetStateForTesting(mResources); } private void setUpPostureMappings() { when(mResources.getIntArray( com.android.internal.R.array.config_foldedDeviceStates)).thenReturn( new int[]{FOLDED_STATE}); when(mResources.getIntArray( com.android.internal.R.array.config_halfFoldedDeviceStates)).thenReturn( new int[]{HALF_FOLDED_STATE}); when(mResources.getIntArray( com.android.internal.R.array.config_openDeviceStates)).thenReturn( new int[]{UNFOLDED_STATE}); when(mResources.getIntArray( com.android.internal.R.array.config_rearDisplayDeviceStates)).thenReturn( new int[]{REAR_DISPLAY_STATE}); } }
tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java +7 −8 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; @RunWith(RobolectricTestRunner.class) @Config(shadows = ShadowSensorPrivacyManager.class) Loading Loading @@ -171,16 +172,14 @@ public class SmartAutoRotateControllerTest { } private void lockDeviceStateRotation() { mDeviceStateAutoRotateSettingsManager.updateSetting( /* deviceState= */0, /* rotationLocked= */ true); mDeviceStateAutoRotateSettingsManager.updateSetting( /* deviceState= */1, /* rotationLocked= */ true); ShadowDeviceStateRotationLockSettingsManager shadowManager = Shadow.extract(mDeviceStateAutoRotateSettingsManager); shadowManager.setRotationLockedForAllStates(true); } private void unlockDeviceStateRotation() { mDeviceStateAutoRotateSettingsManager.updateSetting( /* deviceState= */0, /* rotationLocked= */ false); mDeviceStateAutoRotateSettingsManager.updateSetting( /* deviceState= */1, /* rotationLocked= */ true); ShadowDeviceStateRotationLockSettingsManager shadowManager = Shadow.extract(mDeviceStateAutoRotateSettingsManager); shadowManager.setRotationLockedForAllStates(false); } }
tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceStateRotationLockSettingsManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import org.robolectric.annotation.Implements; public class ShadowDeviceStateRotationLockSettingsManager { private static boolean sDeviceStateRotationLockEnabled; private boolean mIsRotationLockedForAllStates; @Implementation public static boolean isDeviceStateRotationLockEnabled(Context context) { Loading @@ -36,4 +37,13 @@ public class ShadowDeviceStateRotationLockSettingsManager { public static void setDeviceStateRotationLockEnabled(boolean enabled) { sDeviceStateRotationLockEnabled = enabled; } @Implementation public boolean isRotationLockedForAllStates() { return mIsRotationLockedForAllStates; } public void setRotationLockedForAllStates(boolean value) { mIsRotationLockedForAllStates = value; } }