Bug: 35877479 Test: make RunSettingsRoboTests The existing behavior is to bring up a dialog with Bluetooth device details with checkboxes for each supported profile. This adds a new page that serves the same purpose with a switch for each profile and a footer containing the MAC address. Whether to use the new page or old dialog is controlled by a flag accessible via BluetoothFeatureProvider. Change-Id: I026c363d4cd33932a84017a67cbef51c258bad10
161 lines
5.8 KiB
Java
161 lines
5.8 KiB
Java
/*
|
|
* 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.bluetooth;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
|
|
import static org.mockito.Matchers.eq;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import android.widget.Button;
|
|
|
|
import com.android.settings.R;
|
|
import com.android.settings.SettingsRobolectricTestRunner;
|
|
import com.android.settings.TestConfig;
|
|
import com.android.settings.applications.LayoutPreference;
|
|
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
|
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.robolectric.annotation.Config;
|
|
|
|
@RunWith(SettingsRobolectricTestRunner.class)
|
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
|
shadows=SettingsShadowBluetoothDevice.class)
|
|
public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsControllerTestBase {
|
|
private BluetoothDetailsButtonsController mController;
|
|
private LayoutPreference mLayoutPreference;
|
|
private Button mLeftButton;
|
|
private Button mRightButton;
|
|
|
|
@Override
|
|
public void setUp() {
|
|
super.setUp();
|
|
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);
|
|
setupDevice(mDeviceConfig);
|
|
when(mCachedDevice.isBusy()).thenReturn(false);
|
|
}
|
|
|
|
@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));
|
|
}
|
|
|
|
@Test
|
|
public void clickOnDisconnect() {
|
|
showScreen(mController);
|
|
mLeftButton.callOnClick();
|
|
verify(mCachedDevice).disconnect();
|
|
}
|
|
|
|
@Test
|
|
public void clickOnConnect() {
|
|
when(mCachedDevice.isConnected()).thenReturn(false);
|
|
showScreen(mController);
|
|
|
|
assertThat(mLeftButton.getText()).isEqualTo(
|
|
mContext.getString(R.string.bluetooth_device_context_connect));
|
|
|
|
mLeftButton.callOnClick();
|
|
verify(mCachedDevice).connect(eq(true));
|
|
}
|
|
|
|
@Test
|
|
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));
|
|
|
|
// 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));
|
|
|
|
// Click the button and make sure that connect (not disconnect) gets called.
|
|
mLeftButton.callOnClick();
|
|
verify(mCachedDevice).connect(eq(true));
|
|
}
|
|
|
|
@Test
|
|
public void becomeConnected() {
|
|
// Start out with the device disconnected.
|
|
when(mCachedDevice.isConnected()).thenReturn(false);
|
|
showScreen(mController);
|
|
|
|
assertThat(mLeftButton.getText()).isEqualTo(
|
|
mContext.getString(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));
|
|
|
|
// Click the button and make sure that disconnnect (not connect) gets called.
|
|
mLeftButton.callOnClick();
|
|
verify(mCachedDevice).disconnect();
|
|
}
|
|
|
|
@Test
|
|
public void forget() {
|
|
showScreen(mController);
|
|
mRightButton.callOnClick();
|
|
verify(mCachedDevice).unpair();
|
|
verify(mActivity).finish();
|
|
}
|
|
|
|
|
|
@Test
|
|
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();
|
|
|
|
// Now pretend the device became non-busy.
|
|
when(mCachedDevice.isBusy()).thenReturn(false);
|
|
mController.onDeviceAttributesChanged();
|
|
assertThat(mLeftButton.isEnabled()).isTrue();
|
|
}
|
|
|
|
@Test
|
|
public void becomesBusy() {
|
|
showScreen(mController);
|
|
assertThat(mLeftButton.isEnabled()).isTrue();
|
|
|
|
when(mCachedDevice.isBusy()).thenReturn(true);
|
|
mController.onDeviceAttributesChanged();
|
|
assertThat(mLeftButton.isEnabled()).isFalse();
|
|
}
|
|
}
|