Merge "Remove font size & screen size setup flow instance" into tm-dev

This commit is contained in:
Menghan Li
2022-03-03 14:40:17 +00:00
committed by Android (Google) Code Review
18 changed files with 0 additions and 1012 deletions

View File

@@ -1,140 +0,0 @@
/*
* Copyright (C) 2021 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.accessibility.AccessibilityScreenSizeForSetupWizardActivity.VISION_FRAGMENT_NO;
import static com.android.settings.core.SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;
import android.content.Context;
import android.content.Intent;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.FragmentType;
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupdesign.GlifLayout;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link AccessibilityScreenSizeForSetupWizardActivity} */
@RunWith(RobolectricTestRunner.class)
public class AccessibilityScreenSizeForSetupWizardActivityTest {
private Context mContext = ApplicationProvider.getApplicationContext();
private AccessibilityScreenSizeForSetupWizardActivity setupActivity(int fragmentType) {
final Intent intent = new Intent();
intent.putExtra(VISION_FRAGMENT_NO, fragmentType);
return Robolectric.buildActivity(AccessibilityScreenSizeForSetupWizardActivity.class,
intent).create().get();
}
private AccessibilityScreenSizeForSetupWizardActivity setupActivity(int fragmentType,
int transitionType) {
final Intent intent = new Intent();
intent.putExtra(VISION_FRAGMENT_NO, fragmentType);
intent.putExtra(EXTRA_PAGE_TRANSITION_TYPE, transitionType);
return Robolectric.buildActivity(AccessibilityScreenSizeForSetupWizardActivity.class,
intent).create().get();
}
@Test
public void setupActivity_fontSizePage_returnFontSizeTitle() {
final AccessibilityScreenSizeForSetupWizardActivity activity =
setupActivity(FragmentType.FONT_SIZE, TransitionType.TRANSITION_FADE);
final GlifLayout layout = activity.findViewById(R.id.setup_wizard_layout);
assertThat(layout.getHeaderText()).isEqualTo(mContext.getText(R.string.title_font_size));
}
@Test
public void setupActivity_generateDoneButton() {
final AccessibilityScreenSizeForSetupWizardActivity activity =
setupActivity(FragmentType.FONT_SIZE, TransitionType.TRANSITION_FADE);
final GlifLayout layout = activity.findViewById(R.id.setup_wizard_layout);
final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
assertThat(mixin.getPrimaryButton().getText()).isEqualTo(mContext.getText(R.string.done));
}
@Test
public void onPause_getPendingTransitionEnterAnimationResourceId_transitionFade_should() {
final AccessibilityScreenSizeForSetupWizardActivity activity =
setupActivity(FragmentType.FONT_SIZE, TransitionType.TRANSITION_FADE);
activity.onPause();
assertThat(shadowOf(activity).getPendingTransitionEnterAnimationResourceId())
.isEqualTo(R.anim.sud_stay);
}
@Test
public void onPause_getPendingTransitionExitAnimationResourceId_transitionFade_should() {
final AccessibilityScreenSizeForSetupWizardActivity activity =
setupActivity(FragmentType.FONT_SIZE, TransitionType.TRANSITION_FADE);
activity.onPause();
assertThat(shadowOf(activity).getPendingTransitionExitAnimationResourceId())
.isEqualTo(android.R.anim.fade_out);
}
@Test
public void onPause_getPendingTransitionEnterAnimationResourceId_transitionNone_should() {
final AccessibilityScreenSizeForSetupWizardActivity activity =
setupActivity(FragmentType.FONT_SIZE);
activity.onPause();
assertThat(shadowOf(activity).getPendingTransitionEnterAnimationResourceId())
.isNotEqualTo(R.anim.sud_stay);
}
@Test
public void onPause_getPendingTransitionExitAnimationResourceId_transitionNone_should() {
final AccessibilityScreenSizeForSetupWizardActivity activity =
setupActivity(FragmentType.FONT_SIZE);
activity.onPause();
assertThat(shadowOf(activity).getPendingTransitionExitAnimationResourceId())
.isNotEqualTo(android.R.anim.fade_out);
}
@Test
public void updateHeaderLayout_displaySizePage_returnDisplaySizeTitle() {
final Intent intent = new Intent();
intent.putExtra(VISION_FRAGMENT_NO, FragmentType.SCREEN_SIZE);
intent.putExtra(EXTRA_PAGE_TRANSITION_TYPE, TransitionType.TRANSITION_FADE);
final AccessibilityScreenSizeForSetupWizardActivity activity = Robolectric.buildActivity(
AccessibilityScreenSizeForSetupWizardActivity.class, intent).get();
activity.setContentView(R.layout.accessibility_screen_size_setup_wizard);
activity.updateHeaderLayout();
final GlifLayout layout = activity.findViewById(R.id.setup_wizard_layout);
assertThat(layout.getHeaderText()).isEqualTo(mContext.getText(R.string.screen_zoom_title));
}
}

View File

@@ -16,27 +16,18 @@
package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.VISION_FRAGMENT_NO;
import static com.android.settings.accessibility.AccessibilitySettingsForSetupWizardActivity.CLASS_NAME_FONT_SIZE_SETTINGS_FOR_SUW;
import static com.google.common.truth.Truth.assertThat;
import android.content.ComponentName;
import android.content.Intent;
import androidx.test.filters.SmallTest;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.FragmentType;
import com.google.android.setupcompat.util.WizardManagerHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
@RunWith(RobolectricTestRunner.class)
@SmallTest
@@ -51,38 +42,4 @@ public class AccessibilitySettingsForSetupWizardActivityTest {
assertThat(activity.getThemeResId()).isEqualTo(R.style.GlifV3Theme_Light);
}
@Test
public void onCreate_hasFontSizeComponent_shouldGoToFontSizePreferenceDirectly() {
AccessibilitySettingsForSetupWizardActivity activity =
Robolectric.buildActivity(AccessibilitySettingsForSetupWizardActivity.class,
new Intent(Intent.ACTION_MAIN).setComponent(new ComponentName(
RuntimeEnvironment.application,
CLASS_NAME_FONT_SIZE_SETTINGS_FOR_SUW))
.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true)
.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)).get();
activity.tryLaunchFontSizeSettings();
final Intent launchIntent = Shadows.shadowOf(activity).getNextStartedActivity();
assertThat(launchIntent).isNotNull();
assertThat(launchIntent.getIntExtra(VISION_FRAGMENT_NO, -1)).isEqualTo(
FragmentType.FONT_SIZE);
assertThat(activity.isFinishing()).isTrue();
}
@Test
public void onCreate_noFontSizeComponent_shouldNotFinishCurrentActivity() {
AccessibilitySettingsForSetupWizardActivity activity =
Robolectric.buildActivity(AccessibilitySettingsForSetupWizardActivity.class,
new Intent(Intent.ACTION_MAIN)
.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true)
.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)).get();
activity.tryLaunchFontSizeSettings();
final Intent launchIntent = Shadows.shadowOf(activity).getNextStartedActivity();
assertThat(launchIntent).isNull();
assertThat(activity.isFinishing()).isFalse();
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright (C) 2021 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.accessibility.AccessibilityScreenSizeForSetupWizardActivity.VISION_FRAGMENT_NO;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;
import android.app.Activity;
import android.content.Intent;
import androidx.preference.Preference;
import com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.FragmentType;
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link FontSizePreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class FontSizePreferenceControllerTest {
private static final String TEST_KEY = "test_key";
private Activity mActivity;
private FontSizePreferenceController mController;
Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.setupActivity(Activity.class);
mController = new FontSizePreferenceController(mActivity, TEST_KEY);
mPreference = new Preference(mActivity);
mPreference.setKey(TEST_KEY);
}
@Test
public void getAvailabilityStatus_returnAvailable() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void handlePreferenceTreeClick_launchActivityWithExpectedValues() {
mController.handlePreferenceTreeClick(mPreference);
final Intent nextActivity = shadowOf(mActivity).getNextStartedActivity();
assertThat(nextActivity.getIntExtra(VISION_FRAGMENT_NO, /* defaultValue= */-1))
.isEqualTo(FragmentType.FONT_SIZE);
assertThat(nextActivity.getIntExtra(EXTRA_PAGE_TRANSITION_TYPE, /* defaultValue= */-1))
.isEqualTo(TransitionType.TRANSITION_FADE);
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright (C) 2021 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.accessibility.AccessibilityScreenSizeForSetupWizardActivity.VISION_FRAGMENT_NO;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;
import android.app.Activity;
import android.content.Intent;
import androidx.preference.Preference;
import com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.FragmentType;
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link ScreenSizePreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class ScreenSizePreferenceControllerTest {
private static final String TEST_KEY = "test_key";
private Activity mActivity;
private ScreenSizePreferenceController mController;
Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.setupActivity(Activity.class);
mController = new ScreenSizePreferenceController(mActivity, TEST_KEY);
mPreference = new Preference(mActivity);
mPreference.setKey(TEST_KEY);
}
@Test
public void getAvailabilityStatus_returnAvailable() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void handlePreferenceTreeClick_launchActivityWithExpectedValues() {
mController.handlePreferenceTreeClick(mPreference);
final Intent nextActivity = shadowOf(mActivity).getNextStartedActivity();
assertThat(nextActivity.getIntExtra(VISION_FRAGMENT_NO, /* defaultValue= */-1))
.isEqualTo(FragmentType.SCREEN_SIZE);
assertThat(nextActivity.getIntExtra(EXTRA_PAGE_TRANSITION_TYPE, /* defaultValue= */-1))
.isEqualTo(TransitionType.TRANSITION_FADE);
}
}