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.gestures; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.os.UserHandle; 23 import android.provider.Settings; 24 25 import com.android.settings.R; 26 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 import org.robolectric.RobolectricTestRunner; 31 import org.robolectric.RuntimeEnvironment; 32 33 @RunWith(RobolectricTestRunner.class) 34 public class OneHandedSettingsUtilsTest { 35 36 private static final int TIMEOUT_INDEX_NEVER = 0; 37 private static final int TIMEOUT_INDEX_SHORT = 1; 38 private static final int TIMEOUT_INDEX_MEDIUM = 2; 39 private static final int TIMEOUT_INDEX_LONG = 3; 40 41 private static final int OFF = 0; 42 private static final int ON = 1; 43 44 private Context mContext; 45 46 private String[] mConfigTimeout; 47 private int mCurrentUserId; 48 49 @Before setUp()50 public void setUp() { 51 mContext = RuntimeEnvironment.application; 52 mCurrentUserId = UserHandle.myUserId(); 53 mConfigTimeout = mContext.getResources().getStringArray(R.array.one_handed_timeout_values); 54 OneHandedSettingsUtils.setUserId(mCurrentUserId); 55 } 56 57 @Test setOneHandedModeEnabled_setEnable_shouldReturnEnabled()58 public void setOneHandedModeEnabled_setEnable_shouldReturnEnabled() { 59 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, true); 60 61 assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(), 62 Settings.Secure.ONE_HANDED_MODE_ENABLED, OFF, mCurrentUserId)).isEqualTo(ON); 63 } 64 65 @Test setOneHandedModeEnabled_setDisable_shouldReturnDisabled()66 public void setOneHandedModeEnabled_setDisable_shouldReturnDisabled() { 67 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, false); 68 69 assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(), 70 Settings.Secure.ONE_HANDED_MODE_ENABLED, OFF, mCurrentUserId)).isEqualTo(OFF); 71 } 72 73 @Test setTapsAppToExitEnabled_setEnable_shouldReturnEnabled()74 public void setTapsAppToExitEnabled_setEnable_shouldReturnEnabled() { 75 OneHandedSettingsUtils.setTapsAppToExitEnabled(mContext, true); 76 77 assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(), 78 Settings.Secure.TAPS_APP_TO_EXIT, OFF, mCurrentUserId)).isEqualTo(ON); 79 } 80 81 @Test setTapsAppToExitEnabled_setDisable_shouldReturnDisabled()82 public void setTapsAppToExitEnabled_setDisable_shouldReturnDisabled() { 83 OneHandedSettingsUtils.setTapsAppToExitEnabled(mContext, false); 84 85 assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(), 86 Settings.Secure.TAPS_APP_TO_EXIT, OFF, mCurrentUserId)).isEqualTo(OFF); 87 } 88 89 @Test setTimeout_setNever_shouldReturnNeverValue()90 public void setTimeout_setNever_shouldReturnNeverValue() { 91 OneHandedSettingsUtils.setTimeoutValue(mContext, 92 OneHandedSettingsUtils.OneHandedTimeout.NEVER.getValue()); 93 94 assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(), 95 Settings.Secure.ONE_HANDED_MODE_TIMEOUT, 96 OneHandedSettingsUtils.OneHandedTimeout.NEVER.getValue(), mCurrentUserId)) 97 .isEqualTo(Integer.parseInt(mConfigTimeout[TIMEOUT_INDEX_NEVER])); 98 } 99 100 @Test setTimeout_setShort_shouldReturnShortValue()101 public void setTimeout_setShort_shouldReturnShortValue() { 102 OneHandedSettingsUtils.setTimeoutValue(mContext, 103 OneHandedSettingsUtils.OneHandedTimeout.SHORT.getValue()); 104 105 assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(), 106 Settings.Secure.ONE_HANDED_MODE_TIMEOUT, 107 OneHandedSettingsUtils.OneHandedTimeout.SHORT.getValue(), mCurrentUserId)) 108 .isEqualTo(Integer.parseInt(mConfigTimeout[TIMEOUT_INDEX_SHORT])); 109 } 110 111 @Test setTimeout_setMedium_shouldReturnMediumValue()112 public void setTimeout_setMedium_shouldReturnMediumValue() { 113 OneHandedSettingsUtils.setTimeoutValue(mContext, 114 OneHandedSettingsUtils.OneHandedTimeout.MEDIUM.getValue()); 115 116 assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(), 117 Settings.Secure.ONE_HANDED_MODE_TIMEOUT, 118 OneHandedSettingsUtils.OneHandedTimeout.MEDIUM.getValue(), mCurrentUserId)) 119 .isEqualTo(Integer.parseInt(mConfigTimeout[TIMEOUT_INDEX_MEDIUM])); 120 } 121 122 @Test setTimeout_setLong_shouldReturnLongValue()123 public void setTimeout_setLong_shouldReturnLongValue() { 124 OneHandedSettingsUtils.setTimeoutValue(mContext, 125 OneHandedSettingsUtils.OneHandedTimeout.LONG.getValue()); 126 127 assertThat(Settings.Secure.getIntForUser(mContext.getContentResolver(), 128 Settings.Secure.ONE_HANDED_MODE_TIMEOUT, 129 OneHandedSettingsUtils.OneHandedTimeout.LONG.getValue(), mCurrentUserId)) 130 .isEqualTo(Integer.parseInt(mConfigTimeout[TIMEOUT_INDEX_LONG])); 131 } 132 } 133