Split BluetoothSettings into two pages
This cl splits the BluetoothSettings into paired device page and pairing page, including small changes about: 1. Refactor the pages so they could get as much as static preference from xml file rather than dynamically add/remove them everytime. 2. Remove creating method in BluetoothDeviceNamePreferenceController and add it in xml file 3. Create BluetoothPairingDetail page, basically move the logic from BluetoothSettings. 4. Make pairing preference clickable and jump to BluetoothPairingDetail 5. Add and update bunch of tests Bug: 35877041 Test: RunSettingsRoboTests Change-Id: Ief9e9690c612f7b46c58e866e5cecc511af642c8
This commit is contained in:
@@ -23,16 +23,21 @@ import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -54,28 +59,43 @@ public class BluetoothSettingsTest {
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private Resources mResource;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private PreferenceGroup mPairedDevicesCategory;
|
||||
@Mock
|
||||
private BluetoothPairingPreferenceController mPairingPreferenceController;
|
||||
private Context mContext;
|
||||
private BluetoothSettings mFragment;
|
||||
private Preference mMyDevicePreference;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private Preference mFooterPreference;
|
||||
private TextView mEmptyMessage;
|
||||
private View mContainer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
mFragment = spy(new BluetoothSettings());
|
||||
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
doReturn(mResource).when(mFragment).getResources();
|
||||
doReturn(mActivity).when(mFragment).getActivity();
|
||||
|
||||
mMyDevicePreference = new Preference(RuntimeEnvironment.application);
|
||||
mContainer = new View(mContext);
|
||||
mEmptyMessage = new TextView(mContext);
|
||||
doReturn(mContainer).when(mActivity).findViewById(android.R.id.list_container);
|
||||
doReturn(mEmptyMessage).when(mActivity).findViewById(android.R.id.empty);
|
||||
|
||||
mFooterPreference = new FooterPreference(RuntimeEnvironment.application);
|
||||
mFragment.setLocalBluetoothAdapter(mLocalAdapter);
|
||||
mFragment.mPairingPrefController = mPairingPreferenceController;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,9 +109,38 @@ public class BluetoothSettingsTest {
|
||||
doReturn(FOOTAGE_MAC_STRING).when(mFragment).getString(
|
||||
eq(R.string.bluetooth_footer_mac_message), any());
|
||||
|
||||
mFragment.updateMyDevicePreference(mMyDevicePreference);
|
||||
mFragment.updateFooterPreference(mFooterPreference);
|
||||
|
||||
assertThat(mMyDevicePreference.getTitle()).isEqualTo(FOOTAGE_MAC_STRING);
|
||||
assertThat(mFooterPreference.getTitle()).isEqualTo(FOOTAGE_MAC_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayEmptyMessage_showEmptyMessage() {
|
||||
mFragment.displayEmptyMessage(true);
|
||||
|
||||
assertThat(mContainer.getVisibility()).isEqualTo(View.INVISIBLE);
|
||||
assertThat(mEmptyMessage.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayEmptyMessage_hideEmptyMessage() {
|
||||
mFragment.displayEmptyMessage(false);
|
||||
|
||||
assertThat(mContainer.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mEmptyMessage.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitPreferencesFromPreferenceScreen() {
|
||||
doReturn(mPairedDevicesCategory).when(mFragment).findPreference(
|
||||
BluetoothSettings.KEY_PAIRED_DEVICES);
|
||||
doReturn(mFooterPreference).when(mFragment).findPreference(
|
||||
BluetoothSettings.KEY_FOOTER_PREF);
|
||||
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
assertThat(mFragment.mPairedDevicesCategory).isEqualTo(mPairedDevicesCategory);
|
||||
assertThat(mFragment.mFooterPreference).isEqualTo(mFooterPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user