Loading src/com/android/settings/slices/SliceBuilderUtils.java +1 −24 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_PLAT import android.annotation.ColorInt; import android.app.PendingIntent; import android.app.settings.SettingsEnums; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.net.Uri; Loading Loading @@ -110,17 +109,6 @@ public class SliceBuilderUtils { } } /** * @return the {@link SliceData.SliceType} for the {@param controllerClassName} and key. */ @SliceData.SliceType public static int getSliceType(Context context, String controllerClassName, String controllerKey) { BasePreferenceController controller = getPreferenceController(context, controllerClassName, controllerKey); return controller.getSliceType(); } /** * Splits the Settings Slice Uri path into its two expected components: * - intent/action Loading Loading @@ -214,17 +202,6 @@ public class SliceBuilderUtils { return ""; } public static Uri getUri(String path, boolean isPlatformSlice) { final String authority = isPlatformSlice ? SettingsSlicesContract.AUTHORITY : SettingsSliceProvider.SLICE_AUTHORITY; return new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .appendPath(path) .build(); } public static Intent buildSearchResultPageIntent(Context context, String className, String key, String screenTitle, int sourceMetricsCategory) { final Bundle args = new Bundle(); Loading Loading @@ -350,7 +327,7 @@ public class SliceBuilderUtils { .build(); } private static BasePreferenceController getPreferenceController(Context context, static BasePreferenceController getPreferenceController(Context context, String controllerClassName, String controllerKey) { try { return BasePreferenceController.createInstance(context, controllerClassName); Loading src/com/android/settings/slices/SliceDataConverter.java +19 −9 Original line number Diff line number Diff line Loading @@ -27,14 +27,17 @@ import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_UNAVAI import android.accessibilityservice.AccessibilityServiceInfo; import android.app.settings.SettingsEnums; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.net.Uri; import android.os.Bundle; import android.provider.SearchIndexableResource; import android.provider.SettingsSlicesContract; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; Loading Loading @@ -199,17 +202,24 @@ class SliceDataConverter { } final String key = bundle.getString(METADATA_KEY); final BasePreferenceController controller = SliceBuilderUtils .getPreferenceController(mContext, controllerClassName, key); // Only add pre-approved Slices available on the device. if (!controller.isSliceable() || !controller.isAvailable()) { continue; } final String title = bundle.getString(METADATA_TITLE); final String summary = bundle.getString(METADATA_SUMMARY); final int iconResId = bundle.getInt(METADATA_ICON); final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName, key); final int sliceType = controller.getSliceType(); final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG); final String unavailableSliceSubtitle = bundle.getString( METADATA_UNAVAILABLE_SLICE_SUBTITLE); final SliceData xmlSlice = new SliceData.Builder() .setKey(key) .setUri(controller.getSliceUri()) .setTitle(title) .setSummary(summary) .setIcon(iconResId) Loading @@ -221,14 +231,8 @@ class SliceDataConverter { .setUnavailableSliceSubtitle(unavailableSliceSubtitle) .build(); final BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(mContext, xmlSlice); // Only add pre-approved Slices available on the device. if (controller.isSliceable() && controller.isAvailable()) { xmlSliceData.add(xmlSlice); } } } catch (SliceData.InvalidSliceDataException e) { Log.w(TAG, "Invalid data when building SliceData for " + fragmentName, e); mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, Loading Loading @@ -294,6 +298,12 @@ class SliceDataConverter { sliceDataBuilder.setKey(flattenedName) .setTitle(title) .setUri(new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(SettingsSliceProvider.SLICE_AUTHORITY) .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION) .appendPath(flattenedName) .build()) .setIcon(iconResource) .setSliceType(SliceData.SliceType.SWITCH); try { Loading src/com/android/settings/slices/SlicesIndexer.java +1 −0 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ class SlicesIndexer implements Runnable { for (SliceData dataRow : indexData) { values = new ContentValues(); values.put(IndexColumns.KEY, dataRow.getKey()); values.put(IndexColumns.SLICE_URI, dataRow.getUri().toSafeString()); values.put(IndexColumns.TITLE, dataRow.getTitle()); values.put(IndexColumns.SUMMARY, dataRow.getSummary()); values.put(IndexColumns.SCREENTITLE, dataRow.getScreenTitle().toString()); Loading tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java +17 −15 Original line number Diff line number Diff line Loading @@ -163,6 +163,7 @@ public class NfcPreferenceControllerTest { assertThat(keys).hasSize(1); } @Test public void setChecked_True_nfcShouldEnable() { mNfcController.setChecked(true); Loading Loading @@ -256,7 +257,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_noExtra_sliceDoesntUpdate() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); Loading @@ -267,7 +269,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_turningOn_sliceDoesntUpdate() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_TURNING_ON); Loading @@ -279,7 +282,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_turningOff_sliceDoesntUpdate() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_TURNING_OFF); Loading @@ -291,7 +295,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_nfcOn_sliceUpdates() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_ON); Loading @@ -303,7 +308,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_nfcOff_sliceUpdates() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF); Loading @@ -312,8 +318,4 @@ public class NfcPreferenceControllerTest { verify(worker).updateSlice(); } private Uri getDummyUri() { return SliceBuilderUtils.getUri("action/nfc", false); } } tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java +30 −24 Original line number Diff line number Diff line Loading @@ -96,8 +96,18 @@ import java.util.Set; public class SettingsSliceProviderTest { private static final String KEY = "KEY"; private static final String INTENT_PATH = SettingsSlicesContract.PATH_SETTING_INTENT + "/" + KEY; private static final Uri INTENT_SLICE_URI = new Uri.Builder().scheme(SCHEME_CONTENT) .authority(SettingsSliceProvider.SLICE_AUTHORITY) .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT) .appendPath(KEY) .build(); private static final Uri ACTION_SLICE_URI = new Uri.Builder().scheme(SCHEME_CONTENT) .authority(SettingsSlicesContract.AUTHORITY) .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION) .appendPath(KEY) .build(); private static final String TITLE = "title"; private static final String SUMMARY = "summary"; private static final String SCREEN_TITLE = "screen title"; Loading Loading @@ -155,20 +165,18 @@ public class SettingsSliceProviderTest { @Test public void testInitialSliceReturned_emptySlice() { insertSpecialCase(KEY); final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false); Slice slice = mProvider.onBindSlice(uri); Slice slice = mProvider.onBindSlice(INTENT_SLICE_URI); assertThat(slice.getUri()).isEqualTo(uri); assertThat(slice.getUri()).isEqualTo(INTENT_SLICE_URI); assertThat(slice.getItems()).isEmpty(); } @Test public void testLoadSlice_returnsSliceFromAccessor() { insertSpecialCase(KEY); final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false); mProvider.loadSlice(uri); SliceData data = mProvider.mSliceWeakDataCache.get(uri); mProvider.loadSlice(INTENT_SLICE_URI); SliceData data = mProvider.mSliceWeakDataCache.get(INTENT_SLICE_URI); assertThat(data.getKey()).isEqualTo(KEY); assertThat(data.getTitle()).isEqualTo(TITLE); Loading @@ -177,24 +185,23 @@ public class SettingsSliceProviderTest { @Test public void loadSlice_registersIntentFilter() { insertSpecialCase(KEY); final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false); mProvider.loadSlice(uri); mProvider.loadSlice(INTENT_SLICE_URI); verify(mProvider).registerIntentToUri(eq(FakeToggleController.INTENT_FILTER), eq(uri)); verify(mProvider) .registerIntentToUri(eq(FakeToggleController.INTENT_FILTER), eq(INTENT_SLICE_URI)); } @Test public void loadSlice_registersBackgroundListener() { insertSpecialCase(KEY); final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false); mProvider.loadSlice(uri); mProvider.loadSlice(INTENT_SLICE_URI); Robolectric.flushForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); assertThat(mProvider.mPinnedWorkers.get(uri).getClass()) assertThat(mProvider.mPinnedWorkers.get(INTENT_SLICE_URI).getClass()) .isEqualTo(FakeToggleController.TestWorker.class); } Loading Loading @@ -255,27 +262,26 @@ public class SettingsSliceProviderTest { @Test public void getDescendantUris_fullActionUri_returnsSelf() { final Uri uri = SliceBuilderUtils.getUri( SettingsSlicesContract.PATH_SETTING_ACTION + "/key", true); final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri); final Collection<Uri> descendants = mProvider.onGetSliceDescendants(ACTION_SLICE_URI); assertThat(descendants).containsExactly(uri); assertThat(descendants).containsExactly(ACTION_SLICE_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); final Collection<Uri> descendants = mProvider.onGetSliceDescendants(ACTION_SLICE_URI); assertThat(descendants).containsExactly(uri); assertThat(descendants).containsExactly(ACTION_SLICE_URI); } @Test public void getDescendantUris_wrongPath_returnsEmpty() { final Uri uri = SliceBuilderUtils.getUri("invalid_path", true); final Uri uri = new Uri.Builder() .scheme(SCHEME_CONTENT) .authority(SettingsSlicesContract.AUTHORITY) .appendPath("invalid_path") .build(); final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri); Loading Loading
src/com/android/settings/slices/SliceBuilderUtils.java +1 −24 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_PLAT import android.annotation.ColorInt; import android.app.PendingIntent; import android.app.settings.SettingsEnums; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.net.Uri; Loading Loading @@ -110,17 +109,6 @@ public class SliceBuilderUtils { } } /** * @return the {@link SliceData.SliceType} for the {@param controllerClassName} and key. */ @SliceData.SliceType public static int getSliceType(Context context, String controllerClassName, String controllerKey) { BasePreferenceController controller = getPreferenceController(context, controllerClassName, controllerKey); return controller.getSliceType(); } /** * Splits the Settings Slice Uri path into its two expected components: * - intent/action Loading Loading @@ -214,17 +202,6 @@ public class SliceBuilderUtils { return ""; } public static Uri getUri(String path, boolean isPlatformSlice) { final String authority = isPlatformSlice ? SettingsSlicesContract.AUTHORITY : SettingsSliceProvider.SLICE_AUTHORITY; return new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .appendPath(path) .build(); } public static Intent buildSearchResultPageIntent(Context context, String className, String key, String screenTitle, int sourceMetricsCategory) { final Bundle args = new Bundle(); Loading Loading @@ -350,7 +327,7 @@ public class SliceBuilderUtils { .build(); } private static BasePreferenceController getPreferenceController(Context context, static BasePreferenceController getPreferenceController(Context context, String controllerClassName, String controllerKey) { try { return BasePreferenceController.createInstance(context, controllerClassName); Loading
src/com/android/settings/slices/SliceDataConverter.java +19 −9 Original line number Diff line number Diff line Loading @@ -27,14 +27,17 @@ import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_UNAVAI import android.accessibilityservice.AccessibilityServiceInfo; import android.app.settings.SettingsEnums; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.net.Uri; import android.os.Bundle; import android.provider.SearchIndexableResource; import android.provider.SettingsSlicesContract; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; Loading Loading @@ -199,17 +202,24 @@ class SliceDataConverter { } final String key = bundle.getString(METADATA_KEY); final BasePreferenceController controller = SliceBuilderUtils .getPreferenceController(mContext, controllerClassName, key); // Only add pre-approved Slices available on the device. if (!controller.isSliceable() || !controller.isAvailable()) { continue; } final String title = bundle.getString(METADATA_TITLE); final String summary = bundle.getString(METADATA_SUMMARY); final int iconResId = bundle.getInt(METADATA_ICON); final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName, key); final int sliceType = controller.getSliceType(); final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG); final String unavailableSliceSubtitle = bundle.getString( METADATA_UNAVAILABLE_SLICE_SUBTITLE); final SliceData xmlSlice = new SliceData.Builder() .setKey(key) .setUri(controller.getSliceUri()) .setTitle(title) .setSummary(summary) .setIcon(iconResId) Loading @@ -221,14 +231,8 @@ class SliceDataConverter { .setUnavailableSliceSubtitle(unavailableSliceSubtitle) .build(); final BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(mContext, xmlSlice); // Only add pre-approved Slices available on the device. if (controller.isSliceable() && controller.isAvailable()) { xmlSliceData.add(xmlSlice); } } } catch (SliceData.InvalidSliceDataException e) { Log.w(TAG, "Invalid data when building SliceData for " + fragmentName, e); mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, Loading Loading @@ -294,6 +298,12 @@ class SliceDataConverter { sliceDataBuilder.setKey(flattenedName) .setTitle(title) .setUri(new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(SettingsSliceProvider.SLICE_AUTHORITY) .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION) .appendPath(flattenedName) .build()) .setIcon(iconResource) .setSliceType(SliceData.SliceType.SWITCH); try { Loading
src/com/android/settings/slices/SlicesIndexer.java +1 −0 Original line number Diff line number Diff line Loading @@ -101,6 +101,7 @@ class SlicesIndexer implements Runnable { for (SliceData dataRow : indexData) { values = new ContentValues(); values.put(IndexColumns.KEY, dataRow.getKey()); values.put(IndexColumns.SLICE_URI, dataRow.getUri().toSafeString()); values.put(IndexColumns.TITLE, dataRow.getTitle()); values.put(IndexColumns.SUMMARY, dataRow.getSummary()); values.put(IndexColumns.SCREENTITLE, dataRow.getScreenTitle().toString()); Loading
tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java +17 −15 Original line number Diff line number Diff line Loading @@ -163,6 +163,7 @@ public class NfcPreferenceControllerTest { assertThat(keys).hasSize(1); } @Test public void setChecked_True_nfcShouldEnable() { mNfcController.setChecked(true); Loading Loading @@ -256,7 +257,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_noExtra_sliceDoesntUpdate() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); Loading @@ -267,7 +269,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_turningOn_sliceDoesntUpdate() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_TURNING_ON); Loading @@ -279,7 +282,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_turningOff_sliceDoesntUpdate() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_TURNING_OFF); Loading @@ -291,7 +295,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_nfcOn_sliceUpdates() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_ON); Loading @@ -303,7 +308,8 @@ public class NfcPreferenceControllerTest { @Test public void ncfSliceWorker_nfcBroadcast_nfcOff_sliceUpdates() { final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri())); final NfcSliceWorker worker = spy( new NfcSliceWorker(mContext, mNfcController.getSliceUri())); final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker); final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF); Loading @@ -312,8 +318,4 @@ public class NfcPreferenceControllerTest { verify(worker).updateSlice(); } private Uri getDummyUri() { return SliceBuilderUtils.getUri("action/nfc", false); } }
tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java +30 −24 Original line number Diff line number Diff line Loading @@ -96,8 +96,18 @@ import java.util.Set; public class SettingsSliceProviderTest { private static final String KEY = "KEY"; private static final String INTENT_PATH = SettingsSlicesContract.PATH_SETTING_INTENT + "/" + KEY; private static final Uri INTENT_SLICE_URI = new Uri.Builder().scheme(SCHEME_CONTENT) .authority(SettingsSliceProvider.SLICE_AUTHORITY) .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT) .appendPath(KEY) .build(); private static final Uri ACTION_SLICE_URI = new Uri.Builder().scheme(SCHEME_CONTENT) .authority(SettingsSlicesContract.AUTHORITY) .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION) .appendPath(KEY) .build(); private static final String TITLE = "title"; private static final String SUMMARY = "summary"; private static final String SCREEN_TITLE = "screen title"; Loading Loading @@ -155,20 +165,18 @@ public class SettingsSliceProviderTest { @Test public void testInitialSliceReturned_emptySlice() { insertSpecialCase(KEY); final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false); Slice slice = mProvider.onBindSlice(uri); Slice slice = mProvider.onBindSlice(INTENT_SLICE_URI); assertThat(slice.getUri()).isEqualTo(uri); assertThat(slice.getUri()).isEqualTo(INTENT_SLICE_URI); assertThat(slice.getItems()).isEmpty(); } @Test public void testLoadSlice_returnsSliceFromAccessor() { insertSpecialCase(KEY); final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false); mProvider.loadSlice(uri); SliceData data = mProvider.mSliceWeakDataCache.get(uri); mProvider.loadSlice(INTENT_SLICE_URI); SliceData data = mProvider.mSliceWeakDataCache.get(INTENT_SLICE_URI); assertThat(data.getKey()).isEqualTo(KEY); assertThat(data.getTitle()).isEqualTo(TITLE); Loading @@ -177,24 +185,23 @@ public class SettingsSliceProviderTest { @Test public void loadSlice_registersIntentFilter() { insertSpecialCase(KEY); final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false); mProvider.loadSlice(uri); mProvider.loadSlice(INTENT_SLICE_URI); verify(mProvider).registerIntentToUri(eq(FakeToggleController.INTENT_FILTER), eq(uri)); verify(mProvider) .registerIntentToUri(eq(FakeToggleController.INTENT_FILTER), eq(INTENT_SLICE_URI)); } @Test public void loadSlice_registersBackgroundListener() { insertSpecialCase(KEY); final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false); mProvider.loadSlice(uri); mProvider.loadSlice(INTENT_SLICE_URI); Robolectric.flushForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); assertThat(mProvider.mPinnedWorkers.get(uri).getClass()) assertThat(mProvider.mPinnedWorkers.get(INTENT_SLICE_URI).getClass()) .isEqualTo(FakeToggleController.TestWorker.class); } Loading Loading @@ -255,27 +262,26 @@ public class SettingsSliceProviderTest { @Test public void getDescendantUris_fullActionUri_returnsSelf() { final Uri uri = SliceBuilderUtils.getUri( SettingsSlicesContract.PATH_SETTING_ACTION + "/key", true); final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri); final Collection<Uri> descendants = mProvider.onGetSliceDescendants(ACTION_SLICE_URI); assertThat(descendants).containsExactly(uri); assertThat(descendants).containsExactly(ACTION_SLICE_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); final Collection<Uri> descendants = mProvider.onGetSliceDescendants(ACTION_SLICE_URI); assertThat(descendants).containsExactly(uri); assertThat(descendants).containsExactly(ACTION_SLICE_URI); } @Test public void getDescendantUris_wrongPath_returnsEmpty() { final Uri uri = SliceBuilderUtils.getUri("invalid_path", true); final Uri uri = new Uri.Builder() .scheme(SCHEME_CONTENT) .authority(SettingsSlicesContract.AUTHORITY) .appendPath("invalid_path") .build(); final Collection<Uri> descendants = mProvider.onGetSliceDescendants(uri); Loading