InputMethodAndSubtypeEnabler use DashboardFragment
- Move preference log to InputMethodAndSubtypePreferenceController - Add input_methods_subtype.xml Test: manual Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.inputmethod Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.core Test: atest UniquePreferenceTest Change-Id: I45b6e8303d94ef07d17016eeed1d728432a70d98
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.inputmethod;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class InputMethodAndSubtypeEnablerTest {
|
||||
|
||||
private Activity mActivity;
|
||||
private InputMethodAndSubtypeEnabler mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mActivity = Robolectric.setupActivity(Activity.class);
|
||||
mFragment = spy(new InputMethodAndSubtypeEnabler());
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityCreated_shouldUpdateTitleFromArgument() {
|
||||
final String test = "title1";
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(Intent.EXTRA_TITLE, test);
|
||||
mFragment.setArguments(args);
|
||||
|
||||
mFragment.onActivityCreated(null);
|
||||
|
||||
assertThat(mFragment.getActivity().getTitle()).isEqualTo(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityCreated_shouldUpdateTitleFromIntent() {
|
||||
final String test = "title1";
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(Intent.EXTRA_TITLE, test);
|
||||
mActivity.setIntent(intent);
|
||||
|
||||
mFragment.onActivityCreated(null);
|
||||
|
||||
assertThat(mFragment.getActivity().getTitle()).isEqualTo(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceScreenResId_shouldReturnXml() {
|
||||
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(R.xml.input_methods_subtype);
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.inputmethod;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowInputMethodManagerWithMethodList;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.PreferenceFragment;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowInputMethodManagerWithMethodList.class)
|
||||
public class InputMethodAndSubtypePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceFragment mFragment;
|
||||
private Context mContext;
|
||||
private InputMethodAndSubtypePreferenceController mController;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getResources()).thenReturn(mContext.getResources());
|
||||
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
|
||||
mController = new InputMethodAndSubtypePreferenceController(mContext, "pref_key");
|
||||
mController.initialize(mFragment, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAlwaysAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hasInputMethodSubType_shouldAddPreference() {
|
||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||
final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
|
||||
|
||||
mController.displayPreference(screen);
|
||||
|
||||
assertThat(screen.getPreferenceCount()).isEqualTo(0);
|
||||
|
||||
final List<InputMethodInfo> imis = new ArrayList<>();
|
||||
imis.add(createInputMethodInfo("test", mContext));
|
||||
ShadowInputMethodManagerWithMethodList.getShadow().setInputMethodList(imis);
|
||||
|
||||
mController.initialize(mFragment, "");
|
||||
mController.displayPreference(screen);
|
||||
|
||||
assertThat(screen.getPreferenceCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
private InputMethodInfo createInputMethodInfo(final String name, Context targetContext) {
|
||||
List<InputMethodSubtype> subtypes = new ArrayList<>();
|
||||
|
||||
subtypes.add(new InputMethodSubtype.InputMethodSubtypeBuilder()
|
||||
.build());
|
||||
subtypes.add(new InputMethodSubtype.InputMethodSubtypeBuilder()
|
||||
.build());
|
||||
|
||||
final ResolveInfo resolveInfo = new ResolveInfo();
|
||||
resolveInfo.serviceInfo = new ServiceInfo();
|
||||
resolveInfo.serviceInfo.packageName = "com.android.ime";
|
||||
resolveInfo.serviceInfo.name = name;
|
||||
resolveInfo.serviceInfo.applicationInfo = new ApplicationInfo();
|
||||
resolveInfo.serviceInfo.applicationInfo.enabled = true;
|
||||
|
||||
return new InputMethodInfo(
|
||||
resolveInfo,
|
||||
false /* isAuxIme */,
|
||||
"SettingsActivity",
|
||||
subtypes,
|
||||
0 /* isDefaultResId */,
|
||||
true /* forceDefault */);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user