Dupe BluetoothSettings and DeviceListPreferenceFragment
Create the obsolete version of the belowing fragments, so we could flip between old page and new page. BluetoothSettingsObsolete and DeviceListPreferenceObsoleteFragment contains all the old logic but: 1. Logic about BluetoothPairingPreferenceController(ag/2239482), since this preference shouldn't be checked in without the flag :( This cl also adds logic in MasterSwitchPreferenceController to flip these two pages. Following cl will refactor these fragment to make it compatible to new framework. Bug: 35877041 Test: RunSettingsRoboTests Change-Id: I1cc1bc2d49d8a3e11c3127e56f6409fbc84028d8
This commit is contained in:
@@ -16,14 +16,18 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
@@ -38,7 +42,10 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -54,17 +61,26 @@ public class BluetoothMasterSwitchPreferenceControllerTest {
|
||||
private MasterSwitchPreference mPreference;
|
||||
@Mock
|
||||
private RestrictionUtils mRestrictionUtils;
|
||||
@Mock
|
||||
private Fragment mFragment;
|
||||
@Mock
|
||||
private SettingsActivity mActivity;
|
||||
|
||||
private Context mContext;
|
||||
private BluetoothMasterSwitchPreferenceController mController;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application.getApplicationContext();
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
mController = new BluetoothMasterSwitchPreferenceController(
|
||||
mContext, mBluetoothManager, mRestrictionUtils);
|
||||
mContext, mBluetoothManager, mRestrictionUtils, mFragment, mActivity);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +100,7 @@ public class BluetoothMasterSwitchPreferenceControllerTest {
|
||||
mController.onPause();
|
||||
|
||||
verify(mBluetoothManager.getEventManager()).unregisterCallback(
|
||||
any(BluetoothCallback.class));
|
||||
any(BluetoothCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,4 +130,22 @@ public class BluetoothMasterSwitchPreferenceControllerTest {
|
||||
verify(mPreference).setSummary("test summary");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_pairPageEnabled_showNewPage() {
|
||||
when(mFeatureFactory.bluetoothFeatureProvider.isPairingPageEnabled()).thenReturn(true);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mActivity).startPreferencePanelAsUser(eq(mFragment),
|
||||
eq(BluetoothSettings.class.getName()), any(), eq(R.string.bluetooth), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_pairPageDisabled_showOldPage() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mActivity).startPreferencePanelAsUser(eq(mFragment),
|
||||
eq(BluetoothSettingsObsolete.class.getName()), any(), eq(R.string.bluetooth), any(),
|
||||
any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothSettingsObsoleteTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private BluetoothSettingsObsolete mFragment;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
mFragment = spy(new BluetoothSettingsObsolete());
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_pairPageEnabled_keyAdded() {
|
||||
doReturn(true).when(mFeatureFactory.bluetoothFeatureProvider).isPairingPageEnabled();
|
||||
|
||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mContext);
|
||||
|
||||
assertThat(keys).contains(BluetoothSettingsObsolete.DATA_KEY_REFERENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_pairPageDisabled_keyNotAdded() {
|
||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mContext);
|
||||
|
||||
assertThat(keys).doesNotContain(BluetoothSettingsObsolete.DATA_KEY_REFERENCE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,16 +31,20 @@ import android.support.v7.preference.Preference;
|
||||
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 org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothSettingsTest {
|
||||
@@ -50,17 +54,21 @@ public class BluetoothSettingsTest {
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private Resources mResource;
|
||||
@Mock
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
private BluetoothSettings mFragment;
|
||||
private Preference mMyDevicePreference;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
mFragment = spy(new BluetoothSettings());
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
doReturn(mResource).when(mFragment).getResources();
|
||||
@@ -86,4 +94,22 @@ public class BluetoothSettingsTest {
|
||||
assertThat(mMyDevicePreference.getTitle()).isEqualTo(FOOTAGE_MAC_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_pairPageEnabled_keyNotAdded() {
|
||||
doReturn(true).when(mFeatureFactory.bluetoothFeatureProvider).isPairingPageEnabled();
|
||||
|
||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mContext);
|
||||
|
||||
assertThat(keys).doesNotContain(BluetoothSettings.DATA_KEY_REFERENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_pairPageDisabled_keyAdded() {
|
||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
mContext);
|
||||
|
||||
assertThat(keys).contains(BluetoothSettings.DATA_KEY_REFERENCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ import android.nfc.NfcManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.nfc.NfcPreferenceController;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.nfc.NfcPreferenceController;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user