Commit fddbc779 authored by John Mellor's avatar John Mellor Committed by Commit Bot

Revert "Render snippets in ArticleSnippetsTest in isolation"

This reverts commit ab640662.

Reason for revert: ArticleSnippetsTest has failed consistently
on KitKat Tablet Tester since this landed. Specifically the
following tests are failing:
  ArticleSnippetsTest#testDownloadSuggestion__ChromeHomeEnabled
  ArticleSnippetsTest#testSigninPromo__ChromeHomeEnabled
  ArticleSnippetsTest#testSnippetAppearance__ChromeHomeEnabled

Additionally, many other test suites that follow
chrome_public_test_apk started failing when this landed; not
sure if that's related.

Original change's description:
> Render snippets in ArticleSnippetsTest in isolation
> 
> Remove the "snippets" render that shows all cards together, because
> multiple, non-article sections are not realistic in the modern design
> anymore.
> 
> Rebaseline other renders:
> * Use relative timestamp instead of Jan 17, 1970
> * Use only single-card backgrounds for pre-modern cards
> * Update modern card background color after https://crrev.com/497799
> * Update pre-modern text color after https://crrev.com/500684
> 
> Also move card contents in the modern layout except for the rounded
> corners into a RelativeLayout, to avoid a circular dependency between
> the height of the containing layout and the position of the bottom
> corner (see https://developer.android.com/reference/android/widget/RelativeLayout.html).
> 
> Bug: 757735
> Change-Id: I81add3d5bdd8ffec61b9e8aa2ff3a9caa44ccf91
> Reviewed-on: https://chromium-review.googlesource.com/628562
> Commit-Queue: Bernhard Bauer <bauerb@chromium.org>
> Reviewed-by: Sami Kyöstilä <skyostil@chromium.org>
> Reviewed-by: Juan Antonio Navarro Pérez <perezju@chromium.org>
> Reviewed-by: Peter Conn <peconn@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#500975}

TBR=bauerb@chromium.org,skyostil@chromium.org,perezju@chromium.org,peconn@chromium.org

Change-Id: Iedb4e042448a8e4c8090d8af5fbdbb6e2f19a6b7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 757735
Reviewed-on: https://chromium-review.googlesource.com/663382Reviewed-by: default avatarJohn Mellor <johnme@chromium.org>
Commit-Queue: John Mellor <johnme@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501269}
parent d95a5c1b
......@@ -32,7 +32,7 @@ In particular, ~ at the start of a string means it's a regex.
-->
<Bug pattern="BC_UNCONFIRMED_CAST" />
<!-- Ignore unused public rules and implementations thereof in instrumentation tests -->
<!-- Ignore unused public Rule and RuleChain in instrumentation tests -->
<Match>
<Class name="~.*\.*Test" />
<Field type="android.support.test.rule.UiThreadTestRule" />
......@@ -43,10 +43,5 @@ In particular, ~ at the start of a string means it's a regex.
<Field type="org.junit.rules.RuleChain" />
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
</Match>
<Match>
<Class name="~.*\.*Test" />
<Field type="org.junit.rules.TestRule" />
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
</Match>
</FindBugsFilter>
......@@ -6,116 +6,35 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:chrome="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/SuggestionCardModern"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- This layout is nested inside another layout so that we can align the thumbnail corners
relative to it. The corners are aligned with respect to the whole card, in case the card
contents are taller than the thumbnail. -->
<RelativeLayout
android:id="@+id/card_contents"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<org.chromium.chrome.browser.widget.TintedImageView
android:id="@+id/article_thumbnail"
android:layout_width="@dimen/snippets_thumbnail_size_large"
android:layout_height="@dimen/snippets_thumbnail_size_large"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:scaleType="centerCrop"
android:contentDescription="@null"
android:src="@null"
tools:src="@drawable/ic_snippet_thumbnail_placeholder" />
<ImageView
android:id="@+id/offline_icon"
android:layout_width="@dimen/content_suggestions_card_modern_offline_badge_overlay_size"
android:layout_height=
"@dimen/content_suggestions_card_modern_offline_badge_overlay_size"
android:layout_alignTop="@id/article_thumbnail"
android:layout_alignStart="@id/article_thumbnail"
android:layout_marginStart=
"@dimen/content_suggestions_card_modern_offline_badge_overlay_margin_start"
android:layout_marginTop=
"@dimen/content_suggestions_card_modern_offline_badge_overlay_margin_top"
android:contentDescription="@null"
android:visibility="gone"
app:srcCompat="@drawable/ic_offline_pin_white"
tools:src="@drawable/ic_offline_pin_white"/>
<LinearLayout
android:id="@+id/text_layout"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/article_thumbnail"
android:layout_alignWithParentIfMissing="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="@dimen/snippets_padding"
android:orientation="vertical">
<org.chromium.ui.widget.TextViewWithLeading
style="@style/SuggestionCardTitleModern"
android:id="@+id/article_headline"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:text="Article headline" />
<org.chromium.ui.widget.TextViewWithLeading
style="@style/SuggestionCardBodyModern"
android:id="@+id/article_snippet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:maxLines="2"
tools:text="Article snippet" />
<LinearLayout
tools:ignore="UseCompoundDrawables"
android:id="@+id/publisher_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/snippets_publisher_margin_top_with_article_snippet"
android:orientation="horizontal">
<org.chromium.chrome.browser.widget.TintedImageView
android:id="@+id/article_thumbnail"
android:layout_width="@dimen/snippets_thumbnail_size_large"
android:layout_height="@dimen/snippets_thumbnail_size_large"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:scaleType="centerCrop"
android:contentDescription="@null"
android:src="@null"
tools:src="@drawable/ic_snippet_thumbnail_placeholder" />
<!-- The following attributes:
- publisher_bar's android:layout_width="wrap_content"
- article_publisher's android:layout_width="0dp"
- article_publisher's android:layout_weight="1"
- article_publisher's android:ellipsize="end"
- article_age's android:layout_width="wrap_content"
All ensure that when the publisher string is long, it starts to ellipsize
before pushing the article age string and the offline icon off the screen.
See: https://crbug.com/625775 and https://crbug.com/678568 -->
<TextView
android:id="@+id/article_publisher"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"
android:textSize="12sp"
android:textColor="@color/snippets_publisher_name_color"
android:textDirection="locale"
tools:text="chromium.org"/>
<TextView
android:id="@+id/article_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textSize="12sp"
android:textColor="@color/snippets_publisher_name_color"
android:textDirection="locale"
tools:text=" - 3 hours ago" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="@+id/offline_icon"
android:layout_width="@dimen/content_suggestions_card_modern_offline_badge_overlay_size"
android:layout_height="@dimen/content_suggestions_card_modern_offline_badge_overlay_size"
android:layout_alignTop="@id/article_thumbnail"
android:layout_alignStart="@id/article_thumbnail"
android:layout_marginStart="@dimen/content_suggestions_card_modern_offline_badge_overlay_margin_start"
android:layout_marginTop="@dimen/content_suggestions_card_modern_offline_badge_overlay_margin_top"
android:contentDescription="@null"
android:visibility="gone"
app:srcCompat="@drawable/ic_offline_pin_white"
tools:src="@drawable/ic_offline_pin_white"/>
<!-- It would have been nice to use RoundedBitmapDrawable on the thumbnail, but with that you
cannot select which corners must be rounded, they are all rounded. -->
......@@ -123,7 +42,7 @@
android:id="@+id/corner_top"
android:layout_width="@dimen/content_suggestions_card_modern_corner_radius"
android:layout_height="@dimen/content_suggestions_card_modern_corner_radius"
android:layout_alignTop="@id/card_contents"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:contentDescription="@null"
android:scaleX="@integer/automirror_scale_x"
......@@ -133,10 +52,79 @@
android:id="@+id/corner_bottom"
android:layout_width="@dimen/content_suggestions_card_modern_corner_radius"
android:layout_height="@dimen/content_suggestions_card_modern_corner_radius"
android:layout_alignBottom="@id/card_contents"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:contentDescription="@null"
android:scaleX="@integer/automirror_scale_x"
app:srcCompat="@drawable/content_suggestions_card_corner_bottom" />
<LinearLayout
android:id="@+id/text_layout"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/article_thumbnail"
android:layout_alignWithParentIfMissing="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="@dimen/snippets_padding"
android:orientation="vertical">
<org.chromium.ui.widget.TextViewWithLeading
style="@style/SuggestionCardTitleModern"
android:id="@+id/article_headline"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:text="Article headline" />
<org.chromium.ui.widget.TextViewWithLeading
style="@style/SuggestionCardBodyModern"
android:id="@+id/article_snippet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:maxLines="2"
tools:text="Article snippet" />
<LinearLayout
tools:ignore="UseCompoundDrawables"
android:id="@+id/publisher_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/snippets_publisher_margin_top_with_article_snippet"
android:orientation="horizontal">
<!-- The following attributes:
- publisher_bar's android:layout_width="wrap_content"
- article_publisher's android:layout_width="0dp"
- article_publisher's android:layout_weight="1"
- article_publisher's android:ellipsize="end"
- article_age's android:layout_width="wrap_content"
All ensure that when the publisher string is long, it starts to ellipsize before
pushing the article age string and the offline icon off the screen.
See: https://crbug.com/625775 and https://crbug.com/678568 -->
<TextView
android:id="@+id/article_publisher"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"
android:textSize="12sp"
android:textColor="@color/snippets_publisher_name_color"
android:textDirection="locale"
tools:text="chromium.org"/>
<TextView
android:id="@+id/article_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textSize="12sp"
android:textColor="@color/snippets_publisher_name_color"
android:textDirection="locale"
tools:text=" - 3 hours ago" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
......@@ -4,9 +4,6 @@
package org.chromium.chrome.browser.ntp.snippets;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
......@@ -22,31 +19,35 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.ExternalResource;
import org.junit.runner.RunWith;
import org.chromium.base.Callback;
import org.chromium.base.CommandLine;
import org.chromium.base.DiscardableReferencePool;
import org.chromium.base.ThreadUtils;
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.annotations.SuppressFBWarnings;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.base.test.util.parameter.CommandLineParameter;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation;
import org.chromium.chrome.browser.download.ui.ThumbnailProvider;
import org.chromium.chrome.browser.download.ui.ThumbnailProvider.ThumbnailRequest;
import org.chromium.chrome.browser.favicon.LargeIconBridge;
import org.chromium.chrome.browser.ntp.ContextMenuManager;
import org.chromium.chrome.browser.ntp.ContextMenuManager.TouchEnabledDelegate;
import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter;
import org.chromium.chrome.browser.ntp.cards.SignInPromo;
import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.suggestions.ContentSuggestionsAdditionalAction;
import org.chromium.chrome.browser.suggestions.DestructionObserver;
import org.chromium.chrome.browser.suggestions.ImageFetcher;
......@@ -61,9 +62,8 @@ import org.chromium.chrome.browser.widget.displaystyle.HorizontalDisplayStyle;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
import org.chromium.chrome.browser.widget.displaystyle.VerticalDisplayStyle;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.RenderTestRule;
import org.chromium.chrome.test.util.browser.compositor.layouts.DisableChromeAnimations;
import org.chromium.chrome.test.util.browser.suggestions.DummySuggestionsEventReporter;
import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource;
import org.chromium.chrome.test.util.browser.suggestions.SuggestionsDependenciesRule;
......@@ -77,8 +77,7 @@ import java.util.Locale;
/**
* Tests for the appearance of Article Snippets.
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(ChromeJUnit4RunnerDelegate.class)
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
public class ArticleSnippetsTest {
......@@ -88,184 +87,159 @@ public class ArticleSnippetsTest {
@Rule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class);
@Rule
public RenderTestRule mRenderTestRule =
new RenderTestRule("chrome/test/data/android/render_tests");
// Rules must be public for JUnit to access them, but FindBugs complains about that.
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
@Rule
public TestRule mDisableChromeAnimations = new DisableChromeAnimations();
public ExternalResource mDisableChromeAnimationsRule = new ExternalResource() {
private final boolean mChromeHomeEnabled;
private float mOldAnimationMultiplier;
@Override
protected void before() {
mOldAnimationMultiplier = ChromeAnimation.Animation.getAnimationMultiplier();
ChromeAnimation.Animation.setAnimationMultiplierForTesting(0f);
}
@ClassParameter
private static List<ParameterSet> sClassParams = Arrays.asList(
new ParameterSet().name("ChromeHomeEnabled").value(true),
new ParameterSet().name("ChromeHomeDisabled").value(false));
@Override
protected void after() {
ChromeAnimation.Animation.setAnimationMultiplierForTesting(mOldAnimationMultiplier);
}
};
private SuggestionsUiDelegate mUiDelegate;
private FakeSuggestionsSource mSnippetsSource;
private MockThumbnailProvider mThumbnailProvider;
private SuggestionsRecyclerView mRecyclerView;
private ContextMenuManager mContextMenuManager;
private NewTabPageAdapter mAdapter;
private FrameLayout mContentView;
private SnippetArticleViewHolder mSuggestion;
private SignInPromo.GenericPromoViewHolder mSigninPromo;
private UiConfig mUiConfig;
private static final int FULL_CATEGORY = 0;
private static final int MINIMAL_CATEGORY = 1;
private long mTimestamp;
public ArticleSnippetsTest(boolean chromeHomeEnabled) {
mChromeHomeEnabled = chromeHomeEnabled;
if (chromeHomeEnabled) {
mRenderTestRule.setVariantPrefix("modern");
}
}
@Before
public void setUp() throws Exception {
if (mChromeHomeEnabled) {
CommandLine.getInstance().appendSwitch("enable-features=ChromeHome,ChromeHomeModern");
} else {
CommandLine.getInstance().appendSwitch("disable-features=ChromeHome,ChromeHomeModern");
}
mActivityTestRule.startMainActivityOnBlankPage();
ChromePreferenceManager.getInstance().setNewTabPageGenericSigninPromoDismissed(true);
mThumbnailProvider = new MockThumbnailProvider();
mSnippetsSource = new FakeSuggestionsSource();
mSuggestionsDeps.getFactory().thumbnailProvider = mThumbnailProvider;
mSuggestionsDeps.getFactory().suggestionsSource = mSnippetsSource;
mUiDelegate = new MockUiDelegate();
mSnippetsSource.setDefaultFavicon(getBitmap(R.drawable.star_green));
mTimestamp = System.currentTimeMillis() - 5 * DateUtils.MINUTE_IN_MILLIS;
FeatureUtilities.resetChromeHomeEnabledForTests();
FeatureUtilities.cacheChromeHomeEnabled();
assertThat(FeatureUtilities.isChromeHomeModernEnabled(), is(mChromeHomeEnabled));
ThreadUtils.runOnUiThreadBlocking(() -> {
mContentView = new FrameLayout(mActivityTestRule.getActivity());
mUiConfig = new UiConfig(mContentView);
mActivityTestRule.getActivity().setContentView(mContentView);
mRecyclerView = new SuggestionsRecyclerView(mActivityTestRule.getActivity());
TouchEnabledDelegate touchEnabledDelegate =
enabled -> mRecyclerView.setTouchEnabled(enabled);
mContextMenuManager = new ContextMenuManager(mActivityTestRule.getActivity(),
mUiDelegate.getNavigationDelegate(), touchEnabledDelegate);
mRecyclerView.init(mUiConfig, mContextMenuManager);
mSuggestion = new SnippetArticleViewHolder(
mRecyclerView, mContextMenuManager, mUiDelegate, mUiConfig);
mSigninPromo = new SignInPromo.GenericPromoViewHolder(
mRecyclerView, mContextMenuManager, mUiConfig);
});
}
private MockThumbnailProvider mThumbnailProvider;
@Test
@MediumTest
@DisabledTest(message = "crbug.com/757735")
@Feature({"ArticleSnippets", "RenderTest"})
@CommandLineParameter({"", "enable-features=" + ChromeFeatureList.CHROME_HOME + ","
+ ChromeFeatureList.CHROME_HOME_MODERN_LAYOUT})
@RetryOnFailure
public void testSnippetAppearance() throws IOException {
SuggestionsCategoryInfo fullCategoryInfo = new SuggestionsCategoryInfo(FULL_CATEGORY,
"Section Title", ContentSuggestionsCardLayout.FULL_CARD,
ContentSuggestionsAdditionalAction.NONE,
/* show_if_empty = */ true, "No suggestions");
SnippetArticle shortSnippet = new SnippetArticle(FULL_CATEGORY, "id1", "Snippet",
"Publisher", "Preview Text", "www.google.com",
mTimestamp, // Publish timestamp
10f, // Score
mTimestamp, // Fetch timestamp
false); // IsVideoSuggestion
Bitmap watch = BitmapFactory.decodeFile(
// Don't load the Bitmap on the UI thread - this is a StrictModeViolation.
final Bitmap watch = BitmapFactory.decodeFile(
UrlUtils.getIsolatedTestFilePath("chrome/test/data/android/watch.jpg"));
Drawable drawable = ThumbnailGradient.createDrawableWithGradientIfNeeded(
watch, mActivityTestRule.getActivity().getResources());
shortSnippet.setThumbnail(mUiDelegate.getReferencePool().put(drawable));
renderSuggestion(shortSnippet, fullCategoryInfo, "short_snippet");
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
setupTestData(watch);
SnippetArticle longSnippet = new SnippetArticle(FULL_CATEGORY, "id2",
new String(new char[20]).replace("\0", "Snippet "),
new String(new char[20]).replace("\0", "Publisher "),
new String(new char[80]).replace("\0", "Preview Text "), "www.google.com",
mTimestamp, // Publish timestamp
20f, // Score
mTimestamp, // Fetch timestamp
false); // IsVideoSuggestion
renderSuggestion(longSnippet, fullCategoryInfo, "long_snippet");
mContentView = new FrameLayout(mActivityTestRule.getActivity());
mUiConfig = new UiConfig(mContentView);
SuggestionsCategoryInfo minimalCategory = new SuggestionsCategoryInfo(MINIMAL_CATEGORY,
"Section Title", ContentSuggestionsCardLayout.MINIMAL_CARD,
ContentSuggestionsAdditionalAction.NONE,
/* show_if_empty = */ true, "No suggestions");
mActivityTestRule.getActivity().setContentView(mContentView);
SnippetArticle minimalSnippet = new SnippetArticle(MINIMAL_CATEGORY, "id3",
new String(new char[20]).replace("\0", "Bookmark "), "Publisher",
"This should not be displayed", "www.google.com",
mTimestamp, // Publish timestamp
10f, // Score
mTimestamp, // Fetch timestamp
false); // IsVideoSuggestion
renderSuggestion(minimalSnippet, minimalCategory, "minimal_snippet");
mRecyclerView = new SuggestionsRecyclerView(mActivityTestRule.getActivity());
mContentView.addView(mRecyclerView);
SnippetArticle minimalSnippet2 = new SnippetArticle(MINIMAL_CATEGORY, "id4", "Bookmark",
"Publisher", "This should not be displayed", "www.google.com",
mTimestamp, // Publish timestamp
10f, // Score
mTimestamp, // Fetch timestamp
false);
mAdapter = new NewTabPageAdapter(mUiDelegate, /* aboveTheFold = */ null, mUiConfig,
OfflinePageBridge.getForProfile(Profile.getLastUsedProfile()),
/* contextMenuManager = */ null, /* tileGroupDelegate = */ null,
/* suggestionsCarousel = */ null);
mAdapter.refreshSuggestions();
mRecyclerView.setAdapter(mAdapter);
}
});
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
int first = mAdapter.getFirstCardPosition();
mRenderTestRule.render(mRecyclerView.getChildAt(first), "short_snippet");
mRenderTestRule.render(mRecyclerView.getChildAt(first + 1), "long_snippet");
int firstOfSecondCategory = first + 1 /* card 2 */ + 1 /* header */ + 1 /* card 3 */;
mRenderTestRule.render(mRecyclerView.getChildAt(firstOfSecondCategory), "minimal_snippet");
mRenderTestRule.render(mRecyclerView, "snippets");
// See how everything looks in narrow layout.
ThreadUtils.runOnUiThreadBlocking(() -> {
// Since we inform the UiConfig manually about the desired display style, the only
// reason we actually change the LayoutParams is for the rendered Views to look right.
ViewGroup.LayoutParams params = mContentView.getLayoutParams();
params.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350,
mRecyclerView.getResources().getDisplayMetrics());
mContentView.setLayoutParams(params);
mUiConfig.setDisplayStyleForTesting(new UiConfig.DisplayStyle(
HorizontalDisplayStyle.NARROW, VerticalDisplayStyle.REGULAR));
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
// Since we inform the UiConfig manually about the desired display style, the only
// reason we actually change the LayoutParams is for the rendered Views to look
// right.
ViewGroup.LayoutParams params = mContentView.getLayoutParams();
params.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350,
mRecyclerView.getResources().getDisplayMetrics());
mContentView.setLayoutParams(params);
mUiConfig.setDisplayStyleForTesting(new UiConfig.DisplayStyle(
HorizontalDisplayStyle.NARROW, VerticalDisplayStyle.REGULAR));
}
});
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
renderSuggestion(shortSnippet, fullCategoryInfo, "short_snippet_narrow");
renderSuggestion(longSnippet, fullCategoryInfo, "long_snippet_narrow");
renderSuggestion(minimalSnippet, minimalCategory, "long_minimal_snippet_narrow");
renderSuggestion(minimalSnippet2, minimalCategory, "short_minimal_snippet_narrow");
mRenderTestRule.render(mRecyclerView.getChildAt(first), "short_snippet_narrow");
mRenderTestRule.render(mRecyclerView.getChildAt(first + 1), "long_snippet_narrow");
mRenderTestRule.render(
mRecyclerView.getChildAt(firstOfSecondCategory), "long_minimal_snippet_narrow");
mRenderTestRule.render(mRecyclerView.getChildAt(firstOfSecondCategory + 1),
"short_minimal_snippet_narrow");
mRenderTestRule.render(mRecyclerView, "snippets_narrow");
}
// TODO(bauerb): Test top, middle, and bottom card backgrounds.
@Test
@MediumTest
@Feature({"ArticleSnippets", "RenderTest"})
public void testDownloadSuggestion() throws IOException {
String downloadFilePath =
final String filePath =
UrlUtils.getIsolatedTestFilePath("chrome/test/data/android/capybara.jpg");
ThreadUtils.runOnUiThreadBlocking(() -> {
SnippetArticle downloadSuggestion = new SnippetArticle(KnownCategories.DOWNLOADS, "id1",
"test_image.jpg", "example.com", null, "http://example.com", mTimestamp, 10f,
mTimestamp, false);
downloadSuggestion.setAssetDownloadData("asdf", downloadFilePath, "image/jpeg");
SuggestionsCategoryInfo downloadsCategory = new SuggestionsCategoryInfo(
KnownCategories.DOWNLOADS, "Downloads", ContentSuggestionsCardLayout.FULL_CARD,
ContentSuggestionsAdditionalAction.NONE,
/* show_if_empty = */ true, "No suggestions");
mSuggestion.onBindViewHolder(downloadSuggestion, downloadsCategory);
mContentView.addView(mSuggestion.itemView);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
mContentView = new FrameLayout(mActivityTestRule.getActivity());
mUiConfig = new UiConfig(mContentView);
mActivityTestRule.getActivity().setContentView(mContentView);
mRecyclerView = new SuggestionsRecyclerView(mActivityTestRule.getActivity());
TouchEnabledDelegate touchEnabledDelegate = new TouchEnabledDelegate() {
@Override
public void setTouchEnabled(boolean enabled) {
mRecyclerView.setTouchEnabled(enabled);
}
};
ContextMenuManager contextMenuManager =
new ContextMenuManager(mActivityTestRule.getActivity(),
mUiDelegate.getNavigationDelegate(), touchEnabledDelegate);
mRecyclerView.init(mUiConfig, contextMenuManager);
mRecyclerView.setAdapter(mAdapter);
mSuggestion = new SnippetArticleViewHolder(
mRecyclerView, contextMenuManager, mUiDelegate, mUiConfig);
long timestamp = System.currentTimeMillis() - 5 * DateUtils.MINUTE_IN_MILLIS;
SnippetArticle download = new SnippetArticle(KnownCategories.DOWNLOADS, "id1",
"test_image.jpg", "example.com", null, "http://example.com", timestamp, 10f,
timestamp, false);
download.setAssetDownloadData("asdf", filePath, "image/jpeg");
SuggestionsCategoryInfo categoryInfo =
new SuggestionsCategoryInfo(KnownCategories.DOWNLOADS, "Downloads",
ContentSuggestionsCardLayout.FULL_CARD,
ContentSuggestionsAdditionalAction.NONE,
/* show_if_empty = */ true, "No suggestions");
mSuggestion.onBindViewHolder(download, categoryInfo);
mContentView.addView(mSuggestion.itemView);
}
});
mRenderTestRule.render(mSuggestion.itemView, "download_snippet_placeholder");
......@@ -273,21 +247,25 @@ public class ArticleSnippetsTest {
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
List<ThumbnailRequest> requests = mThumbnailProvider.getRequests();
Assert.assertEquals(1, requests.size());
ThumbnailRequest request = requests.get(0);
Assert.assertEquals(downloadFilePath, request.getFilePath());
final ThumbnailRequest request = requests.get(0);
Assert.assertEquals(filePath, request.getFilePath());
Bitmap thumbnail = BitmapFactory.decodeFile(downloadFilePath);
final Bitmap thumbnail = BitmapFactory.decodeFile(filePath);
ThreadUtils.runOnUiThreadBlocking(() -> {
mThumbnailProvider.fulfillRequest(request, thumbnail);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
mThumbnailProvider.fulfillRequest(request, thumbnail);
}
});
mRenderTestRule.render(mSuggestion.itemView, "download_snippet_thumbnail");
}
@Test
@MediumTest
@Feature({"ArticleSnippets", "RenderTest"})
@CommandLineParameter({"", "enable-features=" + ChromeFeatureList.CHROME_HOME + ","
+ ChromeFeatureList.CHROME_HOME_MODERN_LAYOUT})
public void testSigninPromo() throws IOException {
ThreadUtils.runOnUiThreadBlocking(() -> {
mContentView = new FrameLayout(mActivityTestRule.getActivity());
......@@ -302,6 +280,7 @@ public class ArticleSnippetsTest {
new ContextMenuManager(mActivityTestRule.getActivity(),
mUiDelegate.getNavigationDelegate(), touchEnabledDelegate);
mRecyclerView.init(mUiConfig, contextMenuManager);
mRecyclerView.setAdapter(mAdapter);
mSigninPromo = new SignInPromo.GenericPromoViewHolder(
mRecyclerView, contextMenuManager, mUiConfig);
......@@ -309,22 +288,85 @@ public class ArticleSnippetsTest {
mContentView.addView(mSigninPromo.itemView);
});
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mRenderTestRule.render(mSigninPromo.itemView, "signin_promo");
}
private void renderSuggestion(SnippetArticle suggestion, SuggestionsCategoryInfo categoryInfo,
String renderId) throws IOException {
ThreadUtils.runOnUiThreadBlocking(() -> {
mSuggestion.onBindViewHolder(suggestion, categoryInfo);
mContentView.addView(mSuggestion.itemView);
});
mRenderTestRule.render(mSuggestion.itemView, renderId);
private void setupTestData(Bitmap thumbnail) {
@CategoryInt
int fullCategory = 0;
@CategoryInt
int minimalCategory = 1;
SnippetArticle shortSnippet = new SnippetArticle(fullCategory, "id1", "Snippet",
"Publisher", "Preview Text", "www.google.com",
1466614774, // Publish timestamp
10f, // Score
1466634774, // Fetch timestamp
false); // IsVideoSuggestion
ThreadUtils.runOnUiThreadBlocking(() -> {
mContentView.removeView(mSuggestion.itemView);
mSuggestion.recycle();
});
Drawable drawable = ThumbnailGradient.createDrawableWithGradientIfNeeded(
thumbnail, mActivityTestRule.getActivity().getResources());
shortSnippet.setThumbnail(mUiDelegate.getReferencePool().put(drawable));
SnippetArticle longSnippet = new SnippetArticle(fullCategory, "id2",
new String(new char[20]).replace("\0", "Snippet "),
new String(new char[20]).replace("\0", "Publisher "),
new String(new char[80]).replace("\0", "Preview Text "), "www.google.com",
1466614074, // Publish timestamp
20f, // Score
1466634774, // Fetch timestamp
false); // IsVideoSuggestion
SnippetArticle minimalSnippet = new SnippetArticle(minimalCategory, "id3",
new String(new char[20]).replace("\0", "Bookmark "), "Publisher",
"This should not be displayed", "www.google.com",
1466614774, // Publish timestamp
10f, // Score
1466634774, // Fetch timestamp
false); // IsVideoSuggestion
SnippetArticle minimalSnippet2 = new SnippetArticle(minimalCategory, "id4", "Bookmark",
"Publisher", "This should not be displayed", "www.google.com",
1466614774, // Publish timestamp
10f, // Score
1466634774, // Fetch timestamp
false); // IsVideoSuggestion
mSnippetsSource.setInfoForCategory(fullCategory,
new SuggestionsCategoryInfo(fullCategory, "Section Title",
ContentSuggestionsCardLayout.FULL_CARD,
ContentSuggestionsAdditionalAction.NONE,
/*show_if_empty=*/true, "No suggestions"));
mSnippetsSource.setStatusForCategory(fullCategory, CategoryStatus.AVAILABLE);
mSnippetsSource.setSuggestionsForCategory(
fullCategory, Arrays.asList(shortSnippet, longSnippet));
mSnippetsSource.setInfoForCategory(minimalCategory,
new SuggestionsCategoryInfo(minimalCategory, "Section Title",
ContentSuggestionsCardLayout.MINIMAL_CARD,
ContentSuggestionsAdditionalAction.NONE,
/* show_if_empty = */ true, "No suggestions"));
mSnippetsSource.setStatusForCategory(minimalCategory, CategoryStatus.AVAILABLE);
mSnippetsSource.setSuggestionsForCategory(
minimalCategory, Arrays.asList(minimalSnippet, minimalSnippet2));
}
@Before
public void setUp() throws Exception {
mActivityTestRule.startMainActivityOnBlankPage();
ChromePreferenceManager.getInstance().setNewTabPageGenericSigninPromoDismissed(true);
mThumbnailProvider = new MockThumbnailProvider();
mSnippetsSource = new FakeSuggestionsSource();
mSuggestionsDeps.getFactory().thumbnailProvider = mThumbnailProvider;
mSuggestionsDeps.getFactory().suggestionsSource = mSnippetsSource;
mUiDelegate = new MockUiDelegate();
mSnippetsSource.setDefaultFavicon(getBitmap(R.drawable.star_green));
FeatureUtilities.resetChromeHomeEnabledForTests();
FeatureUtilities.cacheChromeHomeEnabled();
if (FeatureUtilities.isChromeHomeModernEnabled()) {
mRenderTestRule.setVariantPrefix("modern");
}
}
private Bitmap getBitmap(@DrawableRes int resId) {
......
......@@ -31,7 +31,6 @@ android_library("chrome_java_test_support") {
"javatests/src/org/chromium/chrome/test/util/ApplicationData.java",
"javatests/src/org/chromium/chrome/test/util/ApplicationTestUtils.java",
"javatests/src/org/chromium/chrome/test/util/BookmarkTestUtil.java",
"javatests/src/org/chromium/chrome/test/util/browser/compositor/layouts/DisableChromeAnimations.java",
"javatests/src/org/chromium/chrome/test/util/browser/contextmenu/ContextMenuUtils.java",
"javatests/src/org/chromium/chrome/test/util/browser/Features.java",
"javatests/src/org/chromium/chrome/test/util/browser/LocationSettingsTestUtil.java",
......
// Copyright 2017 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.chrome.test.util.browser.compositor.layouts;
import org.junit.rules.ExternalResource;
import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation;
/**
* JUnit 4 rule that disables animations in ChromeAnimation for tests.
*/
public class DisableChromeAnimations extends ExternalResource {
private float mOldAnimationMultiplier;
@Override
protected void before() {
mOldAnimationMultiplier = ChromeAnimation.Animation.getAnimationMultiplier();
ChromeAnimation.Animation.setAnimationMultiplierForTesting(0f);
}
@Override
protected void after() {
ChromeAnimation.Animation.setAnimationMultiplierForTesting(mOldAnimationMultiplier);
}
}
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