Implements queryNonIndexableKeys for Settings

queryNonIndexableKeys returns a list of all of the
non-indexable keys for all providers in Settings

Change-Id: Id53cb2f55662e85c66f1c3f0c0e7d933b19fedaf
Fixes: 34623460
Test: RunSettingsRoboTests
This commit is contained in:
Matthew Fritze
2017-01-24 10:45:11 -08:00
parent a1bae0ad7e
commit 2108f91fe6
5 changed files with 129 additions and 5 deletions

View File

@@ -16,14 +16,20 @@
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_DATA_RES_ID;
import static com.android.settings.search.SearchIndexableResources.sResMap;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.annotation.DrawableRes;
import android.annotation.XmlRes;
import android.database.Cursor;
import android.provider.SearchIndexableResource;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -31,8 +37,11 @@ import com.android.settings.wifi.WifiSettings;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.HashMap;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SearchIndexableResourcesTest {
@@ -72,4 +81,24 @@ public class SearchIndexableResourcesTest {
assertThat(index.xmlResId).isEqualTo(NO_DATA_RES_ID);
assertThat(index.iconResId).isEqualTo(R.drawable.ic_settings_wireless);
}
@Test
public void testNonIndexableKeys_GetsKeyFromProvider() {
SearchIndexableResources.sResMap.clear();
SearchIndexableResources.addIndex(FakeIndexProvider.class, 0, 0);
SettingsSearchIndexablesProvider provider = spy(new SettingsSearchIndexablesProvider());
Cursor cursor = provider.queryNonIndexableKeys(null);
boolean hasTestKey = false;
while(cursor.moveToNext()) {
String key = cursor.getString(COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE);
if (TextUtils.equals(key, FakeIndexProvider.KEY)) {
hasTestKey = true;
break;
}
}
assertThat(hasTestKey).isTrue();
}
}