Add ResultPayload for always-on ambient display.

Bug: 62022517
Test: robotest
Change-Id: Ib4ee4d8d999e5a1f9edf34ea6068644b41fc4838
This commit is contained in:
Andrew Sapperstein
2017-07-22 16:22:49 -07:00
parent 6cd295af8a
commit 36af00bb21
2 changed files with 55 additions and 6 deletions

View File

@@ -22,13 +22,16 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.search.InlinePayload;
import com.android.settings.search.InlineSwitchPayload;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.Before;
@@ -115,4 +118,34 @@ public class AmbientDisplayAlwaysOnPreferenceControllerTest {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testPreferenceController_ProperResultPayloadType() {
assertThat(mController.getResultPayload()).isInstanceOf(InlineSwitchPayload.class);
}
@Test
@Config(shadows = ShadowSecureSettings.class)
public void testSetValue_updatesCorrectly() {
int newValue = 1;
ContentResolver resolver = mContext.getContentResolver();
Settings.Secure.putInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, 0);
((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
int updatedValue = Settings.Secure.getInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, -1);
assertThat(updatedValue).isEqualTo(newValue);
}
@Test
@Config(shadows = ShadowSecureSettings.class)
public void testGetValue_correctValueReturned() {
int currentValue = 1;
ContentResolver resolver = mContext.getContentResolver();
Settings.Secure.putInt(resolver, Settings.Secure.DOZE_ALWAYS_ON, currentValue);
int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext);
assertThat(newValue).isEqualTo(currentValue);
}
}