From ccdb949cc92febc9bb978f1a9210f39658948f4d Mon Sep 17 00:00:00 2001 From: Chun-Ku Lin Date: Fri, 13 Oct 2023 02:38:30 +0000 Subject: [PATCH] Fix ToggleScreenMagnificationPreferenceFragmentTest **Root cause** ShadowFragment makes the test using an empty implementation of onCreate, hence the test execution throws SuperNotCalledException. ShadowFragment was accidentally added to this test when migrate to the latest Robolectric. Removing ShadowFragment in the config fixes the test. Fix: 300158627 Test: atest ToggleScreenMagnificationPreferenceFragmentTest Change-Id: I8782ac11a93c5f89b781dcca1713968ed18802cf --- ...enMagnificationPreferenceFragmentTest.java | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java index 72e9b547724..f0b2fbe33f1 100644 --- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java @@ -57,7 +57,6 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.google.common.truth.Correspondence; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -78,7 +77,6 @@ import java.util.List; ShadowUserManager.class, ShadowStorageManager.class, ShadowSettings.ShadowSecure.class, - com.android.settings.testutils.shadow.ShadowFragment.class, }) public class ToggleScreenMagnificationPreferenceFragmentTest { @@ -101,7 +99,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { private static final String KEY_FOLLOW_TYPING = Settings.Secure.ACCESSIBILITY_MAGNIFICATION_FOLLOW_TYPING_ENABLED; - private FragmentController mFragController; private Context mContext; private Resources mSpyResources; @@ -109,6 +106,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Before public void setUpTestFragment() { + mContext = ApplicationProvider.getApplicationContext(); // Set up the fragment that support window magnification feature @@ -130,7 +128,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void onResume_defaultStateForFollowingTyping_switchPreferenceShouldReturnTrue() { setKeyFollowTypingEnabled(true); @@ -144,7 +141,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void onResume_disableFollowingTyping_switchPreferenceShouldReturnFalse() { setKeyFollowTypingEnabled(false); @@ -158,7 +154,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void onResume_haveRegisterToSpecificUris() { ShadowContentResolver shadowContentResolver = Shadows.shadowOf( mContext.getContentResolver()); @@ -187,7 +182,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void hasValueInSettings_putValue_hasValue() { setMagnificationTripleTapEnabled(/* enabled= */ true); @@ -196,7 +190,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void optInAllValuesToSettings_optInValue_haveMatchString() { int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.TRIPLETAP; @@ -210,7 +203,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void optInAllValuesToSettings_existOtherValue_optInValue_haveMatchString() { putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, PLACEHOLDER_COMPONENT_NAME.flattenToString()); @@ -222,7 +214,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void optInAllValuesToSettings_software_sizeValueIsNull_putLargeSizeValue() { ShadowSettings.ShadowSecure.reset(); @@ -236,7 +227,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void optInAllValuesToSettings_software_sizeValueIsNotNull_sizeValueIsNotChanged() { for (int size : new int[] {FloatingMenuSizePreferenceController.Size.LARGE, FloatingMenuSizePreferenceController.Size.SMALL}) { @@ -255,7 +245,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void optInAllValuesToSettings_hardware_sizeValueIsNotChanged() { for (int size : new int[] {FloatingMenuSizePreferenceController.Size.UNKNOWN, FloatingMenuSizePreferenceController.Size.LARGE, @@ -274,7 +263,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void optInAllValuesToSettings_tripletap_sizeValueIsNotChanged() { for (int size : new int[] {FloatingMenuSizePreferenceController.Size.UNKNOWN, FloatingMenuSizePreferenceController.Size.LARGE, @@ -293,7 +281,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void optOutAllValuesToSettings_optOutValue_emptyString() { putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME); putStringIntoSettings(HARDWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME); @@ -310,7 +297,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void optOutValueFromSettings_existOtherValue_optOutValue_haveMatchString() { putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, PLACEHOLDER_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME); @@ -328,7 +314,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void updateShortcutPreferenceData_assignDefaultValueToVariable() { mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); @@ -341,7 +326,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void updateShortcutPreferenceData_hasValueInSettings_assignToVariable() { putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME); setMagnificationTripleTapEnabled(/* enabled= */ true); @@ -355,7 +339,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void updateShortcutPreferenceData_hasValueInSharedPreference_assignToVariable() { final PreferredShortcut tripleTapShortcut = new PreferredShortcut( MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.TRIPLETAP); @@ -370,7 +353,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void setupMagnificationEditShortcutDialog_shortcutPreferenceOff_checkboxIsEmptyValue() { ToggleScreenMagnificationPreferenceFragment fragment = mFragController.create(R.id.main_content, /* bundle= */ @@ -386,7 +368,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void setupMagnificationEditShortcutDialog_shortcutPreferenceOn_checkboxIsSavedValue() { ToggleScreenMagnificationPreferenceFragment fragment = mFragController.create(R.id.main_content, /* bundle= */ @@ -407,7 +388,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void restoreValueFromSavedInstanceState_assignToVariable() { final Bundle fragmentState = createFragmentSavedInstanceState( UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP); @@ -429,7 +409,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void onCreateView_magnificationAreaNotSupported_settingsPreferenceIsNull() { setWindowMagnificationSupported( /* magnificationAreaSupported= */ false, @@ -441,7 +420,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void onCreateView_windowMagnificationNotSupported_settingsPreferenceIsNull() { setWindowMagnificationSupported( /* magnificationAreaSupported= */ true, @@ -453,7 +431,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void onCreateView_setDialogDelegateAndAddTheControllerToLifeCycleObserver() { Correspondence instanceOf = Correspondence.transforming( observer -> (observer instanceof MagnificationModePreferenceController), @@ -471,7 +448,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void onCreateDialog_setDialogDelegate_invokeDialogDelegate() { ToggleScreenMagnificationPreferenceFragment fragment = mFragController.create( @@ -488,7 +464,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void getMetricsCategory_returnsCorrectCategory() { ToggleScreenMagnificationPreferenceFragment fragment = mFragController.create( @@ -499,7 +474,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void getHelpResource_returnsCorrectHelpResource() { ToggleScreenMagnificationPreferenceFragment fragment = mFragController.create( @@ -509,7 +483,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void onProcessArguments_defaultArgumentUnavailable_shouldSetDefaultArguments() { ToggleScreenMagnificationPreferenceFragment fragment = mFragController.create( @@ -524,7 +497,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void getSummary_magnificationEnabled_returnShortcutOnWithSummary() { setMagnificationTripleTapEnabled(true); @@ -535,7 +507,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { } @Test - @Ignore public void getSummary_magnificationDisabled_returnShortcutOffWithSummary() { setMagnificationTripleTapEnabled(false);