Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3928)

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java

Issue 2249903003: 📰 Empty state handling for the Bookmarks section (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java
index 54a9e3f89cada683e3e8b25c15aac094fb854a13..10c0d35434903ee4d5d6fef620791a5c51ae2ae0 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java
@@ -34,14 +34,12 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-
/**
* Unit tests for {@link NewTabPageAdapter}.
*/
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class NewTabPageAdapterTest {
-
private static class FakeSnippetsSource implements SuggestionsSource {
private SuggestionsSource.Observer mObserver;
private final Map<Integer, List<SnippetArticle>> mSuggestions = new HashMap<>();
@@ -178,6 +176,23 @@ private int sectionWithStatusCard() {
return 3; // Header, status card and progress indicator.
}
+ /**
+ * To be used with {@link #assertItemsFor(int...)}, for a section that is hidden.
+ * @return The number of items that should be used by the adapter to represent this section.
+ */
+ private int sectionHidden() {
+ return 0; // The section returns no items.
+ }
+
+ /**
+ * To be used with {@link #assertItemsFor(int...)}, for a section with button that has no
+ * suggestions and instead displays a status card.
+ * @return The number of items that should be used by the adapter to represent this section.
+ */
+ private int sectionWithStatusCardAndMoreButton() {
+ return 4; // Header, status card, More button, progress indicator.
+ }
+
@Before
public void setUp() {
RecordHistogram.disableForTests();
@@ -185,8 +200,9 @@ public void setUp() {
mSnippetsSource = new FakeSnippetsSource();
mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.INITIALIZING);
mSnippetsSource.setInfoForCategory(
- KnownCategories.ARTICLES, new SuggestionsCategoryInfo("Articles for you",
- ContentSuggestionsCardLayout.FULL_CARD, false));
+ KnownCategories.ARTICLES,
+ new SuggestionsCategoryInfo(
+ "Articles for you", ContentSuggestionsCardLayout.FULL_CARD, false, true));
mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
}
@@ -415,6 +431,63 @@ public void testUIUntouchedWhenNotProvided() {
assertItemsFor();
}
+ // TODO(dgn): Properly make this a test based on handling different CategoryInfo when we
+ // stop hardcoding things in sections.
+ @Test
+ @Feature({"Ntp"})
+ public void testSectionVisibility() {
+ mSnippetsSource.setStatusForCategory(
+ KnownCategories.BOOKMARKS, CategoryStatus.INITIALIZING);
+ mSnippetsSource.setInfoForCategory(
+ KnownCategories.BOOKMARKS,
+ new SuggestionsCategoryInfo("Recent bookmarks",
+ ContentSuggestionsCardLayout.MINIMAL_CARD, true, false));
+
+ // Part 1: Test ARTICLES.
+
+ // The |ARTICLES| section should be shown even if we don't receive any suggestion for it.
+ mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSnippetsSource.setSuggestionsForCategory(
+ KnownCategories.ARTICLES, Collections.<SnippetArticle>emptyList());
+ assertItemsFor(sectionWithStatusCard());
+
+ // Make sure we show the articles when we load them.
+ List<SnippetArticle> articles = createDummySnippets(3);
+ mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, articles);
+ assertItemsFor(section(3));
+
+ // When we dismiss them, we should have the status card coming back.
+ int indexOfFirstItemOfArticlesGroup = 1;
+ SuggestionsSection section =
+ (SuggestionsSection) mNtpAdapter.getGroup(indexOfFirstItemOfArticlesGroup);
+ assertEquals(section.getItems().size(), section(3));
+ section.dismissSuggestion(articles.get(0));
+ section.dismissSuggestion(articles.get(1));
+ section.dismissSuggestion(articles.get(2));
+ assertItemsFor(sectionWithStatusCard());
+
+ // Part 2: Test BOOKMARKS.
+
+ // The |BOOKMARKS| section should not be shown if we don't receive any suggestion for it.
+ mSnippetsSource.setStatusForCategory(KnownCategories.BOOKMARKS, CategoryStatus.AVAILABLE);
+ mSnippetsSource.setSuggestionsForCategory(
+ KnownCategories.BOOKMARKS, Collections.<SnippetArticle>emptyList());
+ assertItemsFor(sectionHidden(), sectionWithStatusCard());
+
+ // When we get some, make sure we show the button.
+ mSnippetsSource.setSuggestionsForCategory(KnownCategories.BOOKMARKS, articles);
+ assertItemsFor(sectionWithMoreButton(3), sectionWithStatusCard());
+
+ // When we dismiss snippets, we should still keep the button.
+ int indexOfFirstItemOfBookmarksGroup = 3;
+ section = (SuggestionsSection) mNtpAdapter.getGroup(indexOfFirstItemOfBookmarksGroup);
+ assertEquals(section.getItems().size(), sectionWithMoreButton(3));
+ section.dismissSuggestion(articles.get(0));
+ section.dismissSuggestion(articles.get(1));
+ section.dismissSuggestion(articles.get(2));
+ assertItemsFor(sectionWithStatusCardAndMoreButton(), sectionWithStatusCard());
+ }
+
@Test
@Feature({"Ntp"})
public void testMoreButton() {
@@ -426,7 +499,7 @@ public void testMoreButton() {
List<SnippetArticle> bookmarks = createDummySnippets(10);
mSnippetsSource.setInfoForCategory(KnownCategories.BOOKMARKS,
new SuggestionsCategoryInfo("Bookmarks", ContentSuggestionsCardLayout.MINIMAL_CARD,
- true));
+ true, false));
mSnippetsSource.setStatusForCategory(KnownCategories.BOOKMARKS, CategoryStatus.AVAILABLE);
mSnippetsSource.setSuggestionsForCategory(KnownCategories.BOOKMARKS, bookmarks);
assertItemsFor(sectionWithMoreButton(10), section(3));

Powered by Google App Engine
This is Rietveld 408576698