Commit 5d8bf3e0 authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Add integration tests for step progress bar

This adds integration tests for the new step progress bar.
It also adds disabling of animations.

Bug: b/158750294
Change-Id: I6c49d5768dbcc4ce57f5ce5c3801931ec9207744
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2275440
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarLuca Hunkeler <hluca@google.com>
Cr-Commit-Position: refs/heads/master@{#784030}
parent ad854104
......@@ -259,6 +259,7 @@ android_library("test_java") {
"javatests/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantOverlayUiTest.java",
"javatests/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantPasswordManagerIntegrationTest.java",
"javatests/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantPersonalDataManagerTest.java",
"javatests/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantProgressBarIntegrationTest.java",
"javatests/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantPromptNavigationIntegrationTest.java",
"javatests/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantTextUtilsTest.java",
"javatests/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantUiTest.java",
......
......@@ -25,4 +25,6 @@ public class AssistantTagsForTesting {
public static final String VERTICAL_EXPANDER_CHEVRON = "chevron";
public static final String COLLECT_USER_DATA_CHOICE_LIST = "choicelist";
public static final String RECYCLER_VIEW_TAG = "recycler_view";
public static final String PROGRESSBAR_ICON_TAG = "progress_icon_%d";
public static final String PROGRESSBAR_LINE_TAG = "progress_line_%d";
}
......@@ -66,6 +66,7 @@ class AssistantHeaderViewBinder
void disableAnimations(boolean disable) {
mProgressBar.disableAnimations(disable);
mStepProgressBar.disableAnimations(disable);
// Hiding the animated poodle seems to be the easiest way to disable its animation since
// {@link LogoView#setAnimationEnabled(boolean)} is private.
mPoodle.getView().setVisibility(View.INVISIBLE);
......@@ -102,6 +103,8 @@ class AssistantHeaderViewBinder
} else if (AssistantHeaderModel.STEP_PROGRESS_BAR_ICONS == propertyKey) {
view.mStepProgressBar.setSteps(model.get(AssistantHeaderModel.STEP_PROGRESS_BAR_ICONS));
view.mStepProgressBar.setError(model.get(AssistantHeaderModel.PROGRESS_BAR_ERROR));
view.mStepProgressBar.disableAnimations(
model.get(AssistantHeaderModel.DISABLE_ANIMATIONS_FOR_TESTING));
} else if (AssistantHeaderModel.SPIN_POODLE == propertyKey) {
view.mPoodle.setSpinEnabled(model.get(AssistantHeaderModel.SPIN_POODLE));
} else if (AssistantHeaderModel.FEEDBACK_BUTTON_CALLBACK == propertyKey) {
......
......@@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.autofill_assistant.AssistantTagsForTesting;
import org.chromium.chrome.browser.autofill_assistant.drawable.AssistantDrawableIcon;
import org.chromium.chrome.browser.autofill_assistant.generic_ui.AssistantDrawable;
import org.chromium.components.browser_ui.widget.animation.Interpolators;
......@@ -24,6 +25,7 @@ import org.chromium.ui.widget.ChromeImageView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* Handles construction and state changes on a progress bar with steps.
......@@ -42,21 +44,31 @@ public class AssistantStepProgressBar {
private static final int COLOR_LIST = R.color.blue_when_enabled;
private static final int ERROR_COLOR_LIST = R.color.default_red;
private final RelativeLayout mView;
private final Context mContext;
private final View mPulsor;
private final ChromeImageView mIcon;
private final ValueAnimator mPulseAnimation;
private boolean mShouldRunAnimation;
private boolean mDisableAnimations;
IconViewHolder(ViewGroup view, Context context) {
mContext = context;
RelativeLayout container = addContainer(view, mContext);
mPulsor = addPulsor(container, mContext);
mIcon = addIcon(container, mContext);
mView = addContainer(view, mContext);
mPulsor = addPulsor(mView, mContext);
mIcon = addIcon(mView, mContext);
mPulseAnimation = createPulseAnimation();
}
void setTag(String tag) {
mView.setTag(tag);
}
void disableAnimations(boolean disable) {
mDisableAnimations = disable;
}
private RelativeLayout addContainer(ViewGroup view, Context context) {
RelativeLayout container = new RelativeLayout(context);
view.addView(container);
......@@ -151,6 +163,11 @@ public class AssistantStepProgressBar {
}
void startEnabledAnimation() {
if (mDisableAnimations) {
setEnabled(true);
return;
}
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.setStartDelay(ANIMATION_DELAY_MS);
animator.setDuration(ICON_ENABLED_ANIMATION_DURATION_MS);
......@@ -186,6 +203,10 @@ public class AssistantStepProgressBar {
}
void startPulsingAnimation(boolean delayed) {
if (mDisableAnimations) {
return;
}
mShouldRunAnimation = true;
mPulseAnimation.setStartDelay(delayed
? ANIMATION_DELAY_MS + ICON_ENABLED_ANIMATION_DURATION_MS
......@@ -206,15 +227,26 @@ public class AssistantStepProgressBar {
}
private static class LineViewHolder {
private final LinearLayout mView;
private final View mLineForeground;
private boolean mDisableAnimations;
LineViewHolder(ViewGroup view, Context context) {
LinearLayout mainContainer = addMainContainer(view, context);
RelativeLayout relativeContainer = addRelativeContainer(mainContainer, context);
mView = addMainContainer(view, context);
RelativeLayout relativeContainer = addRelativeContainer(mView, context);
addBackgroundLine(relativeContainer, context);
mLineForeground = addForegroundLine(relativeContainer, context);
}
void setTag(String tag) {
mView.setTag(tag);
}
void disableAnimations(boolean disable) {
mDisableAnimations = disable;
}
private LinearLayout addMainContainer(ViewGroup view, Context context) {
LinearLayout container = new LinearLayout(context);
view.addView(container);
......@@ -265,6 +297,11 @@ public class AssistantStepProgressBar {
}
void startAnimation() {
if (mDisableAnimations) {
setEnabled(true);
return;
}
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.setStartDelay(ANIMATION_DELAY_MS + ICON_ENABLED_ANIMATION_DURATION_MS);
animator.setDuration(LINE_ANIMATION_DURATION_MS);
......@@ -321,8 +358,12 @@ public class AssistantStepProgressBar {
for (int i = 0; i < mNumberOfSteps; ++i) {
mIcons[i] = new IconViewHolder(mView, mView.getContext());
mIcons[i].setIcon(icons.get(i));
mIcons[i].setTag(String.format(
Locale.getDefault(), AssistantTagsForTesting.PROGRESSBAR_ICON_TAG, i));
if (i < mNumberOfSteps - 1) {
mLines[i] = new LineViewHolder(mView, mView.getContext());
mLines[i].setTag(String.format(
Locale.getDefault(), AssistantTagsForTesting.PROGRESSBAR_LINE_TAG, i));
}
}
}
......@@ -331,8 +372,17 @@ public class AssistantStepProgressBar {
mView.setVisibility(visible ? View.VISIBLE : View.GONE);
}
public void disableAnimations(boolean disable) {
for (IconViewHolder icon : mIcons) {
icon.disableAnimations(disable);
}
for (LineViewHolder line : mLines) {
line.disableAnimations(disable);
}
}
public void setActiveStep(int step) {
assert step >= 0 && step < mNumberOfSteps;
assert step >= 0 && step <= mNumberOfSteps;
assert step >= mCurrentStep;
if (step == mCurrentStep) {
return;
......
......@@ -1149,12 +1149,12 @@ message ShowProgressBarProto {
// will be capped to 100, values below 0 will be capped to 0 by the client.
int32 progress = 6;
// Value between 0 and |N - 1| (where N is the size of the initial
// |step_icons|) indicating the current state the flow is in,
// marking all previous steps as active. Setting the value to 0 will mark
// only the first step as active, up to |N - 1|, which marks everything up
// to the final step as active.
// If this is used over |progress| the step progress bar will be used.
// Value between 0 and |N| (where N is the size of the initial
// |step_icons|) indicating the current step the flow is in, marking
// all previous steps as complete. The active step will not be marked as
// complete but instead be marked as active with a pulsating animation.
// Setting the value to |N| will mark all steps as complete with no step
// being active anymore.
int32 active_step = 8;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment