Files
app_Settings/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
Antony Sargent 2efec86bae Get rid of spurious gear icon in BT details page
The problem is that we were calling done() on the EntityHeaderController
and passing false for whether to rebind the action buttons, which means
we were getting the default behavior including a visible gear
icon. Passing true to request rebinding causes that icon to be hidden.

Bug: 63405635
Test: make RunSettingsRoboTests
Change-Id: I031f4a2d176ff3be025cc2675d7026a679936b03
2017-07-07 11:31:43 -07:00

105 lines
4.1 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 org.mockito.Matchers.any;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.graphics.drawable.Drawable;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows={SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class})
public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase {
private BluetoothDetailsHeaderController mController;
private LayoutPreference mPreference;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private EntityHeaderController mHeaderController;
@Override
public void setUp() {
super.setUp();
FakeFeatureFactory.setupForTest(spy(mContext));
ShadowEntityHeaderController.setUseMock(mHeaderController);
mController = new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice,
mLifecycle);
mPreference = new LayoutPreference(mContext, R.layout.settings_entity_header);
mPreference.setKey(mController.getPreferenceKey());
mScreen.addPreference(mPreference);
setupDevice(mDeviceConfig);
}
@After
public void tearDown() {
ShadowEntityHeaderController.reset();
}
@Test
public void header() {
showScreen(mController);
verify(mHeaderController).setLabel(mDeviceConfig.getName());
verify(mHeaderController).setIcon(any(Drawable.class));
verify(mHeaderController).setIconContentDescription(any(String.class));
verify(mHeaderController).setSummary(any(String.class));
verify(mHeaderController).done(mActivity, true);
}
@Test
public void connectionStatusChangesWhileScreenOpen() {
ArrayList<LocalBluetoothProfile> profiles = new ArrayList<>();
InOrder inOrder = inOrder(mHeaderController);
when(mCachedDevice.getConnectionSummary()).thenReturn(R.string.bluetooth_connected);
showScreen(mController);
inOrder.verify(mHeaderController).setSummary(mContext.getString(R.string.bluetooth_connected));
when(mCachedDevice.getConnectionSummary()).thenReturn(0);
mController.onDeviceAttributesChanged();
inOrder.verify(mHeaderController).setSummary((CharSequence) null);
when(mCachedDevice.getConnectionSummary()).thenReturn(R.string.bluetooth_connecting);
mController.onDeviceAttributesChanged();
inOrder.verify(mHeaderController).setSummary(
mContext.getString(R.string.bluetooth_connecting));
}
}