Handle special case slices
Create a handler for any slice that doesn't include anything from a PreferenceController. Test: robotests Change-Id: If23947152d61877537d0cac6240e96b9ab977bce Bug: 80263568
This commit is contained in:
@@ -109,6 +109,7 @@ public class SettingsSliceProviderTest {
|
||||
mProvider.mSliceWeakDataCache = new HashMap<>();
|
||||
mProvider.mSliceDataCache = new HashMap<>();
|
||||
mProvider.mSlicesDatabaseAccessor = new SlicesDatabaseAccessor(mContext);
|
||||
mProvider.mCustomSliceManager = new CustomSliceManager(mContext);
|
||||
when(mProvider.getContext()).thenReturn(mContext);
|
||||
|
||||
mDb = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||
|
@@ -18,12 +18,15 @@
|
||||
package com.android.settings.slices;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.slice.Slice;
|
||||
import android.content.ContentResolver;
|
||||
@@ -82,6 +85,8 @@ public class SliceBroadcastReceiverTest {
|
||||
mSearchFeatureProvider = new SearchFeatureProviderImpl();
|
||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mFakeFeatureFactory.searchFeatureProvider = mSearchFeatureProvider;
|
||||
when(mFakeFeatureFactory.slicesFeatureProvider.getCustomSliceManager(any()))
|
||||
.thenReturn(new CustomSliceManager(mContext));
|
||||
mLoggingNameArgumentCatpor = ArgumentCaptor.forClass(Pair.class);
|
||||
mLoggingValueArgumentCatpor = ArgumentCaptor.forClass(Pair.class);
|
||||
}
|
||||
|
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.slices;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.Uri;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class SpecialCaseSliceManagerTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private CustomSliceManager mCustomSliceManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mCustomSliceManager = spy(new CustomSliceManager(mContext));
|
||||
mCustomSliceManager.mUriMap.clear();
|
||||
mCustomSliceManager.mUriMap.put(FakeSliceable.URI, FakeSliceable.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSliceableFromUri_returnsCorrectObject() {
|
||||
final CustomSliceable sliceable = mCustomSliceManager.getSliceableFromUri(
|
||||
FakeSliceable.URI);
|
||||
|
||||
assertThat(sliceable).isInstanceOf(FakeSliceable.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSliceableFromIntentAction_returnsCorrectObject() {
|
||||
final CustomSliceable sliceable =
|
||||
mCustomSliceManager.getSliceableFromIntentAction(FakeSliceable.URI.toString());
|
||||
|
||||
assertThat(sliceable).isInstanceOf(FakeSliceable.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValidUri_validUri_returnsTrue() {
|
||||
final boolean isValidUri = mCustomSliceManager.isValidUri(FakeSliceable.URI);
|
||||
|
||||
assertThat(isValidUri).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValidUri_invalidUri_returnsFalse() {
|
||||
final boolean isValidUri = mCustomSliceManager.isValidUri(null);
|
||||
|
||||
assertThat(isValidUri).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValidAction_validActions_returnsTrue() {
|
||||
final boolean isValidAction =
|
||||
mCustomSliceManager.isValidAction(FakeSliceable.URI.toString());
|
||||
|
||||
assertThat(isValidAction).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValidAction_invalidAction_returnsFalse() {
|
||||
final boolean isValidAction = mCustomSliceManager.isValidAction("action");
|
||||
|
||||
assertThat(isValidAction).isFalse();
|
||||
}
|
||||
|
||||
static class FakeSliceable implements CustomSliceable {
|
||||
|
||||
static final String KEY = "magic key of khazad dum";
|
||||
|
||||
static final Uri URI = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(KEY)
|
||||
.build();
|
||||
|
||||
static final Slice SLICE = new Slice.Builder(URI).build();
|
||||
|
||||
static boolean backingData = false;
|
||||
|
||||
public FakeSliceable(Context context) {}
|
||||
|
||||
@Override
|
||||
public Slice getSlice(Context context) {
|
||||
return SLICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getUri() {
|
||||
return URI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotifyChange(Intent intent) {
|
||||
backingData = !backingData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntentFilter getIntentFilter() {
|
||||
return new IntentFilter();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user