Merge changes from topic "GameDriver2"
* changes: Game Driver: Fix EnableForAllApps switch and test Game Driver: rename GUP to Game Driver Game Driver: Add footer to the dashboard Game Driver: Add SwitchBar to control GUP feature GUP: Add global switch for all apps GUP: Fixed some typos and update some values GUP: Display a list of Apps and dialogs GUP: Add stub UI
This commit is contained in:
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright 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.development;
|
||||
|
||||
import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_CODE_GUP_DEV_OPT_IN_APPS;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GameUpdatePackageDevOptInPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@Mock
|
||||
private DevelopmentSettingsDashboardFragment mFragment;
|
||||
|
||||
private Context mContext;
|
||||
private Preference mPreference;
|
||||
private GameUpdatePackageDevOptInPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new GameUpdatePackageDevOptInPreferenceController(mContext, mFragment));
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreference);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceClicked_launchActivity() {
|
||||
final Intent activityStartIntent = new Intent(mContext, AppPicker.class);
|
||||
final String preferenceKey = mController.getPreferenceKey();
|
||||
doReturn(activityStartIntent).when(mController).getActivityStartIntent();
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mFragment).startActivityForResult(activityStartIntent,
|
||||
REQUEST_CODE_GUP_DEV_OPT_IN_APPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_foobarAppSelected_shouldUpdateSummaryWithGUPDevOptInAppLabel() {
|
||||
final String selectedApp = "foobar";
|
||||
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||
Settings.Global.putString(contentResolver,
|
||||
Settings.Global.GUP_DEV_OPT_IN_APPS, selectedApp);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.gup_dev_opt_in_app_set, selectedApp));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_noAppSelected_shouldUpdateSummaryWithNoAppSelected() {
|
||||
final String selectedApp = null;
|
||||
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||
Settings.Global.putString(contentResolver,
|
||||
Settings.Global.GUP_DEV_OPT_IN_APPS, selectedApp);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.gup_dev_opt_in_app_not_set));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_foobarAppSelected_shouldUpdateSummaryWithGUPDevOptInLabel() {
|
||||
Intent activityResultIntent = new Intent(mContext, AppPicker.class);
|
||||
final String appLabel = "foobar";
|
||||
activityResultIntent.setAction(appLabel);
|
||||
final boolean result = mController
|
||||
.onActivityResult(REQUEST_CODE_GUP_DEV_OPT_IN_APPS, Activity.RESULT_OK,
|
||||
activityResultIntent);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.gup_dev_opt_in_app_set, appLabel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_badRequestCode_shouldReturnFalse() {
|
||||
assertThat(mController.onActivityResult(
|
||||
-1 /* requestCode */, -1 /* resultCode */, null /* intent */)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsSwitchDisabled();
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
mContext.getString(R.string.gup_dev_opt_in_app_not_set));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright 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.development.gamedriver;
|
||||
|
||||
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
|
||||
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.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GameDriverAppPreferenceControllerTest {
|
||||
|
||||
private static final int DEFAULT = 0;
|
||||
private static final int GAME_DRIVER = 1;
|
||||
private static final int SYSTEM = 2;
|
||||
private static final String TEST_APP_NAME = "testApp";
|
||||
private static final String TEST_PKG_NAME = "testPkg";
|
||||
|
||||
// Pre-installed Apps in the Mock PackageManager
|
||||
private static final String APP_1 = "app1";
|
||||
private static final String APP_2 = "app2";
|
||||
private static final String APP_3 = "app3";
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private GameDriverContentObserver mGameDriverContentObserver;
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceGroup mGroup;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private ContentResolver mResolver;
|
||||
private GameDriverAppPreferenceController mController;
|
||||
private CharSequence[] mValueList;
|
||||
private String mDialogTitle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mResolver = mContext.getContentResolver();
|
||||
mValueList =
|
||||
mContext.getResources().getStringArray(R.array.game_driver_app_preference_values);
|
||||
mDialogTitle = mContext.getResources().getString(R.string.game_driver_app_preference_title);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_shouldAddTwoPreferencesAndSortAscendingly() {
|
||||
mockPackageManager();
|
||||
loadDefaultConfig();
|
||||
|
||||
// Only non-system app has preference
|
||||
assertThat(mGroup.getPreferenceCount()).isEqualTo(2);
|
||||
assertThat(mGroup.getPreference(0).getKey()).isEqualTo(APP_1);
|
||||
assertThat(mGroup.getPreference(1).getKey()).isEqualTo(APP_3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRegister() {
|
||||
loadDefaultConfig();
|
||||
mController.mGameDriverContentObserver = mGameDriverContentObserver;
|
||||
mController.onStart();
|
||||
|
||||
verify(mGameDriverContentObserver).register(mResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldUnregister() {
|
||||
loadDefaultConfig();
|
||||
mController.mGameDriverContentObserver = mGameDriverContentObserver;
|
||||
mController.onStop();
|
||||
|
||||
verify(mGameDriverContentObserver).unregister(mResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreference_configDefault_shouldSetDefaultAttributes() {
|
||||
loadDefaultConfig();
|
||||
final ListPreference preference =
|
||||
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
|
||||
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
|
||||
assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
|
||||
assertThat(preference.getEntries()).isEqualTo(mValueList);
|
||||
assertThat(preference.getEntryValues()).isEqualTo(mValueList);
|
||||
assertThat(preference.getEntry()).isEqualTo(mValueList[DEFAULT]);
|
||||
assertThat(preference.getValue()).isEqualTo(mValueList[DEFAULT]);
|
||||
assertThat(preference.getSummary()).isEqualTo(mValueList[DEFAULT]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreference_configGAME_DRIVER_shouldSetGameDriverAttributes() {
|
||||
loadConfig(TEST_PKG_NAME, "");
|
||||
final ListPreference preference =
|
||||
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
|
||||
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
|
||||
assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
|
||||
assertThat(preference.getEntries()).isEqualTo(mValueList);
|
||||
assertThat(preference.getEntryValues()).isEqualTo(mValueList);
|
||||
assertThat(preference.getEntry()).isEqualTo(mValueList[GAME_DRIVER]);
|
||||
assertThat(preference.getValue()).isEqualTo(mValueList[GAME_DRIVER]);
|
||||
assertThat(preference.getSummary()).isEqualTo(mValueList[GAME_DRIVER]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreference_configSystem_shouldSetSystemAttributes() {
|
||||
loadConfig("", TEST_PKG_NAME);
|
||||
final ListPreference preference =
|
||||
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
|
||||
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
|
||||
assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
|
||||
assertThat(preference.getEntries()).isEqualTo(mValueList);
|
||||
assertThat(preference.getEntryValues()).isEqualTo(mValueList);
|
||||
assertThat(preference.getEntry()).isEqualTo(mValueList[SYSTEM]);
|
||||
assertThat(preference.getValue()).isEqualTo(mValueList[SYSTEM]);
|
||||
assertThat(preference.getSummary()).isEqualTo(mValueList[SYSTEM]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_selectDefault_shouldUpdateAttributesAndSettingsGlobal() {
|
||||
loadDefaultConfig();
|
||||
final ListPreference preference =
|
||||
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
|
||||
mController.onPreferenceChange(preference, mValueList[DEFAULT]);
|
||||
|
||||
assertThat(preference.getEntry()).isEqualTo(mValueList[DEFAULT]);
|
||||
assertThat(preference.getValue()).isEqualTo(mValueList[DEFAULT]);
|
||||
assertThat(preference.getSummary()).isEqualTo(mValueList[DEFAULT]);
|
||||
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
|
||||
.isEqualTo("");
|
||||
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
|
||||
.isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_selectGAME_DRIVER_shouldUpdateAttributesAndSettingsGlobal() {
|
||||
loadDefaultConfig();
|
||||
final ListPreference preference =
|
||||
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
|
||||
mController.onPreferenceChange(preference, mValueList[GAME_DRIVER]);
|
||||
|
||||
assertThat(preference.getEntry()).isEqualTo(mValueList[GAME_DRIVER]);
|
||||
assertThat(preference.getValue()).isEqualTo(mValueList[GAME_DRIVER]);
|
||||
assertThat(preference.getSummary()).isEqualTo(mValueList[GAME_DRIVER]);
|
||||
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
|
||||
.isEqualTo(TEST_PKG_NAME);
|
||||
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
|
||||
.isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_selectSystem_shouldUpdateAttributesAndSettingsGlobal() {
|
||||
loadDefaultConfig();
|
||||
final ListPreference preference =
|
||||
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
|
||||
mController.onPreferenceChange(preference, mValueList[SYSTEM]);
|
||||
|
||||
assertThat(preference.getEntry()).isEqualTo(mValueList[SYSTEM]);
|
||||
assertThat(preference.getValue()).isEqualTo(mValueList[SYSTEM]);
|
||||
assertThat(preference.getSummary()).isEqualTo(mValueList[SYSTEM]);
|
||||
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
|
||||
.isEqualTo("");
|
||||
assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
|
||||
.isEqualTo(TEST_PKG_NAME);
|
||||
}
|
||||
|
||||
private void mockPackageManager() {
|
||||
final int uid = mContext.getUserId();
|
||||
final ApplicationInfo app1 = buildInfo(uid, APP_1, 0 /* flags */, 0 /* targetSdkVersion */);
|
||||
final ApplicationInfo app2 =
|
||||
buildInfo(uid, APP_2, ApplicationInfo.FLAG_SYSTEM, 0 /* targetSdkVersion */);
|
||||
final ApplicationInfo app3 = buildInfo(uid, APP_3, 0 /* flags */, 0 /* targetSdkVersion */);
|
||||
|
||||
when(mPackageManager.getInstalledApplications(0 /* flags */))
|
||||
.thenReturn(Arrays.asList(app3, app2, app1));
|
||||
when(mPackageManager.getApplicationLabel(app1)).thenReturn(APP_1);
|
||||
when(mPackageManager.getApplicationLabel(app2)).thenReturn(APP_2);
|
||||
when(mPackageManager.getApplicationLabel(app3)).thenReturn(APP_3);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
}
|
||||
|
||||
private void loadDefaultConfig() { loadConfig("", ""); }
|
||||
|
||||
private void loadConfig(String optIn, String optOut) {
|
||||
Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS, optIn);
|
||||
Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut);
|
||||
|
||||
mController = new GameDriverAppPreferenceController(mContext, "testKey");
|
||||
mGroup = spy(new PreferenceCategory(mContext));
|
||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||
when(mGroup.getContext()).thenReturn(mContext);
|
||||
when(mGroup.getPreferenceManager()).thenReturn(preferenceManager);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mGroup);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 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.development.gamedriver;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.provider.Settings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GameDriverContentObserverTest {
|
||||
|
||||
@Mock
|
||||
private ContentResolver mResolver;
|
||||
@Mock
|
||||
private GameDriverContentObserver.OnGameDriverContentChangedListener mListener;
|
||||
|
||||
private GameDriverContentObserver mGameDriverContentObserver;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mGameDriverContentObserver = spy(new GameDriverContentObserver(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onChange_shouldCallListener() {
|
||||
mGameDriverContentObserver.mListener = mListener;
|
||||
mGameDriverContentObserver.onChange(true);
|
||||
|
||||
verify(mListener).onGameDriverContentChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void register_shouldRegisterContentObserver() {
|
||||
mGameDriverContentObserver.register(mResolver);
|
||||
|
||||
verify(mResolver).registerContentObserver(
|
||||
Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_ALL_APPS), false,
|
||||
mGameDriverContentObserver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregister_shouldUnregisterContentObserver() {
|
||||
mGameDriverContentObserver.unregister(mResolver);
|
||||
|
||||
verify(mResolver).unregisterContentObserver(mGameDriverContentObserver);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 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.development.gamedriver;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GameDriverDashboardTest {
|
||||
|
||||
private GameDriverDashboard mDashboard;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mDashboard = new GameDriverDashboard();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHelpResource_shouldReturn0() {
|
||||
assertThat(mDashboard.getHelpResource()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricesCategory_shouldReturnGameDriverDashboard() {
|
||||
assertThat(mDashboard.getMetricsCategory())
|
||||
.isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GAME_DRIVER_DASHBOARD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceScreen_shouldReturnGameDriverSettings() {
|
||||
assertThat(mDashboard.getPreferenceScreenResId()).isEqualTo(R.xml.game_driver_settings);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 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.development.gamedriver;
|
||||
|
||||
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
|
||||
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GameDriverEnableForAllAppsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
@Mock
|
||||
private GameDriverContentObserver mGameDriverContentObserver;
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
private GameDriverEnableForAllAppsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mResolver = mContext.getContentResolver();
|
||||
|
||||
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
|
||||
mController = new GameDriverEnableForAllAppsPreferenceController(mContext, "testKey");
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_shouldAddSwitchPreference() {
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRegister() {
|
||||
mController.mGameDriverContentObserver = mGameDriverContentObserver;
|
||||
mController.onStart();
|
||||
|
||||
verify(mGameDriverContentObserver).register(mResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldUnregister() {
|
||||
mController.mGameDriverContentObserver = mGameDriverContentObserver;
|
||||
mController.onStop();
|
||||
|
||||
verify(mGameDriverContentObserver).unregister(mResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_check_shouldUpdateSettingsGlobal() {
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
mController.onPreferenceChange(mPreference, true);
|
||||
|
||||
assertThat(Settings.Global.getInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
|
||||
.isEqualTo(GAME_DRIVER_ALL_APPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_uncheck_shouldUpdateSettingsGlobal() {
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
|
||||
mController.onPreferenceChange(mPreference, false);
|
||||
|
||||
assertThat(Settings.Global.getInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
|
||||
.isEqualTo(GAME_DRIVER_DEFAULT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 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.development.gamedriver;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
|
||||
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
|
||||
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
|
||||
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.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GameDriverFooterPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private FooterPreference mPreference;
|
||||
@Mock
|
||||
private GameDriverContentObserver mGameDriverContentObserver;
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
private GameDriverFooterPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mResolver = mContext.getContentResolver();
|
||||
mController = spy(new GameDriverFooterPreferenceController(mContext));
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_gameDriverOff_availableUnsearchable() {
|
||||
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_gameDriverDefault_conditionallyUnavailable() {
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_gameDriverAllApps_conditionallyUnavailable() {
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRegister() {
|
||||
mController.mGameDriverContentObserver = mGameDriverContentObserver;
|
||||
mController.onStart();
|
||||
|
||||
verify(mGameDriverContentObserver).register(mResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldUnregister() {
|
||||
mController.mGameDriverContentObserver = mGameDriverContentObserver;
|
||||
mController.onStop();
|
||||
|
||||
verify(mGameDriverContentObserver).unregister(mResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_available_visible() {
|
||||
when(mController.getAvailabilityStatus()).thenReturn(AVAILABLE);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setVisible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_unavailable_invisible() {
|
||||
when(mController.getAvailabilityStatus()).thenReturn(CONDITIONALLY_UNAVAILABLE);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setVisible(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 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.development.gamedriver;
|
||||
|
||||
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
|
||||
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settings.widget.SwitchBarController;
|
||||
import com.android.settings.widget.SwitchWidgetController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GameDriverGlobalSwitchBarControllerTest {
|
||||
|
||||
@Mock
|
||||
private SwitchBar mSwitchBar;
|
||||
@Mock
|
||||
private SwitchWidgetController mSwitchWidgetController;
|
||||
@Mock
|
||||
private GameDriverContentObserver mGameDriverContentObserver;
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
private GameDriverGlobalSwitchBarController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mResolver = mContext.getContentResolver();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_gameDriverOn_shouldCheckSwitchBar() {
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
mController = new GameDriverGlobalSwitchBarController(
|
||||
mContext, new SwitchBarController(mSwitchBar));
|
||||
|
||||
verify(mSwitchBar).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_gameDriverOff_shouldUncheckSwitchBar() {
|
||||
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
|
||||
mController = new GameDriverGlobalSwitchBarController(
|
||||
mContext, new SwitchBarController(mSwitchBar));
|
||||
|
||||
verify(mSwitchBar).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldStartListeningAndRegister() {
|
||||
mController = new GameDriverGlobalSwitchBarController(
|
||||
mContext, new SwitchBarController(mSwitchBar));
|
||||
mController.mSwitchWidgetController = mSwitchWidgetController;
|
||||
mController.mGameDriverContentObserver = mGameDriverContentObserver;
|
||||
mController.onStart();
|
||||
|
||||
verify(mSwitchWidgetController).startListening();
|
||||
verify(mGameDriverContentObserver).register(mResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldStopListeningAndUnregister() {
|
||||
mController = new GameDriverGlobalSwitchBarController(
|
||||
mContext, new SwitchBarController(mSwitchBar));
|
||||
mController.mSwitchWidgetController = mSwitchWidgetController;
|
||||
mController.mGameDriverContentObserver = mGameDriverContentObserver;
|
||||
mController.onStop();
|
||||
|
||||
verify(mSwitchWidgetController).stopListening();
|
||||
verify(mGameDriverContentObserver).unregister(mResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSwitchToggled_checked_shouldTurnOnGameDriver() {
|
||||
Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
|
||||
mController = new GameDriverGlobalSwitchBarController(
|
||||
mContext, new SwitchBarController(mSwitchBar));
|
||||
mController.onSwitchToggled(true);
|
||||
|
||||
assertThat(Settings.Global.getInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
|
||||
.isEqualTo(GAME_DRIVER_DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSwitchToggled_unchecked_shouldTurnOffGameDriver() {
|
||||
Settings.Global.putInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
|
||||
mController = new GameDriverGlobalSwitchBarController(
|
||||
mContext, new SwitchBarController(mSwitchBar));
|
||||
mController.onSwitchToggled(false);
|
||||
|
||||
assertThat(Settings.Global.getInt(
|
||||
mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
|
||||
.isEqualTo(GAME_DRIVER_OFF);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user