Merge "Support AOD in the Universal Settings API" into pi-dev am: 3025bc7c18
am: 9180cade44
Change-Id: Ic9bced3c2ec51392cdcf41c15a02adefb8031632
This commit is contained in:
@@ -17,17 +17,14 @@
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
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.search.InlinePayload;
|
||||
@@ -49,8 +46,6 @@ public class AmbientDisplayAlwaysOnPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private AmbientDisplayConfiguration mConfig;
|
||||
@Mock
|
||||
private SwitchPreference mSwitchPreference;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -64,95 +59,90 @@ public class AmbientDisplayAlwaysOnPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
mController = new AmbientDisplayAlwaysOnPreferenceController(mContext, mConfig,
|
||||
() -> {
|
||||
mCallbackInvoked = true;
|
||||
});
|
||||
mController = new AmbientDisplayAlwaysOnPreferenceController(mContext, "key");
|
||||
mController.setConfig(mConfig);
|
||||
mController.setCallback(() -> mCallbackInvoked = true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_enabled() {
|
||||
public void getAvailabilityStatus_available() {
|
||||
when(mConfig.alwaysOnAvailableForUser(anyInt())).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
AmbientDisplayAlwaysOnPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_disabled_unsupported() {
|
||||
when(mConfig.alwaysOnAvailableForUser(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
AmbientDisplayAlwaysOnPreferenceController.DISABLED_UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_enabled() {
|
||||
when(mConfig.alwaysOnEnabled(anyInt())).thenReturn(true);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
verify(mSwitchPreference).setChecked(true);
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disabled() {
|
||||
public void isChecked_disabled() {
|
||||
when(mConfig.alwaysOnEnabled(anyInt())).thenReturn(false);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
verify(mSwitchPreference).setChecked(false);
|
||||
@Test
|
||||
public void setChecked_enabled() {
|
||||
mController.setChecked(true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, Settings.Secure.DOZE_ALWAYS_ON, -1))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_disabled() {
|
||||
mController.setChecked(false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, Settings.Secure.DOZE_ALWAYS_ON, -1))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_callback() {
|
||||
assertThat(mCallbackInvoked).isFalse();
|
||||
mController.onPreferenceChange(mSwitchPreference, true);
|
||||
mController.setChecked(true);
|
||||
assertThat(mCallbackInvoked).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_enable() {
|
||||
mController.onPreferenceChange(mSwitchPreference, true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, Settings.Secure.DOZE_ALWAYS_ON, -1))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_disable() {
|
||||
mController.onPreferenceChange(mSwitchPreference, false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, Settings.Secure.DOZE_ALWAYS_ON, -1))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_available() {
|
||||
mController = spy(mController);
|
||||
doReturn(true).when(mController).alwaysOnAvailableForUser(any());
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_unavailable() {
|
||||
mController = spy(mController);
|
||||
doReturn(false).when(mController).alwaysOnAvailableForUser(any());
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceController_ProperResultPayloadType() {
|
||||
when(mConfig.alwaysOnAvailableForUser(anyInt())).thenReturn(false);
|
||||
mController = spy(mController);
|
||||
doReturn(false).when(mController).alwaysOnAvailableForUser(any());
|
||||
|
||||
assertThat(mController.getResultPayload()).isInstanceOf(InlineSwitchPayload.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValue_updatesCorrectly() {
|
||||
when(mConfig.alwaysOnAvailableForUser(anyInt())).thenReturn(false);
|
||||
mController = spy(mController);
|
||||
doReturn(false).when(mController).alwaysOnAvailableForUser(any());
|
||||
final int newValue = 1;
|
||||
Settings.Secure.putInt(mContentResolver, Settings.Secure.DOZE_ALWAYS_ON, 0 /* value */);
|
||||
|
||||
((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
|
||||
final int updatedValue = Settings.Secure.
|
||||
getInt(mContentResolver, Settings.Secure.DOZE_ALWAYS_ON, 1 /* default */);
|
||||
getInt(mContentResolver, Settings.Secure.DOZE_ALWAYS_ON, 1 /* default */);
|
||||
|
||||
assertThat(updatedValue).isEqualTo(newValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValue_correctValueReturned() {
|
||||
when(mConfig.alwaysOnAvailableForUser(anyInt())).thenReturn(false);
|
||||
mController = spy(mController);
|
||||
doReturn(false).when(mController).alwaysOnAvailableForUser(any());
|
||||
final int currentValue = 1;
|
||||
Settings.Secure.putInt(mContentResolver, Settings.Secure.DOZE_ALWAYS_ON, currentValue);
|
||||
|
||||
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.display;
|
||||
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AmbientDisplaySettingsTest {
|
||||
|
||||
private TestFragment mTestFragment;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mTestFragment = spy(new TestFragment());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAttach_shouldSetConfigAndCallback() {
|
||||
final AmbientDisplayAlwaysOnPreferenceController controller = mock(
|
||||
AmbientDisplayAlwaysOnPreferenceController.class);
|
||||
doReturn(controller).when(mTestFragment).use(
|
||||
AmbientDisplayAlwaysOnPreferenceController.class);
|
||||
|
||||
mTestFragment.onAttach(mContext);
|
||||
|
||||
verify(controller).setConfig(any());
|
||||
verify(controller).setCallback(any());
|
||||
}
|
||||
|
||||
public static class TestFragment extends AmbientDisplaySettings {
|
||||
@Override
|
||||
protected <T extends AbstractPreferenceController> T use(Class<T> clazz) {
|
||||
return super.use(clazz);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user