Commit 65a6d6b2 authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Add a render test

Add a render test that checks layout of:
 - peeking bar
 - card while its thumbnail is loading
 - card after the thumbnail has loaded
 - card with offline badge
 - full sheet
 - full sheet scrolled

BUG=835450

Change-Id: I8860d9eca6fd7f54e794b08076749cae0f3ecbe1
Reviewed-on: https://chromium-review.googlesource.com/1039876
Commit-Queue: Theresa <twellington@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555778}
parent 15798520
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.ntp.snippets; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.ntp.snippets;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.metrics.ImpressionTracker; import org.chromium.chrome.browser.metrics.ImpressionTracker;
import org.chromium.chrome.browser.ntp.ContextMenuManager; import org.chromium.chrome.browser.ntp.ContextMenuManager;
...@@ -245,4 +246,9 @@ public class SnippetArticleViewHolder extends CardViewHolder { ...@@ -245,4 +246,9 @@ public class SnippetArticleViewHolder extends CardViewHolder {
mUiDelegate.getEventReporter().onSuggestionShown(mArticle); mUiDelegate.getEventReporter().onSuggestionShown(mArticle);
mRecyclerView.onSnippetImpression(); mRecyclerView.onSnippetImpression();
} }
@VisibleForTesting
public void setOfflineBadgeVisibilityForTesting(boolean visible) {
mSuggestionsBinder.updateOfflineBadgeVisibility(visible);
}
} }
...@@ -50,6 +50,7 @@ import org.chromium.chrome.test.ChromeActivityTestRule; ...@@ -50,6 +50,7 @@ import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule; import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.RenderTestRule;
import org.chromium.chrome.test.util.ViewUtils; import org.chromium.chrome.test.util.ViewUtils;
import org.chromium.chrome.test.util.browser.ChromeModernDesign; import org.chromium.chrome.test.util.browser.ChromeModernDesign;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
...@@ -87,6 +88,8 @@ public class ContextualSuggestionsTest { ...@@ -87,6 +88,8 @@ public class ContextualSuggestionsTest {
public ScreenShooter mScreenShooter = new ScreenShooter(); public ScreenShooter mScreenShooter = new ScreenShooter();
@Rule @Rule
public TestRule mDisableChromeAnimations = new DisableChromeAnimations(); public TestRule mDisableChromeAnimations = new DisableChromeAnimations();
@Rule
public RenderTestRule mRenderTestRule = new RenderTestRule();
private static final String TEST_PAGE = private static final String TEST_PAGE =
"/chrome/test/data/android/contextual_suggestions/contextual_suggestions_test.html"; "/chrome/test/data/android/contextual_suggestions/contextual_suggestions_test.html";
...@@ -486,6 +489,48 @@ public class ContextualSuggestionsTest { ...@@ -486,6 +489,48 @@ public class ContextualSuggestionsTest {
mScreenShooter.shoot("Contextual suggestions: scrolled"); mScreenShooter.shoot("Contextual suggestions: scrolled");
} }
@Test
@MediumTest
@Feature({"ContextualSuggestions", "RenderTest"})
@DisableFeatures(FeatureConstants.CONTEXTUAL_SUGGESTIONS_FEATURE)
public void testRender() throws Exception {
// Force suggestions to populate in the bottom sheet, then render the peeking bar.
forceShowSuggestions();
BottomSheetTestRule.waitForWindowUpdates();
mRenderTestRule.render(
mBottomSheet.getCurrentSheetContent().getToolbarView(), "peeking_bar");
// Open the sheet to cause the suggestions to be bound in the RecyclerView, then capture
// a suggestion with its thumbnail loading.
ThreadUtils.runOnUiThreadBlocking(
() -> mBottomSheet.setSheetState(BottomSheet.SHEET_STATE_FULL, false));
BottomSheetTestRule.waitForWindowUpdates();
mRenderTestRule.render(getFirstSuggestionViewHolder().itemView, "suggestion_image_loading");
// Run the image fetch callback so images load, then capture a suggestion with its
// thumbnail loaded.
ThreadUtils.runOnUiThreadBlocking(() -> mFakeSource.runImageFetchCallbacks());
BottomSheetTestRule.waitForWindowUpdates();
mRenderTestRule.render(getFirstSuggestionViewHolder().itemView, "suggestion_image_loaded");
// Render a thumbnail with an offline badge.
ThreadUtils.runOnUiThreadBlocking(
() -> getSuggestionViewHolder(2).setOfflineBadgeVisibilityForTesting(true));
mRenderTestRule.render(getSuggestionViewHolder(2).itemView, "suggestion_offline");
// Render the full suggestions sheet.
mRenderTestRule.render(mBottomSheet, "full_height");
// Scroll the suggestions and render the full suggestions sheet.
ThreadUtils.runOnUiThreadBlocking(() -> {
RecyclerView view =
(RecyclerView) mBottomSheet.getCurrentSheetContent().getContentView();
view.scrollToPosition(5);
});
BottomSheetTestRule.waitForWindowUpdates();
mRenderTestRule.render(mBottomSheet, "full_height_scrolled");
}
private void forceShowSuggestions() throws InterruptedException, TimeoutException { private void forceShowSuggestions() throws InterruptedException, TimeoutException {
assertEquals("Model has incorrect number of items.", assertEquals("Model has incorrect number of items.",
(int) FakeContextualSuggestionsSource.TOTAL_ITEM_COUNT, (int) FakeContextualSuggestionsSource.TOTAL_ITEM_COUNT,
...@@ -527,12 +572,20 @@ public class ContextualSuggestionsTest { ...@@ -527,12 +572,20 @@ public class ContextualSuggestionsTest {
} }
private SnippetArticleViewHolder getFirstSuggestionViewHolder(BottomSheet bottomSheet) { private SnippetArticleViewHolder getFirstSuggestionViewHolder(BottomSheet bottomSheet) {
return getSuggestionViewHolder(bottomSheet, 0);
}
private SnippetArticleViewHolder getSuggestionViewHolder(int index) {
return getSuggestionViewHolder(mBottomSheet, index);
}
private SnippetArticleViewHolder getSuggestionViewHolder(BottomSheet bottomSheet, int index) {
ContextualSuggestionsBottomSheetContent content = ContextualSuggestionsBottomSheetContent content =
(ContextualSuggestionsBottomSheetContent) bottomSheet.getCurrentSheetContent(); (ContextualSuggestionsBottomSheetContent) bottomSheet.getCurrentSheetContent();
RecyclerView recyclerView = (RecyclerView) content.getContentView(); RecyclerView recyclerView = (RecyclerView) content.getContentView();
RecyclerViewTestUtils.waitForStableRecyclerView(recyclerView); RecyclerViewTestUtils.waitForStableRecyclerView(recyclerView);
return (SnippetArticleViewHolder) recyclerView.findViewHolderForAdapterPosition(0); return (SnippetArticleViewHolder) recyclerView.findViewHolderForAdapterPosition(index);
} }
} }
...@@ -89,7 +89,7 @@ public class FakeContextualSuggestionsSource extends ContextualSuggestionsSource ...@@ -89,7 +89,7 @@ public class FakeContextualSuggestionsSource extends ContextualSuggestionsSource
mPendingImageRequests.clear(); mPendingImageRequests.clear();
} }
private ContextualSuggestionsResult createDummyResults() { private static ContextualSuggestionsResult createDummyResults() {
SnippetArticle suggestion1 = new SnippetArticle(KnownCategories.CONTEXTUAL, "id1", SnippetArticle suggestion1 = new SnippetArticle(KnownCategories.CONTEXTUAL, "id1",
"Capybaras also love hats", "Capybaras also love hats",
"Lorem ipsum dolor sit amet, consectetur adipiscing " "Lorem ipsum dolor sit amet, consectetur adipiscing "
...@@ -109,7 +109,8 @@ public class FakeContextualSuggestionsSource extends ContextualSuggestionsSource ...@@ -109,7 +109,8 @@ public class FakeContextualSuggestionsSource extends ContextualSuggestionsSource
new SnippetArticle(KnownCategories.CONTEXTUAL, "id3", "Capybaras don't like ties", new SnippetArticle(KnownCategories.CONTEXTUAL, "id3", "Capybaras don't like ties",
"Pellentesque nec lorem nec velit convallis suscipit " "Pellentesque nec lorem nec velit convallis suscipit "
+ "non eget nunc.", + "non eget nunc.",
"Capybara News", "https://site.com/url3", 0, 0, 0, false, null, true); "Breaking Capybara News Updates Delivered Daily", "https://site.com/url3",
0, 0, 0, false, null, true);
SnippetArticle article4 = SnippetArticle article4 =
new SnippetArticle(KnownCategories.CONTEXTUAL, "id4", "Fancy watches", new SnippetArticle(KnownCategories.CONTEXTUAL, "id4", "Fancy watches",
"Duis egestas est vitae eros consectetur vulputate. Integer " "Duis egestas est vitae eros consectetur vulputate. Integer "
......
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