Merge "Move Index provider conversion into Settings provider"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2260321fd8
@@ -114,11 +114,10 @@ public class SearchIndexProviderCodeInspector extends CodeInspector {
|
||||
continue;
|
||||
}
|
||||
// Must be in SearchProviderRegistry
|
||||
if (SearchIndexableResources.getResourceByName(className) == null) {
|
||||
if (!SearchIndexableResources.providerValues().contains(clazz)) {
|
||||
if (!notInSearchIndexableRegistryGrandfatherList.remove(className)) {
|
||||
notInSearchProviderRegistry.add(className);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,12 +17,13 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
|
||||
import static com.android.settings.search.SearchIndexableResources.NO_RES_ID;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
@@ -35,60 +36,48 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SearchIndexableResourcesTest {
|
||||
|
||||
Map<String, SearchIndexableResource> sResMapCopy;
|
||||
Set<Class> sProviderClassCopy;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
sResMapCopy = new HashMap<>(SearchIndexableResources.sResMap);
|
||||
sProviderClassCopy = new HashSet<>(SearchIndexableResources.sProviders);
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
SearchIndexableResources.sResMap.clear();
|
||||
for (String key : sResMapCopy.keySet()) {
|
||||
SearchIndexableResources.sResMap.put(key, sResMapCopy.get(key));
|
||||
}
|
||||
SearchIndexableResources.sProviders.clear();
|
||||
SearchIndexableResources.sProviders.addAll(sProviderClassCopy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddIndex() {
|
||||
final Class stringClass = java.lang.String.class;
|
||||
// Confirms that String.class isn't contained in SearchIndexableResources.
|
||||
assertThat(SearchIndexableResources.getResourceByName("java.lang.String")).isNull();
|
||||
final int beforeCount = SearchIndexableResources.values().size();
|
||||
assertThat(SearchIndexableResources.sProviders).doesNotContain(stringClass);
|
||||
final int beforeCount = SearchIndexableResources.providerValues().size();
|
||||
|
||||
SearchIndexableResources.addIndex(java.lang.String.class);
|
||||
final SearchIndexableResource index = SearchIndexableResources
|
||||
.getResourceByName("java.lang.String");
|
||||
|
||||
assertThat(index).isNotNull();
|
||||
assertThat(index.className).isEqualTo("java.lang.String");
|
||||
assertThat(index.xmlResId).isEqualTo(NO_RES_ID);
|
||||
assertThat(index.iconResId).isEqualTo(NO_RES_ID);
|
||||
final int afterCount = SearchIndexableResources.values().size();
|
||||
assertThat(SearchIndexableResources.sProviders).contains(stringClass);
|
||||
final int afterCount = SearchIndexableResources.providerValues().size();
|
||||
assertThat(afterCount).isEqualTo(beforeCount + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexHasWifiSettings() {
|
||||
final SearchIndexableResource index = SearchIndexableResources
|
||||
.getResourceByName(WifiSettings.class.getName());
|
||||
|
||||
assertThat(index).isNotNull();
|
||||
assertThat(index.className).isEqualTo(WifiSettings.class.getName());
|
||||
assertThat(index.xmlResId).isEqualTo(NO_RES_ID);
|
||||
assertThat(index.iconResId).isEqualTo(NO_RES_ID);
|
||||
assertThat(sProviderClassCopy).contains(WifiSettings.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIndexableKeys_GetsKeyFromProvider() {
|
||||
SearchIndexableResources.sResMap.clear();
|
||||
SearchIndexableResources.sProviders.clear();
|
||||
SearchIndexableResources.addIndex(FakeIndexProvider.class);
|
||||
|
||||
SettingsSearchIndexablesProvider provider = spy(new SettingsSearchIndexablesProvider());
|
||||
@@ -105,4 +94,13 @@ public class SearchIndexableResourcesTest {
|
||||
|
||||
assertThat(hasTestKey).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllClassNamesHaveProviders() {
|
||||
for (Class clazz: sProviderClassCopy) {
|
||||
if(DatabaseIndexingUtils.getSearchIndexProvider(clazz) == null) {
|
||||
fail(clazz.getName() + "is not an index provider");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,119 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.SearchIndexablesContract;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search.indexing.FakeSettingsFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SettingsSearchIndexablesProviderTest {
|
||||
|
||||
private final String BASE_AUTHORITY = "com.android.settings";
|
||||
|
||||
private SettingsSearchIndexablesProvider mProvider;
|
||||
|
||||
Set<Class> sProviderClasses;
|
||||
Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mProvider = spy(new SettingsSearchIndexablesProvider());
|
||||
ProviderInfo info = new ProviderInfo();
|
||||
info.exported = true;
|
||||
info.grantUriPermissions = true;
|
||||
info.authority = BASE_AUTHORITY;
|
||||
info.readPermission = Manifest.permission.READ_SEARCH_INDEXABLES;
|
||||
mProvider.attachInfo(mContext, info);
|
||||
|
||||
sProviderClasses = new HashSet<>(SearchIndexableResources.sProviders);
|
||||
SearchIndexableResources.sProviders.clear();
|
||||
SearchIndexableResources.sProviders.add(FakeSettingsFragment.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
SearchIndexableResources.sProviders.clear();
|
||||
SearchIndexableResources.sProviders.addAll(sProviderClasses);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawColumnFetched() {
|
||||
Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
|
||||
SearchIndexablesContract.INDEXABLES_RAW_PATH);
|
||||
|
||||
final Cursor cursor = mProvider.query(rawUri,
|
||||
SearchIndexablesContract.INDEXABLES_RAW_COLUMNS, null, null, null);
|
||||
|
||||
cursor.moveToFirst();
|
||||
assertThat(cursor.getString(1)).isEqualTo(FakeSettingsFragment.TITLE);
|
||||
assertThat(cursor.getString(2)).isEqualTo(FakeSettingsFragment.SUMMARY_ON);
|
||||
assertThat(cursor.getString(3)).isEqualTo(FakeSettingsFragment.SUMMARY_OFF);
|
||||
assertThat(cursor.getString(4)).isEqualTo(FakeSettingsFragment.ENTRIES);
|
||||
assertThat(cursor.getString(5)).isEqualTo(FakeSettingsFragment.KEYWORDS);
|
||||
assertThat(cursor.getString(6)).isEqualTo(FakeSettingsFragment.SCREEN_TITLE);
|
||||
assertThat(cursor.getString(7)).isEqualTo(FakeSettingsFragment.CLASS_NAME);
|
||||
assertThat(cursor.getInt(8)).isEqualTo(FakeSettingsFragment.ICON);
|
||||
assertThat(cursor.getString(9)).isEqualTo(FakeSettingsFragment.INTENT_ACTION);
|
||||
assertThat(cursor.getString(10)).isEqualTo(FakeSettingsFragment.TARGET_PACKAGE);
|
||||
assertThat(cursor.getString(11)).isEqualTo(FakeSettingsFragment.TARGET_CLASS);
|
||||
assertThat(cursor.getString(12)).isEqualTo(FakeSettingsFragment.KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourcesColumnFetched() {
|
||||
Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
|
||||
SearchIndexablesContract.INDEXABLES_XML_RES_PATH);
|
||||
|
||||
final Cursor cursor = mProvider.query(rawUri,
|
||||
SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS, null, null, null);
|
||||
|
||||
cursor.moveToFirst();
|
||||
assertThat(cursor.getCount()).isEqualTo(1);
|
||||
assertThat(cursor.getInt(1)).isEqualTo(R.xml.display_settings);
|
||||
assertThat(cursor.getString(2)).isEqualTo(FakeSettingsFragment.CLASS_NAME);
|
||||
assertThat(cursor.getInt(3)).isEqualTo(0);
|
||||
assertThat(cursor.getString(4)).isNull();
|
||||
assertThat(cursor.getString(5)).isNull();
|
||||
assertThat(cursor.getString(6)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIndexablesColumnFetched() {
|
||||
Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
|
||||
SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH);
|
||||
//final ContentResolver resolver = mContext.getContentResolver();
|
||||
|
||||
final Cursor cursor = mProvider.query(rawUri,
|
||||
SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS, null, null, null);
|
||||
|
||||
cursor.moveToFirst();
|
||||
assertThat(cursor.getCount()).isEqualTo(2);
|
||||
assertThat(cursor.getString(0)).isEqualTo("pref_key_1");
|
||||
cursor.moveToNext();
|
||||
assertThat(cursor.getString(0)).isEqualTo("pref_key_3");
|
||||
}
|
||||
}
|
@@ -266,55 +266,6 @@ public class IndexDataConverterTest {
|
||||
assertThat(row.iconResId).isGreaterThan(0);
|
||||
}
|
||||
|
||||
// Tests for the flow: IndexOneResource -> IndexFromProvider -> IndexFromResource ->
|
||||
// UpdateOneRowWithFilteredData -> UpdateOneRow
|
||||
|
||||
@Test
|
||||
public void testAddProviderWithResource_rowInserted() {
|
||||
final SearchIndexableResource resource = getFakeResource(0 /* xml */);
|
||||
resource.className = FAKE_CLASS_NAME;
|
||||
final PreIndexData preIndexData = new PreIndexData();
|
||||
preIndexData.dataToUpdate.add(resource);
|
||||
|
||||
List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
|
||||
|
||||
assertThat(indexData.size()).isEqualTo(NUM_FAKE_FRAGMENT_ENTRIES);
|
||||
assertThat(findIndexDataForTitle(indexData, PAGE_TITLE)).isNotNull();
|
||||
assertThat(findIndexDataForTitle(indexData, TITLE_ONE)).isNotNull();
|
||||
assertThat(findIndexDataForTitle(indexData, TITLE_TWO)).isNotNull();
|
||||
assertThat(findIndexDataForTitle(indexData, TITLE_THREE)).isNotNull();
|
||||
assertThat(findIndexDataForTitle(indexData, TITLE_FOUR)).isNotNull();
|
||||
assertThat(findIndexDataForTitle(indexData, TITLE_FIVE)).isNotNull();
|
||||
assertThat(findIndexDataForTitle(indexData, FakeSettingsFragment.TITLE)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddProviderWithRaw_rowInserted() {
|
||||
final SearchIndexableResource resource = getFakeResource(0 /* xml */);
|
||||
resource.className = FAKE_CLASS_NAME;
|
||||
final PreIndexData preIndexData = new PreIndexData();
|
||||
preIndexData.dataToUpdate.add(resource);
|
||||
|
||||
List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
|
||||
|
||||
final IndexData data = findIndexDataForTitle(indexData, FakeSettingsFragment.TITLE);
|
||||
assertFakeFragment(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddProvider_disabledRows() {
|
||||
// Note that in FakeSettingsFragment, preferences 1 and 3 are disabled.
|
||||
final SearchIndexableResource resource = getFakeResource(0 /* xml */);
|
||||
resource.className = FAKE_CLASS_NAME;
|
||||
|
||||
final PreIndexData preIndexData = new PreIndexData();
|
||||
preIndexData.dataToUpdate.add(resource);
|
||||
|
||||
List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
|
||||
|
||||
assertThat(getEnabledResultCount(indexData)).isEqualTo(NUM_ENABLED_FAKE_FRAGMENT_ENTRIES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResource_sameTitleForSettingAndPage_titleNotInserted() {
|
||||
final SearchIndexableResource resource = getFakeResource(R.xml.about_legal);
|
||||
|
Reference in New Issue
Block a user