Merge "Introduce boolean flags to show/hide items for Language & input."

This commit is contained in:
Ben Lin
2018-01-10 22:29:28 +00:00
committed by Android (Google) Code Review
17 changed files with 265 additions and 22 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,6 +35,7 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@@ -44,18 +46,18 @@ import java.util.List;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class GameControllerPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private InputManager mInputManager;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private InputDevice mInputDevice;
private Context mContext;
private GameControllerPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mInputManager);
mController = new GameControllerPreferenceController(mContext);
}
@@ -110,6 +112,14 @@ public class GameControllerPreferenceControllerTest {
assertThat(mController.isAvailable()).isFalse();
}
@Test
@Config(qualifiers = "mcc999")
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
mController = new GameControllerPreferenceController(mContext);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void updateNonIndexableKeys_shouldIncludeCategoryAndPrefKeys() {
when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{});

View File

@@ -18,6 +18,7 @@ package com.android.settings.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -37,6 +38,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -65,10 +67,22 @@ public class PhysicalKeyboardPreferenceControllerTest {
}
@Test
public void shouldAlwaysBeAvailable() {
public void testPhysicalKeyboard_byDefault_shouldBeShown() {
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new PhysicalKeyboardPreferenceController(context, null);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testPhysicalKeyboard_ifDisabled_shouldNotBeShown() {
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new PhysicalKeyboardPreferenceController(context, null);
assertThat(mController.isAvailable()).isFalse();
}
@Test
@Config(shadows = {
ShadowInputDevice.class,

View File

@@ -16,7 +16,10 @@
package com.android.settings.inputmethod;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.preference.Preference;
import android.view.textservice.SpellCheckerInfo;
import android.view.textservice.TextServicesManager;
@@ -46,6 +49,9 @@ public class SpellCheckerPreferenceControllerTest {
private Context mContext;
@Mock
private TextServicesManager mTextServicesManager;
@Mock
private Resources mResources;
private Context mAppContext;
private Preference mPreference;
private SpellCheckerPreferenceController mController;
@@ -56,10 +62,23 @@ public class SpellCheckerPreferenceControllerTest {
mAppContext = RuntimeEnvironment.application;
when(mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
.thenReturn(mTextServicesManager);
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getBoolean(R.bool.config_show_spellcheckers_settings)).thenReturn(true);
mPreference = new Preference(mAppContext);
mController = new SpellCheckerPreferenceController(mContext);
}
@Test
public void testSpellChecker_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testSpellChecker_ifDisabled_shouldNotBeShown() {
when(mResources.getBoolean(R.bool.config_show_spellcheckers_settings)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void updateState_NoSpellerChecker_shouldSetSummaryToDefault() {
when(mTextServicesManager.isSpellCheckerEnabled()).thenReturn(true);

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -75,10 +76,20 @@ public class VirtualKeyboardPreferenceControllerTest {
}
@Test
public void shouldAlwaysBeAvailable() {
public void testVirtualKeyboard_byDefault_shouldBeShown() {
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new VirtualKeyboardPreferenceController(context);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testVirtualKeyboard_ifDisabled_shouldNotBeShown() {
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new VirtualKeyboardPreferenceController(context);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void updateState_noEnabledIMEs_setEmptySummary() {
mController.updateState(mPreference);

View File

@@ -17,10 +17,13 @@
package com.android.settings.language;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.AssetManager;
import android.support.v7.preference.Preference;
import com.android.settings.TestConfig;
@@ -33,6 +36,7 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@@ -42,34 +46,44 @@ import java.util.List;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PhoneLanguagePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private Preference mPreference;
@Mock
private AssetManager mAssets;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private PhoneLanguagePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getAssets()).thenReturn(mAssets);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mController = new PhoneLanguagePreferenceController(mContext);
}
@Test
public void testIsAvailable_hasMultipleLocales_shouldReturnTrue() {
when(mContext.getAssets().getLocales()).thenReturn(new String[] {"en", "de"});
when(mAssets.getLocales()).thenReturn(new String[] {"en", "de"});
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testIsAvailable_hasSingleLocales_shouldReturnFalse() {
when(mContext.getAssets().getLocales()).thenReturn(new String[] {"en"});
when(mAssets.getLocales()).thenReturn(new String[] {"en"});
assertThat(mController.isAvailable()).isFalse();
}
@Test
@Config(qualifiers = "mcc999")
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testUpdateState_shouldUpdateSummary() {
final String testSummary = "test";

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2017 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.language;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PointerSpeedControllerTest {
private Context mContext;
private PointerSpeedController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new PointerSpeedController(mContext);
}
@Test
public void testDeviceAdministrators_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testDeviceAdministrators_ifDisabled_shouldNotBeShown() {
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -18,6 +18,7 @@ package com.android.settings.language;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -45,19 +46,19 @@ import java.util.List;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class TtsPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private TtsEngines mTtsEngines;
@Mock
private PreferenceScreen mScreen;
private Context mContext;
private TtsPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new TtsPreferenceController(mContext, mTtsEngines);
mPreference = new Preference(RuntimeEnvironment.application);
@@ -89,4 +90,11 @@ public class TtsPreferenceControllerTest {
assertThat(mPreference.isVisible()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
assertThat(mController.isAvailable()).isFalse();
}
}