Merge "Add getDescendants to Settings Slice Provider" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1257466d0b
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.android.settings.slices;
|
||||
|
||||
import static android.content.ContentResolver.SCHEME_CONTENT;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -41,6 +43,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@@ -114,7 +117,190 @@ public class SettingsSliceProviderTest {
|
||||
assertThat(cachedData).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_fullActionUri_returnsSelf() {
|
||||
final Uri uri = SliceBuilderUtils.getUri(
|
||||
SettingsSlicesContract.PATH_SETTING_ACTION + "/key", true);
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_fullIntentUri_returnsSelf() {
|
||||
final Uri uri = SliceBuilderUtils.getUri(
|
||||
SettingsSlicesContract.PATH_SETTING_ACTION + "/key", true);
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_wrongPath_returnsEmpty() {
|
||||
final Uri uri = SliceBuilderUtils.getUri("invalid_path", true);
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_invalidPath_returnsEmpty() {
|
||||
final String key = "platform_key";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath("invalid")
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
|
||||
insertSpecialCase("oem_key", false /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
|
||||
insertSpecialCase("platform_key", true /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
|
||||
final String key = "oem_key";
|
||||
insertSpecialCase(key, false /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.build();
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(expectedUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_oemSliceNoPath_returnsOEMUriDescendant() {
|
||||
final String key = "oem_key";
|
||||
insertSpecialCase(key, false /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.build();
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(expectedUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
|
||||
final String key = "platform_key";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.build();
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(expectedUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_platformSliceNoPath_returnsPlatformUriDescendant() {
|
||||
final String key = "platform_key";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.build();
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(expectedUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_noAuthorityNorPath_returnsAllUris() {
|
||||
final String platformKey = "platform_key";
|
||||
final String oemKey = "oemKey";
|
||||
insertSpecialCase(platformKey, true /* isPlatformSlice */);
|
||||
insertSpecialCase(oemKey, false /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.build();
|
||||
final Uri expectedPlatformUri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(platformKey)
|
||||
.build();
|
||||
final Uri expectedOemUri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(oemKey)
|
||||
.build();
|
||||
|
||||
final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri);
|
||||
|
||||
assertThat(descendants).containsExactly(expectedPlatformUri, expectedOemUri);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
insertSpecialCase(key, true);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key, boolean isPlatformSlice) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, TITLE);
|
||||
@@ -123,6 +309,8 @@ public class SettingsSliceProviderTest {
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, 1234);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, "test");
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, "test");
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.PLATFORM_SLICE, isPlatformSlice);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_TYPE, SliceData.SliceType.INTENT);
|
||||
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
}
|
||||
|
@@ -295,14 +295,16 @@ public class SliceBuilderUtilsTest {
|
||||
assertThat(pathPair.second).isEqualTo(KEY);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void getPathData_noKey_returnsNull() {
|
||||
final Uri uri = new Uri.Builder()
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.build();
|
||||
|
||||
SliceBuilderUtils.getPathData(uri);
|
||||
final Pair<Boolean, String> pathPair = SliceBuilderUtils.getPathData(uri);
|
||||
|
||||
assertThat(pathPair).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -18,6 +18,7 @@
|
||||
package com.android.settings.slices;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.ContentValues;
|
||||
@@ -35,15 +36,17 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class SlicesDatabaseAccessorTest {
|
||||
|
||||
private final String fakeTitle = "title";
|
||||
private final String fakeSummary = "summary";
|
||||
private final String fakeScreenTitle = "screen_title";
|
||||
private final int fakeIcon = 1234;
|
||||
private final String fakeFragmentClassName = FakeIndexProvider.class.getName();
|
||||
private final String fakeControllerName = FakePreferenceController.class.getName();
|
||||
private final String FAKE_TITLE = "title";
|
||||
private final String FAKE_SUMMARY = "summary";
|
||||
private final String FAKE_SCREEN_TITLE = "screen_title";
|
||||
private final int FAKE_ICON = 1234;
|
||||
private final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName();
|
||||
private final String FAKE_CONTROLLER_NAME = FakePreferenceController.class.getName();
|
||||
|
||||
private Context mContext;
|
||||
private SQLiteDatabase mDb;
|
||||
@@ -70,13 +73,13 @@ public class SlicesDatabaseAccessorTest {
|
||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||
|
||||
assertThat(data.getKey()).isEqualTo(key);
|
||||
assertThat(data.getTitle()).isEqualTo(fakeTitle);
|
||||
assertThat(data.getSummary()).isEqualTo(fakeSummary);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(fakeScreenTitle);
|
||||
assertThat(data.getIconResource()).isEqualTo(fakeIcon);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(fakeFragmentClassName);
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(fakeControllerName);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@@ -96,13 +99,13 @@ public class SlicesDatabaseAccessorTest {
|
||||
SliceData data = mAccessor.getSliceDataFromUri(uri);
|
||||
|
||||
assertThat(data.getKey()).isEqualTo(key);
|
||||
assertThat(data.getTitle()).isEqualTo(fakeTitle);
|
||||
assertThat(data.getSummary()).isEqualTo(fakeSummary);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(fakeScreenTitle);
|
||||
assertThat(data.getIconResource()).isEqualTo(fakeIcon);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(fakeFragmentClassName);
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isEqualTo(uri);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(fakeControllerName);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@@ -111,15 +114,62 @@ public class SlicesDatabaseAccessorTest {
|
||||
mAccessor.getSliceDataFromUri(uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
|
||||
final String key = "oem_key";
|
||||
final boolean isPlatformSlice = false;
|
||||
insertSpecialCase(key, isPlatformSlice);
|
||||
final List<String> keys = mAccessor.getSliceKeys(!isPlatformSlice);
|
||||
|
||||
assertThat(keys).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
|
||||
final String key = "platform_key";
|
||||
final boolean isPlatformSlice = true;
|
||||
insertSpecialCase(key, isPlatformSlice);
|
||||
final List<String> keys = mAccessor.getSliceKeys(!isPlatformSlice);
|
||||
|
||||
assertThat(keys).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
|
||||
final String key = "oem_key";
|
||||
final boolean isPlatformSlice = false;
|
||||
insertSpecialCase(key, isPlatformSlice);
|
||||
final List<String> keys = mAccessor.getSliceKeys(isPlatformSlice);
|
||||
|
||||
assertThat(keys).containsExactly(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
|
||||
final String key = "platform_key";
|
||||
final boolean isPlatformSlice = true;
|
||||
insertSpecialCase(key, isPlatformSlice);
|
||||
final List<String> keys = mAccessor.getSliceKeys(isPlatformSlice);
|
||||
|
||||
assertThat(keys).containsExactly(key);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
insertSpecialCase(key, true);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key, boolean isPlatformSlice) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, fakeTitle);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, fakeSummary);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, fakeScreenTitle);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, fakeIcon);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, fakeFragmentClassName);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, fakeControllerName);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, FAKE_TITLE);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, FAKE_SUMMARY);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, FAKE_SCREEN_TITLE);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, FAKE_ICON);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, FAKE_FRAGMENT_NAME);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, FAKE_CONTROLLER_NAME);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.PLATFORM_SLICE, isPlatformSlice);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_TYPE, SliceData.SliceType.INTENT);
|
||||
|
||||
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
}
|
||||
|
Reference in New Issue
Block a user