Merge changes I05beec7d,Iad4e9fc2
* changes: Remove "platform_slice" attribute from Settings. Use slice uri from slice index db directly.
This commit is contained in:
@@ -34,10 +34,8 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.slice.SliceManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.os.StrictMode;
|
||||
import android.provider.Settings;
|
||||
@@ -49,7 +47,6 @@ import androidx.slice.Slice;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeToggleController;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
@@ -108,13 +105,8 @@ public class SettingsSliceProviderTest {
|
||||
.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";
|
||||
private static final String FRAGMENT_NAME = "fragment name";
|
||||
private static final int ICON = R.drawable.ic_settings_accent;
|
||||
|
||||
private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private static final String PREF_CONTROLLER = FakeToggleController.class.getName();
|
||||
|
||||
private Context mContext;
|
||||
private SettingsSliceProvider mProvider;
|
||||
@@ -164,7 +156,7 @@ public class SettingsSliceProviderTest {
|
||||
|
||||
@Test
|
||||
public void testInitialSliceReturned_emptySlice() {
|
||||
insertSpecialCase(KEY);
|
||||
SliceTestUtils.insertSliceToDb(mContext, KEY);
|
||||
Slice slice = mProvider.onBindSlice(INTENT_SLICE_URI);
|
||||
|
||||
assertThat(slice.getUri()).isEqualTo(INTENT_SLICE_URI);
|
||||
@@ -173,18 +165,18 @@ public class SettingsSliceProviderTest {
|
||||
|
||||
@Test
|
||||
public void testLoadSlice_returnsSliceFromAccessor() {
|
||||
insertSpecialCase(KEY);
|
||||
SliceTestUtils.insertSliceToDb(mContext, KEY);
|
||||
|
||||
mProvider.loadSlice(INTENT_SLICE_URI);
|
||||
SliceData data = mProvider.mSliceWeakDataCache.get(INTENT_SLICE_URI);
|
||||
|
||||
assertThat(data.getKey()).isEqualTo(KEY);
|
||||
assertThat(data.getTitle()).isEqualTo(TITLE);
|
||||
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadSlice_registersIntentFilter() {
|
||||
insertSpecialCase(KEY);
|
||||
SliceTestUtils.insertSliceToDb(mContext, KEY);
|
||||
|
||||
mProvider.loadSlice(INTENT_SLICE_URI);
|
||||
|
||||
@@ -194,7 +186,7 @@ public class SettingsSliceProviderTest {
|
||||
|
||||
@Test
|
||||
public void loadSlice_registersBackgroundListener() {
|
||||
insertSpecialCase(KEY);
|
||||
SliceTestUtils.insertSliceToDb(mContext, KEY);
|
||||
|
||||
mProvider.loadSlice(INTENT_SLICE_URI);
|
||||
|
||||
@@ -210,7 +202,7 @@ public class SettingsSliceProviderTest {
|
||||
SliceData data = getDummyData();
|
||||
mProvider.mSliceWeakDataCache.put(data.getUri(), data);
|
||||
mProvider.onBindSlice(data.getUri());
|
||||
insertSpecialCase(data.getKey());
|
||||
SliceTestUtils.insertSliceToDb(mContext, data.getKey());
|
||||
|
||||
SliceData cachedData = mProvider.mSliceWeakDataCache.get(data.getUri());
|
||||
|
||||
@@ -291,7 +283,7 @@ public class SettingsSliceProviderTest {
|
||||
@Test
|
||||
public void getDescendantUris_invalidPath_returnsEmpty() {
|
||||
final String key = "platform_key";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
@@ -306,7 +298,7 @@ public class SettingsSliceProviderTest {
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
|
||||
insertSpecialCase("oem_key", false /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, "oem_key", false /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
@@ -320,7 +312,7 @@ public class SettingsSliceProviderTest {
|
||||
|
||||
@Test
|
||||
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
|
||||
insertSpecialCase("platform_key", true /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, "platform_key", true /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
@@ -335,7 +327,7 @@ public class SettingsSliceProviderTest {
|
||||
@Test
|
||||
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
|
||||
final String key = "oem_key";
|
||||
insertSpecialCase(key, false /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
@@ -358,7 +350,7 @@ public class SettingsSliceProviderTest {
|
||||
@Test
|
||||
public void getDescendantUris_oemSliceNoPath_returnsOEMUriDescendant() {
|
||||
final String key = "oem_key";
|
||||
insertSpecialCase(key, false /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
@@ -380,7 +372,7 @@ public class SettingsSliceProviderTest {
|
||||
@Test
|
||||
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
|
||||
final String key = "platform_key";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
@@ -403,7 +395,7 @@ public class SettingsSliceProviderTest {
|
||||
@Test
|
||||
public void getDescendantUris_platformSliceNoPath_returnsPlatformUriDescendant() {
|
||||
final String key = "platform_key";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.authority(SettingsSlicesContract.AUTHORITY)
|
||||
@@ -426,8 +418,8 @@ public class SettingsSliceProviderTest {
|
||||
public void getDescendantUris_noAuthorityNorPath_returnsAllUris() {
|
||||
final String platformKey = "platform_key";
|
||||
final String oemKey = "oemKey";
|
||||
insertSpecialCase(platformKey, true /* isPlatformSlice */);
|
||||
insertSpecialCase(oemKey, false /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, platformKey, true /* isPlatformSlice */);
|
||||
SliceTestUtils.insertSliceToDb(mContext, oemKey, false /* isPlatformSlice */);
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(SCHEME_CONTENT)
|
||||
.build();
|
||||
@@ -492,31 +484,6 @@ public class SettingsSliceProviderTest {
|
||||
mProvider.onSlicePinned(uri);
|
||||
}
|
||||
|
||||
@Implements(WifiScanWorker.class)
|
||||
public static class ShadowWifiScanWorker {
|
||||
private static WifiTracker mWifiTracker;
|
||||
|
||||
@Implementation
|
||||
protected void onSlicePinned() {
|
||||
mWifiTracker = mock(WifiTracker.class);
|
||||
mWifiTracker.onStart();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected void onSliceUnpinned() {
|
||||
mWifiTracker.onStop();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected void close() {
|
||||
mWifiTracker.onDestroy();
|
||||
}
|
||||
|
||||
static WifiTracker getWifiTracker() {
|
||||
return mWifiTracker;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSlicePinned_backgroundWorker_started() {
|
||||
mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI);
|
||||
@@ -563,45 +530,44 @@ public class SettingsSliceProviderTest {
|
||||
.grantSlicePermission("com.android.settings.slice_whitelist_package", uris.get(0));
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
insertSpecialCase(key, true);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key, boolean isPlatformSlice) {
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, TITLE);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, "s");
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, "s");
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, R.drawable.ic_settings_accent);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, "test");
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, PREF_CONTROLLER);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.PLATFORM_SLICE, isPlatformSlice);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_TYPE, SliceData.SliceType.INTENT);
|
||||
final SQLiteDatabase db = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
try {
|
||||
db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
|
||||
private static SliceData getDummyData() {
|
||||
return new SliceData.Builder()
|
||||
.setKey(KEY)
|
||||
.setTitle(TITLE)
|
||||
.setSummary(SUMMARY)
|
||||
.setScreenTitle(SCREEN_TITLE)
|
||||
.setIcon(ICON)
|
||||
.setFragmentName(FRAGMENT_NAME)
|
||||
.setUri(URI)
|
||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||
.setTitle(SliceTestUtils.FAKE_TITLE)
|
||||
.setSummary(SliceTestUtils.FAKE_SUMMARY)
|
||||
.setScreenTitle(SliceTestUtils.FAKE_SCREEN_TITLE)
|
||||
.setIcon(SliceTestUtils.FAKE_ICON)
|
||||
.setFragmentName(SliceTestUtils.FAKE_FRAGMENT_NAME)
|
||||
.setPreferenceControllerClassName(SliceTestUtils.FAKE_CONTROLLER_NAME)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Implements(WifiScanWorker.class)
|
||||
public static class ShadowWifiScanWorker {
|
||||
private static WifiTracker mWifiTracker;
|
||||
|
||||
@Implementation
|
||||
protected void onSlicePinned() {
|
||||
mWifiTracker = mock(WifiTracker.class);
|
||||
mWifiTracker.onStart();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected void onSliceUnpinned() {
|
||||
mWifiTracker.onStop();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected void close() {
|
||||
mWifiTracker.onDestroy();
|
||||
}
|
||||
|
||||
static WifiTracker getWifiTracker() {
|
||||
return mWifiTracker;
|
||||
}
|
||||
}
|
||||
|
||||
@Implements(value = StrictMode.class)
|
||||
public static class ShadowStrictMode {
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.search.SearchFeatureProviderImpl;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.FakeIndexProvider;
|
||||
import com.android.settings.testutils.FakeSliderController;
|
||||
import com.android.settings.testutils.FakeToggleController;
|
||||
|
||||
@@ -57,13 +56,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SliceBroadcastReceiverTest {
|
||||
|
||||
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 Class fakeControllerName = FakeToggleController.class;
|
||||
|
||||
private Context mContext;
|
||||
private SQLiteDatabase mDb;
|
||||
private SliceBroadcastReceiver mReceiver;
|
||||
@@ -90,21 +82,18 @@ public class SliceBroadcastReceiverTest {
|
||||
@Test
|
||||
public void onReceive_toggleChanged() {
|
||||
final String key = "key";
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
final Uri uri = buildUri(key);
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(key);
|
||||
final ContentResolver resolver = mock(ContentResolver.class);
|
||||
doReturn(resolver).when(mContext).getContentResolver();
|
||||
// Turn on toggle setting
|
||||
FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||
final FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||
fakeToggleController.setChecked(true);
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(uri);
|
||||
|
||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||
|
||||
@@ -128,6 +117,8 @@ public class SliceBroadcastReceiverTest {
|
||||
doReturn(resolver).when(mContext).getContentResolver();
|
||||
|
||||
final String key = "key";
|
||||
final Uri expectedUri = buildUri(key);
|
||||
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(key);
|
||||
|
||||
@@ -135,8 +126,9 @@ public class SliceBroadcastReceiverTest {
|
||||
fakeToggleController.setChecked(true);
|
||||
// Set the toggle setting update synchronously.
|
||||
fakeToggleController.setAsyncUpdate(false);
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(expectedUri);
|
||||
|
||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||
|
||||
@@ -145,12 +137,6 @@ public class SliceBroadcastReceiverTest {
|
||||
|
||||
assertThat(fakeToggleController.isChecked()).isFalse();
|
||||
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
|
||||
verify(resolver).notifyChange(expectedUri, null);
|
||||
}
|
||||
@@ -163,16 +149,11 @@ public class SliceBroadcastReceiverTest {
|
||||
|
||||
final String key = "key";
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(key);
|
||||
insertSpecialCase(AsyncToggleController.class.getName(), key);
|
||||
|
||||
FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||
fakeToggleController.setChecked(true);
|
||||
// Set the toggle setting update asynchronously.
|
||||
fakeToggleController.setAsyncUpdate(true);
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
|
||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(buildUri(key));
|
||||
|
||||
// Toggle setting
|
||||
mReceiver.onReceive(mContext, intent);
|
||||
@@ -183,26 +164,22 @@ public class SliceBroadcastReceiverTest {
|
||||
@Test
|
||||
public void onReceive_sliderChanged() {
|
||||
final String key = "key";
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
final Uri uri = buildUri(key);
|
||||
final ContentResolver resolver = mock(ContentResolver.class);
|
||||
doReturn(resolver).when(mContext).getContentResolver();
|
||||
final int position = FakeSliderController.MAX_VALUE - 1;
|
||||
final int oldPosition = FakeSliderController.MAX_VALUE;
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(FakeSliderController.class, key);
|
||||
insertSpecialCase(FakeSliderController.class.getName(), key);
|
||||
|
||||
// Set slider setting
|
||||
FakeSliderController fakeSliderController = new FakeSliderController(mContext, key);
|
||||
fakeSliderController.setSliderPosition(oldPosition);
|
||||
// Build action
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(uri);
|
||||
|
||||
assertThat(fakeSliderController.getSliderPosition()).isEqualTo(oldPosition);
|
||||
|
||||
@@ -225,12 +202,12 @@ public class SliceBroadcastReceiverTest {
|
||||
final String key = "key";
|
||||
final int position = 0;
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(FakeToggleController.class, key);
|
||||
insertSpecialCase(key);
|
||||
|
||||
// Build action
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
|
||||
// Trigger the exception.
|
||||
mReceiver.onReceive(mContext, intent);
|
||||
@@ -272,29 +249,25 @@ public class SliceBroadcastReceiverTest {
|
||||
|
||||
// Insert Fake Toggle into Database
|
||||
final String key = "key";
|
||||
final Uri expectedUri = buildUri(key);
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(FakeToggleController.class, key);
|
||||
insertSpecialCase(key);
|
||||
|
||||
// Turn on toggle setting
|
||||
final FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||
fakeToggleController.setChecked(true);
|
||||
|
||||
// Build Action
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(expectedUri);
|
||||
|
||||
// Trigger Slice change
|
||||
mReceiver.onReceive(mContext, intent);
|
||||
|
||||
// Check the value is the same and the Uri has been notified.
|
||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
verify(resolver).notifyChange(eq(expectedUri), eq(null));
|
||||
verify(resolver).notifyChange(expectedUri, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -310,47 +283,65 @@ public class SliceBroadcastReceiverTest {
|
||||
|
||||
// Insert Fake Slider into Database
|
||||
final String key = "key";
|
||||
final Uri expectedUri = buildUri(key);
|
||||
|
||||
final int position = FakeSliderController.MAX_VALUE - 1;
|
||||
final int oldPosition = FakeSliderController.MAX_VALUE;
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(FakeSliderController.class, key);
|
||||
insertSpecialCase(FakeSliderController.class.getName(), key);
|
||||
|
||||
// Set slider setting
|
||||
final FakeSliderController fakeSliderController = new FakeSliderController(mContext, key);
|
||||
fakeSliderController.setSliderPosition(oldPosition);
|
||||
|
||||
// Build action
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(expectedUri);
|
||||
|
||||
// Trigger Slice change
|
||||
mReceiver.onReceive(mContext, intent);
|
||||
|
||||
// Check position is the same and the Uri has been notified.
|
||||
assertThat(fakeSliderController.getSliderPosition()).isEqualTo(oldPosition);
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
verify(resolver).notifyChange(eq(expectedUri), eq(null));
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
insertSpecialCase(SliceTestUtils.FAKE_CONTROLLER_NAME, key);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String controllerClass, String key) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, SliceTestUtils.FAKE_TITLE);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, SliceTestUtils.FAKE_SUMMARY);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, SliceTestUtils.FAKE_ICON);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, controllerClass);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_URI, buildUri(key).toSafeString());
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
}
|
||||
|
||||
private static Uri buildUri(String key) {
|
||||
return new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
verify(resolver).notifyChange(eq(expectedUri), eq(null));
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
insertSpecialCase(fakeControllerName, key);
|
||||
}
|
||||
public static class AsyncToggleController extends FakeToggleController {
|
||||
public AsyncToggleController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(Class controllerClass, String key) {
|
||||
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, controllerClass.getName());
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
@Override
|
||||
public boolean hasAsyncUpdate() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,6 @@ public class SliceDataConverterTest {
|
||||
assertThat(fakeSlice.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_CLASSNAME);
|
||||
assertThat(fakeSlice.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
assertThat(fakeSlice.getSliceType()).isEqualTo(SliceData.SliceType.SLIDER);
|
||||
assertThat(fakeSlice.isPlatformDefined()).isTrue(); // from XML
|
||||
assertThat(fakeSlice.getUnavailableSliceSubtitle()).isEqualTo(
|
||||
"subtitleOfUnavailableSlice"); // from XML
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ public class SliceDataTest {
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
||||
private final int SLICE_TYPE = SliceData.SliceType.SWITCH;
|
||||
private final boolean IS_PLATFORM_DEFINED = true;
|
||||
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
||||
|
||||
@Test
|
||||
@@ -53,7 +52,6 @@ public class SliceDataTest {
|
||||
.setUri(URI)
|
||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||
.setSliceType(SLICE_TYPE)
|
||||
.setPlatformDefined(IS_PLATFORM_DEFINED)
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
SliceData data = builder.build();
|
||||
@@ -68,7 +66,6 @@ public class SliceDataTest {
|
||||
assertThat(data.getUri()).isEqualTo(URI);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(PREF_CONTROLLER);
|
||||
assertThat(data.getSliceType()).isEqualTo(SLICE_TYPE);
|
||||
assertThat(data.isPlatformDefined()).isEqualTo(IS_PLATFORM_DEFINED);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
|
||||
import com.android.settings.testutils.FakeIndexProvider;
|
||||
import com.android.settings.testutils.FakeToggleController;
|
||||
|
||||
class SliceTestUtils {
|
||||
|
||||
public static final String FAKE_TITLE = "title";
|
||||
public static final String FAKE_SUMMARY = "summary";
|
||||
public static final String FAKE_SCREEN_TITLE = "screen_title";
|
||||
public static final String FAKE_KEYWORDS = "a, b, c";
|
||||
public static final int FAKE_ICON = 1234;
|
||||
public static final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName();
|
||||
public static final String FAKE_CONTROLLER_NAME = FakeToggleController.class.getName();
|
||||
|
||||
|
||||
public static void insertSliceToDb(Context context, String key) {
|
||||
insertSliceToDb(context, key, true /* isPlatformSlice */);
|
||||
}
|
||||
|
||||
public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice) {
|
||||
insertSliceToDb(context, key, isPlatformSlice, null /*customizedUnavailableSliceSubtitle*/);
|
||||
}
|
||||
|
||||
public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice,
|
||||
String customizedUnavailableSliceSubtitle) {
|
||||
final SQLiteDatabase db = SlicesDatabaseHelper.getInstance(context).getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_URI,
|
||||
new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(isPlatformSlice
|
||||
? SettingsSlicesContract.AUTHORITY
|
||||
: SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build().toSafeString());
|
||||
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.KEYWORDS, FAKE_KEYWORDS);
|
||||
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.SLICE_TYPE, SliceData.SliceType.INTENT);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
customizedUnavailableSliceSubtitle);
|
||||
|
||||
db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import com.android.settings.search.SearchFeatureProvider;
|
||||
@@ -62,16 +63,8 @@ import java.util.Locale;
|
||||
ShadowBluetoothAdapter.class, ShadowLockPatternUtils.class})
|
||||
public class SlicesDatabaseAccessorTest {
|
||||
|
||||
private final String FAKE_TITLE = "title";
|
||||
private final String FAKE_SUMMARY = "summary";
|
||||
private final String FAKE_SCREEN_TITLE = "screen_title";
|
||||
private final String FAKE_KEYWORDS = "a, b, c";
|
||||
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;
|
||||
private SlicesDatabaseAccessor mAccessor;
|
||||
|
||||
@Before
|
||||
@@ -79,7 +72,6 @@ public class SlicesDatabaseAccessorTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
ShadowUserManager.getShadow().setIsAdminUser(true);
|
||||
mAccessor = spy(new SlicesDatabaseAccessor(mContext));
|
||||
mDb = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||
SlicesDatabaseHelper.getInstance(mContext).setIndexedState();
|
||||
|
||||
// Register the fake a11y Service
|
||||
@@ -96,39 +88,39 @@ public class SlicesDatabaseAccessorTest {
|
||||
@Test
|
||||
public void testGetSliceDataFromKey_validKey_validSliceReturned() {
|
||||
String key = "key";
|
||||
insertSpecialCase(key);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key);
|
||||
|
||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||
|
||||
assertThat(data.getKey()).isEqualTo(key);
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSliceDataFromKey_allowDynamicSummary_validSliceReturned() {
|
||||
String key = "key";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */,
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
|
||||
null /* customizedUnavailableSliceSubtitle */);
|
||||
|
||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||
|
||||
assertThat(data.getKey()).isEqualTo(key);
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@@ -141,7 +133,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
@Test
|
||||
public void testGetSliceFromUri_validUri_validSliceReturned() {
|
||||
final String key = "key";
|
||||
insertSpecialCase(key);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key);
|
||||
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
@@ -153,14 +145,14 @@ public class SlicesDatabaseAccessorTest {
|
||||
SliceData data = mAccessor.getSliceDataFromUri(uri);
|
||||
|
||||
assertThat(data.getKey()).isEqualTo(key);
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isEqualTo(uri);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@@ -177,9 +169,8 @@ public class SlicesDatabaseAccessorTest {
|
||||
@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);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
|
||||
final List<Uri> keys = mAccessor.getSliceUris(SettingsSlicesContract.AUTHORITY);
|
||||
|
||||
assertThat(keys).isEmpty();
|
||||
}
|
||||
@@ -187,9 +178,8 @@ public class SlicesDatabaseAccessorTest {
|
||||
@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);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||
final List<Uri> keys = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
|
||||
|
||||
assertThat(keys).isEmpty();
|
||||
}
|
||||
@@ -197,21 +187,21 @@ public class SlicesDatabaseAccessorTest {
|
||||
@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);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
|
||||
final List<Uri> keys = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
|
||||
|
||||
assertThat(keys).containsExactly(key);
|
||||
assertThat(keys).containsExactly(
|
||||
Uri.parse("content://com.android.settings.slices/action/oem_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);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||
final List<Uri> keys = mAccessor.getSliceUris(SettingsSlicesContract.AUTHORITY);
|
||||
|
||||
assertThat(keys).containsExactly(key);
|
||||
assertThat(keys).containsExactly(
|
||||
Uri.parse("content://android.settings.slices/action/platform_key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -220,7 +210,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
// Force new indexing
|
||||
Locale.setDefault(new Locale("ca"));
|
||||
final SearchFeatureProvider provider = new SearchFeatureProviderImpl();
|
||||
final SlicesFeatureProvider sliceProvider = spy(new SlicesFeatureProviderImpl());
|
||||
final SlicesFeatureProvider sliceProvider = new SlicesFeatureProviderImpl();
|
||||
final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest();
|
||||
factory.searchFeatureProvider = provider;
|
||||
factory.slicesFeatureProvider = sliceProvider;
|
||||
@@ -230,7 +220,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
FakeIndexProvider.class);
|
||||
|
||||
final SlicesDatabaseAccessor accessor = new SlicesDatabaseAccessor(mContext);
|
||||
final List<String> keys = accessor.getSliceKeys(true);
|
||||
final List<Uri> keys = accessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
|
||||
|
||||
assertThat(keys).isNotEmpty();
|
||||
}
|
||||
@@ -238,20 +228,20 @@ public class SlicesDatabaseAccessorTest {
|
||||
@Test
|
||||
public void testGetSliceDataFromKey_defaultUnavailableSlice_validSliceReturned() {
|
||||
String key = "key";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */,
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
|
||||
null /* customizedUnavailableSliceSubtitle */);
|
||||
|
||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||
|
||||
assertThat(data.getKey()).isEqualTo(key);
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isNull();
|
||||
}
|
||||
|
||||
@@ -259,49 +249,22 @@ public class SlicesDatabaseAccessorTest {
|
||||
public void testGetSliceDataFromKey_customizeSubtitleOfUnavailableSlice_validSliceReturned() {
|
||||
String key = "key";
|
||||
String subtitle = "subtitle";
|
||||
insertSpecialCase(key, true /* isPlatformSlice */, subtitle);
|
||||
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */, subtitle);
|
||||
|
||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||
|
||||
assertThat(data.getKey()).isEqualTo(key);
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(subtitle);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
insertSpecialCase(key, true);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key, boolean isPlatformSlice) {
|
||||
insertSpecialCase(key, isPlatformSlice, null /*customizedUnavailableSliceSubtitle*/);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key, boolean isPlatformSlice,
|
||||
String customizedUnavailableSliceSubtitle) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||
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.KEYWORDS, FAKE_KEYWORDS);
|
||||
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);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
customizedUnavailableSliceSubtitle);
|
||||
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
}
|
||||
|
||||
@Implements(ApplicationPackageManager.class)
|
||||
public static class ShadowApplicationPackageManager extends
|
||||
org.robolectric.shadows.ShadowApplicationPackageManager {
|
||||
|
||||
@@ -73,7 +73,6 @@ public class SlicesDatabaseHelperTest {
|
||||
IndexColumns.ICON_RESOURCE,
|
||||
IndexColumns.FRAGMENT,
|
||||
IndexColumns.CONTROLLER,
|
||||
IndexColumns.PLATFORM_SLICE,
|
||||
IndexColumns.SLICE_TYPE,
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
};
|
||||
|
||||
@@ -52,7 +52,6 @@ public class SlicesIndexerTest {
|
||||
private final int ICON = 1234; // I declare a thumb war
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
||||
private final boolean PLATFORM_DEFINED = true;
|
||||
private final int SLICE_TYPE = SliceData.SliceType.SLIDER;
|
||||
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
||||
|
||||
@@ -136,9 +135,6 @@ public class SlicesIndexerTest {
|
||||
assertThat(
|
||||
cursor.getString(cursor.getColumnIndex(IndexColumns.CONTROLLER)))
|
||||
.isEqualTo(PREF_CONTROLLER);
|
||||
assertThat(cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.PLATFORM_SLICE)))
|
||||
.isEqualTo(1 /* true */);
|
||||
assertThat(cursor.getInt(cursor.getColumnIndex(IndexColumns.SLICE_TYPE)))
|
||||
.isEqualTo(SLICE_TYPE);
|
||||
assertThat(cursor.getString(
|
||||
@@ -176,7 +172,6 @@ public class SlicesIndexerTest {
|
||||
.setIcon(ICON)
|
||||
.setUri(URI)
|
||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||
.setPlatformDefined(PLATFORM_DEFINED)
|
||||
.setSliceType(SLICE_TYPE)
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class FakeToggleController extends TogglePreferenceController {
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.System.getInt(mContext.getContentResolver(),
|
||||
SETTING_KEY, OFF) == ON;
|
||||
SETTING_KEY, OFF) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,7 +103,7 @@ public class FakeToggleController extends TogglePreferenceController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user