Merge "Add list-select as an inline result" into oc-dr1-dev am: e455c8f377
am: 46483a1a29
Change-Id: Ia2f55440571504c66b67276990e9fde19a1709fa
This commit is contained in:
@@ -244,7 +244,7 @@ public class CursorToSearchResultConverterTest {
|
||||
final InlineSwitchPayload newPayload = (InlineSwitchPayload) result.payload;
|
||||
final Intent rebuiltIntent = newPayload.getIntent();
|
||||
assertThat(newPayload.mSettingKey).isEqualTo(uri);
|
||||
assertThat(newPayload.mInlineType).isEqualTo(type);
|
||||
assertThat(newPayload.getType()).isEqualTo(type);
|
||||
assertThat(newPayload.mSettingSource).isEqualTo(source);
|
||||
assertThat(newPayload.isStandard()).isTrue();
|
||||
assertThat(newPayload.getAvailability()).isEqualTo(Availability.AVAILABLE);
|
||||
|
@@ -0,0 +1,107 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class InlineListPayloadTest {
|
||||
|
||||
private static final String DUMMY_SETTING = "inline_list_key";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_DataRetained() {
|
||||
final String uri = "test.com";
|
||||
final int type = ResultPayload.PayloadType.INLINE_LIST;
|
||||
final int source = ResultPayload.SettingsSource.SYSTEM;
|
||||
final String intentKey = "key";
|
||||
final String intentVal = "value";
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(intentKey, intentVal);
|
||||
|
||||
InlineListPayload payload = new InlineListPayload(uri, source,
|
||||
intent, true /* isAvailable */, 1);
|
||||
|
||||
final Intent retainedIntent = payload.getIntent();
|
||||
assertThat(payload.mSettingKey).isEqualTo(uri);
|
||||
assertThat(payload.getType()).isEqualTo(type);
|
||||
assertThat(payload.mSettingSource).isEqualTo(source);
|
||||
assertThat(payload.getAvailability()).isEqualTo(ResultPayload.Availability.AVAILABLE);
|
||||
assertThat(retainedIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelConstructor_DataRetained() {
|
||||
String uri = "test.com";
|
||||
int type = ResultPayload.PayloadType.INLINE_LIST;
|
||||
int source = ResultPayload.SettingsSource.SYSTEM;
|
||||
final String intentKey = "key";
|
||||
final String intentVal = "value";
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(intentKey, intentVal);
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.writeParcelable(intent, 0);
|
||||
parcel.writeString(uri);
|
||||
parcel.writeInt(source);
|
||||
parcel.writeInt(InlineSwitchPayload.TRUE);
|
||||
parcel.writeInt(InlineSwitchPayload.TRUE);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
InlineListPayload payload = InlineListPayload
|
||||
.CREATOR.createFromParcel(parcel);
|
||||
|
||||
final Intent builtIntent = payload.getIntent();
|
||||
assertThat(payload.mSettingKey).isEqualTo(uri);
|
||||
assertThat(payload.getType()).isEqualTo(type);
|
||||
assertThat(payload.mSettingSource).isEqualTo(source);
|
||||
assertThat(payload.getAvailability()).isEqualTo(ResultPayload.Availability.AVAILABLE);
|
||||
assertThat(builtIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputStandardization_inputDoesntChange() {
|
||||
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
||||
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
||||
3 /* numOptions */);
|
||||
int input = 2;
|
||||
|
||||
assertThat(payload.standardizeInput(input)).isEqualTo(input);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetSystem_negativeValue_throwsError() {
|
||||
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
||||
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
||||
3 /* numOptions */);
|
||||
|
||||
payload.setValue(mContext, -1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetSystem_exceedsMaxValue_throwsError() {
|
||||
int maxOptions = 4;
|
||||
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
||||
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
||||
maxOptions /* numOptions */);
|
||||
|
||||
payload.setValue(mContext, maxOptions + 1);
|
||||
}
|
||||
}
|
@@ -0,0 +1,127 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search.ResultPayload.SettingsSource;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class InlinePayloadTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private final String KEY = "key";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSecure_returnsSecureSetting() {
|
||||
InlinePayload payload = getDummyPayload(SettingsSource.SECURE);
|
||||
int currentValue = 2;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY, currentValue);
|
||||
|
||||
int newValue = payload.getValue(mContext);
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGlobal_returnsGlobalSetting() {
|
||||
InlinePayload payload = getDummyPayload(SettingsSource.GLOBAL);
|
||||
int currentValue = 2;
|
||||
Settings.Global.putInt(mContext.getContentResolver(), KEY, currentValue);
|
||||
|
||||
int newValue = payload.getValue(mContext);
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSystem_returnsSystemSetting() {
|
||||
InlinePayload payload = getDummyPayload(SettingsSource.SYSTEM);
|
||||
int currentValue = 2;
|
||||
Settings.System.putInt(mContext.getContentResolver(), KEY, currentValue);
|
||||
|
||||
int newValue = payload.getValue(mContext);
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSecure_updatesSecureSetting() {
|
||||
InlinePayload payload = getDummyPayload(SettingsSource.SECURE);
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.Secure.putInt(resolver, KEY, 0);
|
||||
|
||||
payload.setValue(mContext, newValue);
|
||||
int updatedValue = Settings.System.getInt(resolver, KEY, -1);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetGlobal_updatesGlobalSetting() {
|
||||
InlinePayload payload = getDummyPayload(SettingsSource.GLOBAL);
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.Global.putInt(resolver, KEY, 0);
|
||||
|
||||
payload.setValue(mContext, newValue);
|
||||
int updatedValue = Settings.Global.getInt(resolver, KEY, -1);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSystem_updatesSystemSetting() {
|
||||
InlinePayload payload = getDummyPayload(SettingsSource.SECURE);
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, 0);
|
||||
|
||||
payload.setValue(mContext, newValue);
|
||||
int updatedValue = Settings.System.getInt(resolver, KEY, -1);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
private InlinePayload getDummyPayload(int source) {
|
||||
return new ConcreteInlinePayload(KEY, source, null /* intent */,
|
||||
true /* isDeviceSupported */);
|
||||
}
|
||||
|
||||
class ConcreteInlinePayload extends InlinePayload {
|
||||
|
||||
public ConcreteInlinePayload(String key, @SettingsSource int source, Intent intent,
|
||||
boolean isDeviceSupported) {
|
||||
super(key, source, intent, isDeviceSupported);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int standardizeInput(int input) throws IllegalArgumentException {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
@@ -64,7 +64,7 @@ public class InlineSwitchPayloadTest {
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, 1, intent, true);
|
||||
final Intent retainedIntent = payload.getIntent();
|
||||
assertThat(payload.mSettingKey).isEqualTo(uri);
|
||||
assertThat(payload.mInlineType).isEqualTo(type);
|
||||
assertThat(payload.getType()).isEqualTo(type);
|
||||
assertThat(payload.mSettingSource).isEqualTo(source);
|
||||
assertThat(payload.isStandard()).isTrue();
|
||||
assertThat(payload.getAvailability()).isEqualTo(ResultPayload.Availability.AVAILABLE);
|
||||
@@ -80,104 +80,25 @@ public class InlineSwitchPayloadTest {
|
||||
final String intentVal = "value";
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(intentKey, intentVal);
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.writeParcelable(intent, 0);
|
||||
parcel.writeString(uri);
|
||||
parcel.writeInt(type);
|
||||
parcel.writeInt(source);
|
||||
parcel.writeInt(InlineSwitchPayload.TRUE);
|
||||
parcel.writeInt(InlineSwitchPayload.TRUE);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
InlineSwitchPayload payload = InlineSwitchPayload.CREATOR.createFromParcel(parcel);
|
||||
|
||||
final Intent builtIntent = payload.getIntent();
|
||||
assertThat(payload.mSettingKey).isEqualTo(uri);
|
||||
assertThat(payload.mInlineType).isEqualTo(type);
|
||||
assertThat(payload.getType()).isEqualTo(type);
|
||||
assertThat(payload.mSettingSource).isEqualTo(source);
|
||||
assertThat(payload.isStandard()).isTrue();
|
||||
assertThat(payload.getAvailability()).isEqualTo(Availability.AVAILABLE);
|
||||
assertThat(builtIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSecure_returnsSecureSetting() {
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SECURE,
|
||||
STANDARD_ON, null /* intent */, true);
|
||||
int currentValue = 1;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), DUMMY_SETTING, currentValue);
|
||||
|
||||
int newValue = payload.getValue(mContext);
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGlobal_returnsGlobalSetting() {
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.GLOBAL,
|
||||
STANDARD_ON, null /* intent */, true);
|
||||
int currentValue = 1;
|
||||
Settings.Global.putInt(mContext.getContentResolver(), DUMMY_SETTING, currentValue);
|
||||
|
||||
int newValue = payload.getValue(mContext);
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSystem_returnsSystemSetting() {
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
||||
STANDARD_ON, null /* intent */, true);
|
||||
int currentValue = 1;
|
||||
Settings.System.putInt(mContext.getContentResolver(), DUMMY_SETTING, currentValue);
|
||||
|
||||
int newValue = payload.getValue(mContext);
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSecure_updatesSecureSetting() {
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SECURE,
|
||||
STANDARD_ON, null /* intent */, true);
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.Secure.putInt(resolver, SCREEN_BRIGHTNESS_MODE, 0);
|
||||
|
||||
payload.setValue(mContext, newValue);
|
||||
int updatedValue = Settings.System.getInt(resolver, DUMMY_SETTING, -1);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetGlobal_updatesGlobalSetting() {
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.GLOBAL,
|
||||
STANDARD_ON, null /* intent */, true);
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.Global.putInt(resolver, SCREEN_BRIGHTNESS_MODE, 0);
|
||||
|
||||
payload.setValue(mContext, newValue);
|
||||
int updatedValue = Settings.Global.getInt(resolver, DUMMY_SETTING, -1);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSystem_updatesSystemSetting() {
|
||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
||||
STANDARD_ON, null /* intent */, true);
|
||||
int newValue = 1;
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, 0);
|
||||
|
||||
payload.setValue(mContext, newValue);
|
||||
int updatedValue = Settings.System.getInt(resolver, DUMMY_SETTING, -1);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSystem_flippedSetting_returnsFlippedValue() {
|
||||
// Stores 1s as 0s, and vis versa
|
||||
|
Reference in New Issue
Block a user