MagnificationPreferenceFragment use DashboardFragment

- Move preference related logic to Controller
- Add settings:controller in xml file

Bug: 73899467
Test: manual
Test: make RunSettingsRoboTests

Change-Id: I3eaccc617c4408f50110bf1f5df3482f491f7393
Signed-off-by: rafftsai <rafftsai@android.com>
This commit is contained in:
rafftsai
2018-03-28 16:07:24 +08:00
committed by Fan Zhang
parent e35e00712c
commit 807506b166
8 changed files with 393 additions and 101 deletions

View File

@@ -0,0 +1,80 @@
/*
* 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.accessibility;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
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 MagnificationGesturesPreferenceControllerTest {
private Context mContext;
private MagnificationGesturesPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new MagnificationGesturesPreferenceController(mContext, "pref_key");
mPreference = new Preference(mContext);
mController.updateState(mPreference);
}
@Test
public void isAlwaysAvailable() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void updateState_shouldRefreshSummary() {
Settings.System.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 1);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.accessibility_feature_state_on));
Settings.System.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.accessibility_feature_state_off));
}
@Test
public void updateState_shouldRefreshSummarySuw() {
mController.setIsFromSUW(true);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.
accessibility_screen_magnification_short_summary));
}
}

View File

@@ -0,0 +1,123 @@
/*
* 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.accessibility;
import static com.android.settings.search.ResultPayload.Availability.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
@RunWith(SettingsRobolectricTestRunner.class)
public class MagnificationNavbarPreferenceControllerTest {
private Context mContext;
private MagnificationNavbarPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new MagnificationNavbarPreferenceController(mContext, "test_key");
mPreference = new Preference(mContext);
mController.updateState(mPreference);
}
@After
public void tearDown() {
ShadowMagnificationPreferenceFragment.reset();
}
@Test
@Config(shadows = ShadowMagnificationPreferenceFragment.class)
public void isAvailable_unsupported_shouldNotBeAvailable() {
ShadowMagnificationPreferenceFragment.setApplicable(false);
assertThat(mController.getAvailabilityStatus())
.isNotEqualTo(AVAILABLE);
}
@Test
@Config(shadows = ShadowMagnificationPreferenceFragment.class)
public void isAvailable_supported_shouldBeAvailable() {
ShadowMagnificationPreferenceFragment.setApplicable(true);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(AVAILABLE);
}
@Test
public void updateState_shouldRefreshSummary() {
Settings.System.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 1);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getText(R.string.accessibility_feature_state_on));
Settings.System.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getText(R.string.accessibility_feature_state_off));
}
@Test
public void updateState_shouldRefreshSummarySuw() {
mController.setIsFromSUW(true);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.
accessibility_screen_magnification_navbar_short_summary));
}
@Implements(MagnificationPreferenceFragment.class)
public static class ShadowMagnificationPreferenceFragment {
private static boolean sIsApplicable;
@Resetter
static void reset() {
sIsApplicable = false;
}
@Implementation
static boolean isApplicable(Resources res) {
return sIsApplicable;
}
static void setApplicable(boolean applicable) {
sIsApplicable = applicable;
}
}
}