Declare "searchable" attribute for preferences.

Now we can easily mark a preference nonIndexable in xml instead of
adding key into searchIndexProvider.

Bug: 112608186
Test: robotests
Change-Id: I0ff16d44bb7b6ad148d3d35f09ca0da0163f73f4
This commit is contained in:
Fan Zhang
2018-08-14 16:25:54 -07:00
parent 097cfa7251
commit a79c377fbc
28 changed files with 201 additions and 148 deletions

View File

@@ -1,6 +1,7 @@
package com.android.settings.search;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -21,6 +22,9 @@ import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
public class SettingsSearchIndexablesProviderTest {
@@ -96,16 +100,19 @@ public class SettingsSearchIndexablesProviderTest {
@Test
@Config(qualifiers = "mcc999")
public void testNonIndexablesColumnFetched() {
Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
final Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH);
final Cursor cursor = mProvider.query(rawUri,
SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS, null, null, null);
final List<String> keys = new ArrayList<>();
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");
try (Cursor cursor = mProvider.query(rawUri,
SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS, null, null, null)) {
while (cursor.moveToNext()) {
keys.add(cursor.getString(0));
}
}
assertThat(keys).hasSize(3);
assertThat(keys).containsAllOf("pref_key_1", "pref_key_3", "pref_key_5");
}
}