Merge "Don't show quick settings tooltip if the user is in the Setup Wizard, since the user can't access the Quick Settings Panel." into main

This commit is contained in:
Chun-Ku Lin
2023-11-16 03:03:57 +00:00
committed by Android (Google) Code Review
9 changed files with 100 additions and 6 deletions

View File

@@ -26,31 +26,39 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.view.LayoutInflater;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import androidx.fragment.app.testing.EmptyFragmentActivity;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.LabeledSeekBarPreference;
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
import com.google.android.setupcompat.util.WizardManagerHelper;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.LooperMode;
@@ -64,10 +72,16 @@ import org.robolectric.shadows.ShadowApplication;
@LooperMode(LooperMode.Mode.LEGACY)
@Config(shadows = {ShadowInteractionJankMonitor.class})
public class PreviewSizeSeekBarControllerTest {
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@Rule
public ActivityScenarioRule<EmptyFragmentActivity> rule =
new ActivityScenarioRule<>(EmptyFragmentActivity.class);
private static final String FONT_SIZE_KEY = "font_size";
private static final String KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow";
@Spy
private final Context mContext = ApplicationProvider.getApplicationContext();
private Activity mContext;
private PreviewSizeSeekBarController mSeekBarController;
private FontSizeData mFontSizeData;
private LabeledSeekBarPreference mSeekBarPreference;
@@ -91,7 +105,9 @@ public class PreviewSizeSeekBarControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowInteractionJankMonitor.reset();
rule.getScenario().onActivity(activity -> mContext = activity);
mContext.setTheme(androidx.appcompat.R.style.Theme_AppCompat);
mFragment = spy(new TestFragment());
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
@@ -196,6 +212,24 @@ public class PreviewSizeSeekBarControllerTest {
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
@Test
@RequiresFlagsEnabled(Flags.FLAG_REMOVE_QS_TOOLTIP_IN_SUW)
public void onProgressChanged_inSuw_toolTipShouldNotShown() {
Intent intent = mContext.getIntent();
intent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true);
mContext.setIntent(intent);
mSeekBarController.displayPreference(mPreferenceScreen);
// Simulate changing the progress for the first time
int newProgress = (mSeekBarPreference.getProgress() != 0) ? 0 : mSeekBarPreference.getMax();
mSeekBarPreference.setProgress(newProgress);
mSeekBarPreference.onProgressChanged(new SeekBar(mContext),
newProgress,
/* fromUser= */ false);
assertThat(getLatestPopupWindow()).isNull();
}
@Test
public void onProgressChanged_tooltipViewHasBeenShown_notShowTooltipView() {
mSeekBarController.displayPreference(mPreferenceScreen);

View File

@@ -60,6 +60,8 @@ import com.android.settings.flags.Flags;
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settingslib.widget.TopIntroPreference;
import com.google.android.setupcompat.util.WizardManagerHelper;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -301,6 +303,20 @@ public class ToggleFeaturePreferenceFragmentTest {
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
@Test
@RequiresFlagsEnabled(com.android.settings.accessibility.Flags.FLAG_REMOVE_QS_TOOLTIP_IN_SUW)
@Config(shadows = ShadowFragment.class)
public void onPreferenceToggledOnEnabledService_inSuw_toolTipViewShouldNotShow() {
Intent suwIntent = new Intent();
suwIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true);
when(mActivity.getIntent()).thenReturn(suwIntent);
mFragment.onPreferenceToggled(
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
assertThat(getLatestPopupWindow()).isNull();
}
@Test
@Config(shadows = ShadowFragment.class)
public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() {