Add search providers for Connected Devices in new IA

Also add code inspection tests to ensure search provider is added
properly.

Bug: 33252252
Test: make RunSettingsRoboTests
Change-Id: I192e1d9fe0498b76013c4d43b5624d1ef2beb6f9
This commit is contained in:
Fan Zhang
2016-11-30 15:56:17 -08:00
parent 8a898fe430
commit 762b4969d9
11 changed files with 152 additions and 77 deletions

View File

@@ -16,10 +16,13 @@
package com.android.settings.connecteddevice;
import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -27,28 +30,45 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ConnectedDeviceDashboardFragmentTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private ConnectedDeviceDashboardFragment mFragment;
private ConnectedDeviceDashboardFragment mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFragment = new ConnectedDeviceDashboardFragment();
}
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
final FakeFeatureFactory factory =
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mFragment = new ConnectedDeviceDashboardFragment();
}
@Test
public void testCategory_isConnectedDevice() {
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE);
}
@Test
public void testCategory_isConnectedDevice() {
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE);
}
@Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
ShadowApplication.getInstance().getApplicationContext(),
true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
}
}