Commit 1b65f305 authored by Wenyu Fu's avatar Wenyu Fu Committed by Commit Bot

[HomepagePromo] PromoCard MVC component

Build a standard promo card component that could be used in different
area.

Bug: 1068831
Change-Id: I8f557c602109abfbe5736e82afad7bfea262d236
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2141136
Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759071}
parent 97ae0bdd
...@@ -54,6 +54,10 @@ android_library("java") { ...@@ -54,6 +54,10 @@ android_library("java") {
"java/src/org/chromium/components/browser_ui/widget/listmenu/ListMenuItemAdapter.java", "java/src/org/chromium/components/browser_ui/widget/listmenu/ListMenuItemAdapter.java",
"java/src/org/chromium/components/browser_ui/widget/listmenu/ListMenuItemProperties.java", "java/src/org/chromium/components/browser_ui/widget/listmenu/ListMenuItemProperties.java",
"java/src/org/chromium/components/browser_ui/widget/listmenu/ListMenuItemViewBinder.java", "java/src/org/chromium/components/browser_ui/widget/listmenu/ListMenuItemViewBinder.java",
"java/src/org/chromium/components/browser_ui/widget/promo/PromoCardCoordinator.java",
"java/src/org/chromium/components/browser_ui/widget/promo/PromoCardProperties.java",
"java/src/org/chromium/components/browser_ui/widget/promo/PromoCardView.java",
"java/src/org/chromium/components/browser_ui/widget/promo/PromoCardViewBinder.java",
"java/src/org/chromium/components/browser_ui/widget/scrim/ScrimCoordinator.java", "java/src/org/chromium/components/browser_ui/widget/scrim/ScrimCoordinator.java",
"java/src/org/chromium/components/browser_ui/widget/scrim/ScrimMediator.java", "java/src/org/chromium/components/browser_ui/widget/scrim/ScrimMediator.java",
"java/src/org/chromium/components/browser_ui/widget/scrim/ScrimProperties.java", "java/src/org/chromium/components/browser_ui/widget/scrim/ScrimProperties.java",
...@@ -146,6 +150,7 @@ android_resources("java_resources") { ...@@ -146,6 +150,7 @@ android_resources("java_resources") {
"java/res/layout/modern_list_item_view.xml", "java/res/layout/modern_list_item_view.xml",
"java/res/layout/more_progress_button.xml", "java/res/layout/more_progress_button.xml",
"java/res/layout/number_roll_view.xml", "java/res/layout/number_roll_view.xml",
"java/res/layout/promo_card_view.xml",
"java/res/layout/promo_dialog_layout.xml", "java/res/layout/promo_dialog_layout.xml",
"java/res/layout/radio_button_layout_element.xml", "java/res/layout/radio_button_layout_element.xml",
"java/res/layout/radio_button_with_description.xml", "java/res/layout/radio_button_with_description.xml",
...@@ -198,6 +203,8 @@ android_library("javatests") { ...@@ -198,6 +203,8 @@ android_library("javatests") {
"java/src/org/chromium/components/browser_ui/widget/WrappingLayoutTest.java", "java/src/org/chromium/components/browser_ui/widget/WrappingLayoutTest.java",
"java/src/org/chromium/components/browser_ui/widget/highlight/ViewHighlighterTest.java", "java/src/org/chromium/components/browser_ui/widget/highlight/ViewHighlighterTest.java",
"java/src/org/chromium/components/browser_ui/widget/listmenu/ListMenuRenderTest.java", "java/src/org/chromium/components/browser_ui/widget/listmenu/ListMenuRenderTest.java",
"java/src/org/chromium/components/browser_ui/widget/promo/PromoCardCoordinatorTest.java",
"java/src/org/chromium/components/browser_ui/widget/promo/PromoCardViewRenderTest.java",
"java/src/org/chromium/components/browser_ui/widget/scrim/ScrimTest.java", "java/src/org/chromium/components/browser_ui/widget/scrim/ScrimTest.java",
] ]
deps = [ deps = [
...@@ -228,6 +235,7 @@ android_resources("java_test_resources") { ...@@ -228,6 +235,7 @@ android_resources("java_test_resources") {
"test/java/res/drawable-xhdpi/promo_dialog_test_drawable.png", "test/java/res/drawable-xhdpi/promo_dialog_test_drawable.png",
"test/java/res/drawable-xxhdpi/promo_dialog_test_drawable.png", "test/java/res/drawable-xxhdpi/promo_dialog_test_drawable.png",
"test/java/res/drawable-xxxhdpi/promo_dialog_test_drawable.png", "test/java/res/drawable-xxxhdpi/promo_dialog_test_drawable.png",
"test/java/res/drawable/logo_avatar_anonymous.xml",
"test/java/res/drawable/promo_dialog_test_vector.xml", "test/java/res/drawable/promo_dialog_test_vector.xml",
"test/java/res/layout/dual_control_test_layout.xml", "test/java/res/layout/dual_control_test_layout.xml",
"test/java/res/layout/radio_button_render_test.xml", "test/java/res/layout/radio_button_render_test.xml",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<org.chromium.components.browser_ui.widget.promo.PromoCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="@drawable/hairline_border_card_background"
android:padding="@dimen/promo_padding">
<!-- Promo Header-->
<FrameLayout
android:id="@+id/promo_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/promo_header_margin_vertical">
<ImageView
android:id="@+id/promo_image"
android:layout_width="@dimen/promo_image_size"
android:layout_height="@dimen/promo_image_size"
android:layout_gravity="center"
android:scaleType="fitCenter"
tools:ignore="ContentDescription" />
<org.chromium.ui.widget.ChromeImageButton
android:id="@+id/promo_close_button"
android:layout_width="@dimen/promo_close_btn_size"
android:layout_height="@dimen/promo_close_btn_size"
android:layout_gravity="top|end"
android:contentDescription="@string/close"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter"
android:src="@drawable/btn_close"
app:tint="@color/default_icon_color" />
</FrameLayout>
<org.chromium.ui.widget.TextViewWithLeading
android:id="@+id/promo_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/promo_title_margin_vertical"
android:layout_marginEnd="@dimen/promo_description_margin_horizontal"
android:layout_marginStart="@dimen/promo_description_margin_horizontal"
android:gravity="center"
android:textAppearance="@style/TextAppearance.TextLarge.Primary"
android:layout_below="@+id/promo_header"
app:leading="@dimen/text_size_large_leading"/>
<org.chromium.ui.widget.TextViewWithLeading
android:id="@+id/promo_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/promo_description_margin_vertical"
android:layout_marginEnd="@dimen/promo_description_margin_horizontal"
android:layout_marginStart="@dimen/promo_description_margin_horizontal"
android:layout_below="@+id/promo_title"
android:gravity="center"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary"
app:leading="@dimen/text_size_small_leading" />
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/promo_primary_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/promo_buttons_margin_horizontal"
android:layout_marginStart="@dimen/promo_buttons_margin_horizontal"
android:ellipsize="end"
android:singleLine="true"
android:layout_below="@+id/description"
style="@style/FilledButton.Flat" />
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/promo_secondary_button"
style="@style/TextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/promo_buttons_margin_horizontal"
android:layout_marginStart="@dimen/promo_buttons_margin_horizontal"
android:ellipsize="end"
android:singleLine="true"
android:layout_below="@+id/primary_button"/>
</org.chromium.components.browser_ui.widget.promo.PromoCardView>
...@@ -62,6 +62,16 @@ ...@@ -62,6 +62,16 @@
24dp is needed to completely round the corners. --> 24dp is needed to completely round the corners. -->
<dimen name="modern_toolbar_background_corner_radius">24dp</dimen> <dimen name="modern_toolbar_background_corner_radius">24dp</dimen>
<!-- Promo cards dimensions -->
<dimen name="promo_image_size">24dp</dimen>
<dimen name="promo_padding">16dp</dimen>
<dimen name="promo_header_margin_vertical">8dp</dimen>
<dimen name="promo_close_btn_size">24dp</dimen>
<dimen name="promo_title_margin_vertical">8dp</dimen>
<dimen name="promo_description_margin_horizontal">8dp</dimen>
<dimen name="promo_description_margin_vertical">16dp</dimen>
<dimen name="promo_buttons_margin_horizontal">8dp</dimen>
<!-- TextBubble dimensions --> <!-- TextBubble dimensions -->
<dimen name="text_bubble_margin">4dp</dimen> <dimen name="text_bubble_margin">4dp</dimen>
<dimen name="text_bubble_corner_radius">8dp</dimen> <dimen name="text_bubble_corner_radius">8dp</dimen>
......
...@@ -84,5 +84,4 @@ ...@@ -84,5 +84,4 @@
<item name="android:windowEnterAnimation">@anim/textbubble_in</item> <item name="android:windowEnterAnimation">@anim/textbubble_in</item>
<item name="android:windowExitAnimation">@anim/textbubble_out</item> <item name="android:windowExitAnimation">@anim/textbubble_out</item>
</style> </style>
</resources> </resources>
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.browser_ui.widget.promo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import org.chromium.components.browser_ui.widget.R;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
/**
* PromoCard Coordinator that owns the view and the model change processor. Client will need to
* create another layer of controller to own this coordinator, and pass in the {@link PropertyModel}
* to initialize the view.
*/
public class PromoCardCoordinator {
private PromoCardView mPromoCardView;
private PropertyModelChangeProcessor mModelChangeProcessor;
private String mFeatureName;
/**
* Create the Coordinator of PromoCard that owns the view and the change process.
* @param context Context used to create the view.
* @param model {@link PropertyModel} built with {@link PromoCardProperties}.
* @param featureName Name of the feature of this promo. Will be used to create keys for
* SharedPreference.
*/
public PromoCardCoordinator(Context context, PropertyModel model, String featureName) {
mPromoCardView = (PromoCardView) LayoutInflater.from(context).inflate(
R.layout.promo_card_view, null, false);
mModelChangeProcessor = PropertyModelChangeProcessor.create(
model, mPromoCardView, new PromoCardViewBinder());
mFeatureName = featureName;
}
/**
* Destroy the PromoCard component and release the PropertyModelChangeProcessor.
*/
public void destroy() {
mModelChangeProcessor.destroy();
}
/**
* @return {@link PromoCardView} held by this promo component.
*/
public View getView() {
return mPromoCardView;
}
/**
* @return Name of the feature this promo is representing.
*/
public String getFeatureName() {
return mFeatureName;
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.browser_ui.widget.promo;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.view.View;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.components.browser_ui.widget.test.R;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.modelutil.PropertyModel;
/**
* Basic test for creating, using the promo component with {@link PromoCardCoordinator}.
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class PromoCardCoordinatorTest {
private Context mContext;
private PropertyModel mModel;
private PromoCardCoordinator mPromoCardCoordinator;
private PromoCardView mView;
@Before
public void setUp() {
mContext = InstrumentationRegistry.getInstrumentation().getContext();
mModel = new PropertyModel.Builder(PromoCardProperties.ALL_KEYS).build();
mPromoCardCoordinator = new PromoCardCoordinator(mContext, mModel, "test-feature");
mView = (PromoCardView) mPromoCardCoordinator.getView();
Assert.assertNotNull("PromoCardView is null", mView);
}
@Test
@SmallTest
public void testTextImageBinding() {
final Drawable testImage =
mContext.getResources().getDrawable(R.drawable.logo_avatar_anonymous);
final String titleString = "Some string for title";
final String testString = "Some test string";
final String primaryButtonString = "Primary button string";
final String secondaryButtonString = "Secondary button string";
TestThreadUtils.runOnUiThreadBlocking(() -> {
mModel.set(PromoCardProperties.TITLE, titleString);
mModel.set(PromoCardProperties.DESCRIPTION, testString);
mModel.set(PromoCardProperties.IMAGE, testImage);
mModel.set(PromoCardProperties.PRIMARY_BUTTON_TEXT, primaryButtonString);
mModel.set(PromoCardProperties.SECONDARY_BUTTON_TEXT, secondaryButtonString);
});
Assert.assertEquals(
"Promo image drawable is different.", testImage, mView.mPromoImage.getDrawable());
Assert.assertEquals(
"Promo title is different.", titleString, mView.mTitle.getText().toString());
Assert.assertEquals("Promo description is different.", testString,
mView.mDescription.getText().toString());
Assert.assertEquals("Promo primary button text is different.", primaryButtonString,
mView.mPrimaryButton.getText().toString());
Assert.assertEquals("Promo secondary button text is different.", secondaryButtonString,
mView.mSecondaryButton.getText().toString());
// Change the description again
final String testString2 = "Some other test string.";
TestThreadUtils.runOnUiThreadBlocking(
() -> { mModel.set(PromoCardProperties.DESCRIPTION, testString2); });
Assert.assertEquals(testString2, mView.mDescription.getText().toString());
}
@Test
@SmallTest
public void testChangeVisibility() {
Assert.assertEquals(mView.getVisibility(), View.VISIBLE);
Assert.assertEquals(mView.mSecondaryButton.getVisibility(), View.VISIBLE);
// Hide the secondary button
TestThreadUtils.runOnUiThreadBlocking(
() -> { mModel.set(PromoCardProperties.SECONDARY_BUTTON_VISIBLE, false); });
Assert.assertEquals("Secondary button is still visible.", View.GONE,
mView.mSecondaryButton.getVisibility());
}
@Test
@SmallTest
public void testActionBinding() throws Exception {
final CallbackHelper primaryClickCallback = new CallbackHelper();
final CallbackHelper secondaryClickCallback = new CallbackHelper();
final CallbackHelper dismissClickCallback = new CallbackHelper();
mModel.set(PromoCardProperties.PRIMARY_BUTTON_CALLBACK,
(v) -> primaryClickCallback.notifyCalled());
mModel.set(PromoCardProperties.SECONDARY_BUTTON_CALLBACK,
(v) -> secondaryClickCallback.notifyCalled());
mModel.set(PromoCardProperties.CLOSE_BUTTON_CALLBACK,
(v) -> dismissClickCallback.notifyCalled());
TestThreadUtils.runOnUiThreadBlocking(() -> mView.mPrimaryButton.performClick());
primaryClickCallback.waitForCallback("Primary button callback is never called.", 0);
Assert.assertEquals(
"Primary button should be clicked once.", 1, primaryClickCallback.getCallCount());
TestThreadUtils.runOnUiThreadBlocking(() -> mView.mSecondaryButton.performClick());
secondaryClickCallback.waitForCallback("Secondary button callback is never called.", 0);
Assert.assertEquals("Secondary button should be clicked once.", 1,
secondaryClickCallback.getCallCount());
TestThreadUtils.runOnUiThreadBlocking(() -> mView.mDismissButton.performClick());
dismissClickCallback.waitForCallback("Close button callback is never called.", 0);
Assert.assertEquals(
"Dismissed button should be clicked once.", 1, dismissClickCallback.getCallCount());
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.browser_ui.widget.promo;
import android.graphics.drawable.Drawable;
import android.view.View;
import org.chromium.base.Callback;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableBooleanPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey;
/**
* Properties for PromoCardView.
*/
public class PromoCardProperties {
// Visible related properties
public static final WritableBooleanPropertyKey SECONDARY_BUTTON_VISIBLE =
new WritableBooleanPropertyKey();
// View related properties
public static final WritableObjectPropertyKey<Drawable> IMAGE =
new WritableObjectPropertyKey<>();
public static final WritableObjectPropertyKey<String> TITLE = new WritableObjectPropertyKey<>();
public static final WritableObjectPropertyKey<String> DESCRIPTION =
new WritableObjectPropertyKey<>();
public static final WritableObjectPropertyKey<String> PRIMARY_BUTTON_TEXT =
new WritableObjectPropertyKey<>();
public static final WritableObjectPropertyKey<String> SECONDARY_BUTTON_TEXT =
new WritableObjectPropertyKey<>();
// Callback related properties
public static final WritableObjectPropertyKey<Callback<View>> PRIMARY_BUTTON_CALLBACK =
new WritableObjectPropertyKey<>();
public static final WritableObjectPropertyKey<Callback<View>> SECONDARY_BUTTON_CALLBACK =
new WritableObjectPropertyKey<>();
public static final WritableObjectPropertyKey<Callback<View>> CLOSE_BUTTON_CALLBACK =
new WritableObjectPropertyKey<>();
/**
* All the property keys needed to create the model for {@link PromoCardView}.
*/
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {SECONDARY_BUTTON_VISIBLE, IMAGE,
TITLE, DESCRIPTION, PRIMARY_BUTTON_TEXT, SECONDARY_BUTTON_TEXT, PRIMARY_BUTTON_CALLBACK,
SECONDARY_BUTTON_CALLBACK, CLOSE_BUTTON_CALLBACK};
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.browser_ui.widget.promo;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import org.chromium.components.browser_ui.widget.R;
import org.chromium.ui.widget.ButtonCompat;
import org.chromium.ui.widget.ChromeImageButton;
/**
* A promo card view that contains an image view in the top center, a block of short description,
* two button compat and a close button.
*/
class PromoCardView extends LinearLayout {
ImageView mPromoImage;
TextView mTitle;
TextView mDescription;
ButtonCompat mPrimaryButton;
ChromeImageButton mDismissButton;
ButtonCompat mSecondaryButton;
public PromoCardView(Context context) {
this(context, null);
}
public PromoCardView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
// Find members
mPromoImage = findViewById(R.id.promo_image);
mTitle = findViewById(R.id.promo_title);
mDescription = findViewById(R.id.promo_description);
mPrimaryButton = findViewById(R.id.promo_primary_button);
mDismissButton = findViewById(R.id.promo_close_button);
mSecondaryButton = findViewById(R.id.promo_secondary_button);
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.browser_ui.widget.promo;
import android.view.View;
import org.chromium.base.Callback;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
/**
* View binder than binds the promo view with the property model.
*/
class PromoCardViewBinder
implements PropertyModelChangeProcessor
.ViewBinder<PropertyModel, PromoCardView, PropertyKey> {
@Override
public void bind(PropertyModel model, PromoCardView view, PropertyKey propertyKey) {
if (propertyKey == PromoCardProperties.IMAGE) {
view.mPromoImage.setImageDrawable(model.get(PromoCardProperties.IMAGE));
} else if (propertyKey == PromoCardProperties.TITLE) {
view.mTitle.setText(model.get(PromoCardProperties.TITLE));
} else if (propertyKey == PromoCardProperties.DESCRIPTION) {
view.mDescription.setText(model.get(PromoCardProperties.DESCRIPTION));
} else if (propertyKey == PromoCardProperties.PRIMARY_BUTTON_TEXT) {
view.mPrimaryButton.setText(model.get(PromoCardProperties.PRIMARY_BUTTON_TEXT));
} else if (propertyKey == PromoCardProperties.SECONDARY_BUTTON_TEXT) {
view.mSecondaryButton.setText(model.get(PromoCardProperties.SECONDARY_BUTTON_TEXT));
// Visibility properties
} else if (propertyKey == PromoCardProperties.SECONDARY_BUTTON_VISIBLE) {
view.mSecondaryButton.setVisibility(
model.get(PromoCardProperties.SECONDARY_BUTTON_VISIBLE) ? View.VISIBLE
: View.GONE);
// Callback properties
} else if (propertyKey == PromoCardProperties.PRIMARY_BUTTON_CALLBACK) {
Callback<View> callback = model.get(PromoCardProperties.PRIMARY_BUTTON_CALLBACK);
view.mPrimaryButton.setOnClickListener(callback::onResult);
} else if (propertyKey == PromoCardProperties.SECONDARY_BUTTON_CALLBACK) {
Callback<View> callback = model.get(PromoCardProperties.SECONDARY_BUTTON_CALLBACK);
view.mSecondaryButton.setOnClickListener(callback::onResult);
} else if (propertyKey == PromoCardProperties.CLOSE_BUTTON_CALLBACK) {
Callback<View> callback = model.get(PromoCardProperties.CLOSE_BUTTON_CALLBACK);
view.mDismissButton.setOnClickListener(callback::onResult);
}
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.browser_ui.widget.promo;
import android.app.Activity;
import android.support.test.filters.SmallTest;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.params.BaseJUnit4RunnerDelegate;
import org.chromium.base.test.params.ParameterAnnotations.ClassParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.components.browser_ui.widget.test.R;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.test.util.DummyUiActivityTestCase;
import org.chromium.ui.test.util.NightModeTestUtils;
import org.chromium.ui.test.util.RenderTestRule;
import org.chromium.ui.widget.ButtonCompat;
import java.util.List;
/**
* Render test for {@link PromoCardView}.
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
public class PromoCardViewRenderTest extends DummyUiActivityTestCase {
@ClassParameter
private static List<ParameterSet> sClassParams =
new NightModeTestUtils.NightModeParams().getParameters();
@Rule
public RenderTestRule mRenderTestRule =
new RenderTestRule("chrome/test/data/android/render_tests");
public PromoCardViewRenderTest(boolean nightModeEnabled) {
NightModeTestUtils.setUpNightModeForDummyUiActivity(nightModeEnabled);
mRenderTestRule.setNightModeEnabled(nightModeEnabled);
}
private PromoCardCoordinator mPromoCardCoordinator;
private PropertyModel mModel;
@Override
public void setUpTest() throws Exception {
super.setUpTest();
Activity activity = getActivity();
mModel =
new PropertyModel.Builder(PromoCardProperties.ALL_KEYS)
.with(PromoCardProperties.IMAGE, activity, R.drawable.logo_avatar_anonymous)
.with(PromoCardProperties.TITLE, "Title for Promo Card.")
.with(PromoCardProperties.DESCRIPTION, "Description for Promo Card.")
.with(PromoCardProperties.PRIMARY_BUTTON_TEXT, "Primary button")
.with(PromoCardProperties.SECONDARY_BUTTON_TEXT, "Secondary button")
.build();
mPromoCardCoordinator = new PromoCardCoordinator(activity, mModel, "render-test");
TestThreadUtils.runOnUiThreadBlocking(() -> {
// Set the content and add the promo card into the window
LinearLayout content = new LinearLayout(activity);
activity.setContentView(content);
content.addView(mPromoCardCoordinator.getView(),
new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
});
}
@Test
@SmallTest
@Feature({"RenderTest"})
public void testDefault() throws Exception {
mRenderTestRule.render(mPromoCardCoordinator.getView(), "promo_card_default");
}
@Test
@SmallTest
@Feature({"RenderTest"})
public void testHideSecondaryButton() throws Exception {
mModel.set(PromoCardProperties.SECONDARY_BUTTON_VISIBLE, false);
CriteriaHelper.pollUiThread(Criteria.equals(View.GONE, () -> {
ButtonCompat secondaryButton =
mPromoCardCoordinator.getView().findViewById(R.id.promo_secondary_button);
return secondaryButton.getVisibility();
}));
mRenderTestRule.render(mPromoCardCoordinator.getView(), "promo_card_secondary_hidden");
}
}
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:targetApi="21"
android:width="40dp"
android:height="40dp"
android:viewportWidth="192"
android:viewportHeight="192">
<path
android:fillColor="#E0E0E0"
android:pathData="M96,0C43.01,0,0,43.01,0,96s43.01,96,96,96s96-43.01,96-96S148.99,0,96,0z" />
<path
android:fillColor="#BDBDBD"
android:pathData="M96,85.09c13.28,0,24-10.72,24-24c0-13.28-10.72-24-24-24s-24,10.72-24,24
C72,74.37,82.72,85.09,96,85.09z" />
<path
android:fillColor="#BDBDBD"
android:pathData="M96,99.27c-29.33,0-52.36,14.18-52.36,27.27c11.09,17.06,30.51,28.36,52.36,28.36
s41.27-11.3,52.36-28.36C148.36,113.45,125.33,99.27,96,99.27z" />
<path
android:pathData="M 0 0 H 192 V 192 H 0 V 0 Z" />
</vector>
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