Merge "Convert more pages to use ActionButtonPreference"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c7e7f28e88
@@ -17,6 +17,18 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyDouble;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.Fragment;
|
||||
@@ -35,18 +47,18 @@ import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController;
|
||||
import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
@@ -69,18 +81,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.anyDouble;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@@ -133,6 +133,7 @@ public final class InstalledAppDetailsTest {
|
||||
|
||||
mBatteryPreference = new Preference(mShadowContext);
|
||||
mAppDetail.mBatteryPreference = mBatteryPreference;
|
||||
mAppDetail.mActionButtons = ActionButtonPreferenceTest.createMock();
|
||||
|
||||
mBatterySipper.drainType = BatterySipper.DrainType.IDLE;
|
||||
mBatterySipper.uidObj = mUid;
|
||||
@@ -281,15 +282,13 @@ public final class InstalledAppDetailsTest {
|
||||
appEntry.info = info;
|
||||
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||
packageInfo.applicationInfo = info;
|
||||
final Button uninstallButton = mock(Button.class);
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
ReflectionHelpers.setField(mAppDetail, "mUninstallButton", uninstallButton);
|
||||
|
||||
mAppDetail.initUnintsallButtonForUserApp();
|
||||
verify(uninstallButton).setVisibility(View.GONE);
|
||||
mAppDetail.initUninstallButtonForUserApp();
|
||||
verify(mAppDetail.mActionButtons).setButton1Visible(false);
|
||||
}
|
||||
|
||||
// Tests that we don't show the force stop button for instant apps (they aren't allowed to run
|
||||
@@ -303,15 +302,13 @@ public final class InstalledAppDetailsTest {
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
appEntry.info = info;
|
||||
final Button forceStopButton = mock(Button.class);
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
ReflectionHelpers.setField(mAppDetail, "mForceStopButton", forceStopButton);
|
||||
|
||||
mAppDetail.checkForceStop();
|
||||
verify(forceStopButton).setVisibility(View.GONE);
|
||||
verify(mAppDetail.mActionButtons).setButton2Visible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -484,10 +481,9 @@ public final class InstalledAppDetailsTest {
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mHomePackages", homePackages);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
final Button button = mock(Button.class);
|
||||
|
||||
assertThat(mAppDetail.handleDisableable(button)).isFalse();
|
||||
verify(button).setText(R.string.disable_text);
|
||||
assertThat(mAppDetail.handleDisableable()).isFalse();
|
||||
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -506,10 +502,31 @@ public final class InstalledAppDetailsTest {
|
||||
ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
|
||||
mFeatureFactory.applicationFeatureProvider);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
final Button button = mock(Button.class);
|
||||
|
||||
assertThat(mAppDetail.handleDisableable(button)).isTrue();
|
||||
verify(button).setText(R.string.disable_text);
|
||||
assertThat(mAppDetail.handleDisableable()).isTrue();
|
||||
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowUtils.class)
|
||||
public void handleDisableable_appIsDisabled_buttonShouldShowEnable() {
|
||||
final ApplicationInfo info = new ApplicationInfo();
|
||||
info.packageName = "pkg";
|
||||
info.enabled = false;
|
||||
info.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
||||
|
||||
final AppEntry appEntry = mock(AppEntry.class);
|
||||
appEntry.info = info;
|
||||
when(mFeatureFactory.applicationFeatureProvider.getKeepEnabledPackages()).thenReturn(
|
||||
new HashSet<>());
|
||||
|
||||
ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
|
||||
mFeatureFactory.applicationFeatureProvider);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
|
||||
assertThat(mAppDetail.handleDisableable()).isTrue();
|
||||
verify(mAppDetail.mActionButtons).setButton1Text(R.string.enable_text);
|
||||
verify(mAppDetail.mActionButtons).setButton1Positive(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -532,10 +549,8 @@ public final class InstalledAppDetailsTest {
|
||||
mFeatureFactory.applicationFeatureProvider);
|
||||
ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
|
||||
|
||||
final Button button = mock(Button.class);
|
||||
|
||||
assertThat(mAppDetail.handleDisableable(button)).isFalse();
|
||||
verify(button).setText(R.string.disable_text);
|
||||
assertThat(mAppDetail.handleDisableable()).isFalse();
|
||||
verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -48,7 +48,7 @@ public class LayoutPreferenceTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new LayoutPreference(mContext, R.layout.app_action_buttons);
|
||||
mPreference = new LayoutPreference(mContext, R.layout.two_action_buttons);
|
||||
mRootView = mPreference.mRootView;
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.layout_preference_frame, null, false));
|
||||
@@ -79,12 +79,12 @@ public class LayoutPreferenceTest {
|
||||
|
||||
@Test
|
||||
public void disableSomeView_shouldMaintainStateAfterBind() {
|
||||
mPreference.findViewById(R.id.left_button).setEnabled(false);
|
||||
mPreference.findViewById(R.id.right_button).setEnabled(true);
|
||||
mPreference.findViewById(R.id.button1_positive).setEnabled(false);
|
||||
mPreference.findViewById(R.id.button2_positive).setEnabled(true);
|
||||
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mPreference.findViewById(R.id.left_button).isEnabled()).isFalse();
|
||||
assertThat(mPreference.findViewById(R.id.right_button).isEnabled()).isTrue();
|
||||
assertThat(mPreference.findViewById(R.id.button1_positive).isEnabled()).isFalse();
|
||||
assertThat(mPreference.findViewById(R.id.button2_positive).isEnabled()).isTrue();
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -26,17 +26,20 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -44,22 +47,34 @@ import org.robolectric.annotation.Config;
|
||||
shadows = SettingsShadowBluetoothDevice.class)
|
||||
public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsControllerTestBase {
|
||||
private BluetoothDetailsButtonsController mController;
|
||||
private LayoutPreference mLayoutPreference;
|
||||
private ActionButtonPreference mButtonsPref;
|
||||
private Button mLeftButton;
|
||||
private Button mRightButton;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
final View buttons = View.inflate(
|
||||
RuntimeEnvironment.application, R.layout.two_action_buttons, null /* parent */);
|
||||
mLeftButton = buttons.findViewById(R.id.button1_positive);
|
||||
mRightButton = buttons.findViewById(R.id.button2_positive);
|
||||
mController = new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice,
|
||||
mLifecycle);
|
||||
mLeftButton = new Button(mContext);
|
||||
mRightButton = new Button(mContext);
|
||||
mLayoutPreference = new LayoutPreference(mContext, R.layout.app_action_buttons);
|
||||
mLayoutPreference.setKey(mController.getPreferenceKey());
|
||||
mScreen.addPreference(mLayoutPreference);
|
||||
mLeftButton = (Button) mLayoutPreference.findViewById(R.id.left_button);
|
||||
mRightButton = (Button) mLayoutPreference.findViewById(R.id.right_button);
|
||||
mButtonsPref = ActionButtonPreferenceTest.createMock();
|
||||
when(mButtonsPref.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
when(mButtonsPref.setButton1OnClickListener(any(View.OnClickListener.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
final Object[] args = invocation.getArguments();
|
||||
mLeftButton.setOnClickListener((View.OnClickListener) args[0]);
|
||||
return mButtonsPref;
|
||||
});
|
||||
when(mButtonsPref.setButton2OnClickListener(any(View.OnClickListener.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
final Object[] args = invocation.getArguments();
|
||||
mRightButton.setOnClickListener((View.OnClickListener) args[0]);
|
||||
return mButtonsPref;
|
||||
});
|
||||
mScreen.addPreference(mButtonsPref);
|
||||
setupDevice(mDeviceConfig);
|
||||
when(mCachedDevice.isBusy()).thenReturn(false);
|
||||
}
|
||||
@@ -67,15 +82,16 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
||||
@Test
|
||||
public void connected() {
|
||||
showScreen(mController);
|
||||
assertThat(mLeftButton.getText()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_device_context_disconnect));
|
||||
assertThat(mRightButton.getText()).isEqualTo(mContext.getString(R.string.forget));
|
||||
|
||||
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_disconnect);
|
||||
verify(mButtonsPref).setButton2Text(R.string.forget);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickOnDisconnect() {
|
||||
showScreen(mController);
|
||||
mLeftButton.callOnClick();
|
||||
|
||||
verify(mCachedDevice).disconnect();
|
||||
}
|
||||
|
||||
@@ -84,8 +100,7 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
||||
when(mCachedDevice.isConnected()).thenReturn(false);
|
||||
showScreen(mController);
|
||||
|
||||
assertThat(mLeftButton.getText()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_device_context_connect));
|
||||
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_connect);
|
||||
|
||||
mLeftButton.callOnClick();
|
||||
verify(mCachedDevice).connect(eq(true));
|
||||
@@ -95,14 +110,12 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
||||
public void becomeDisconnected() {
|
||||
showScreen(mController);
|
||||
// By default we start out with the device connected.
|
||||
assertThat(mLeftButton.getText()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_device_context_disconnect));
|
||||
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_disconnect);
|
||||
|
||||
// Now make the device appear to have changed to disconnected.
|
||||
when(mCachedDevice.isConnected()).thenReturn(false);
|
||||
mController.onDeviceAttributesChanged();
|
||||
assertThat(mLeftButton.getText()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_device_context_connect));
|
||||
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_connect);
|
||||
|
||||
// Click the button and make sure that connect (not disconnect) gets called.
|
||||
mLeftButton.callOnClick();
|
||||
@@ -115,14 +128,13 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
||||
when(mCachedDevice.isConnected()).thenReturn(false);
|
||||
showScreen(mController);
|
||||
|
||||
assertThat(mLeftButton.getText()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_device_context_connect));
|
||||
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_connect);
|
||||
|
||||
|
||||
// Now make the device appear to have changed to connected.
|
||||
when(mCachedDevice.isConnected()).thenReturn(true);
|
||||
mController.onDeviceAttributesChanged();
|
||||
assertThat(mLeftButton.getText()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_device_context_disconnect));
|
||||
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_disconnect);
|
||||
|
||||
// Click the button and make sure that disconnnect (not connect) gets called.
|
||||
mLeftButton.callOnClick();
|
||||
@@ -150,24 +162,27 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
||||
public void startsOutBusy() {
|
||||
when(mCachedDevice.isBusy()).thenReturn(true);
|
||||
showScreen(mController);
|
||||
assertThat(mLeftButton.getText()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_device_context_disconnect));
|
||||
assertThat(mRightButton.getText()).isEqualTo(mContext.getString(R.string.forget));
|
||||
assertThat(mLeftButton.isEnabled()).isFalse();
|
||||
|
||||
verify(mButtonsPref).setButton1Text(R.string.bluetooth_device_context_disconnect);
|
||||
verify(mButtonsPref).setButton1Enabled(false);
|
||||
verify(mButtonsPref).setButton2Text(R.string.forget);
|
||||
|
||||
// Now pretend the device became non-busy.
|
||||
when(mCachedDevice.isBusy()).thenReturn(false);
|
||||
mController.onDeviceAttributesChanged();
|
||||
assertThat(mLeftButton.isEnabled()).isTrue();
|
||||
|
||||
verify(mButtonsPref).setButton1Enabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void becomesBusy() {
|
||||
showScreen(mController);
|
||||
assertThat(mLeftButton.isEnabled()).isTrue();
|
||||
verify(mButtonsPref).setButton1Enabled(true);
|
||||
|
||||
// Now pretend the device became busy.
|
||||
when(mCachedDevice.isBusy()).thenReturn(true);
|
||||
mController.onDeviceAttributesChanged();
|
||||
assertThat(mLeftButton.isEnabled()).isFalse();
|
||||
|
||||
verify(mButtonsPref).setButton1Enabled(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user