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

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

Issue 2275693003: Ntp: show footer with learn more link. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@9patches
Patch Set: Use the intended url. 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
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 47fadbc0fcad933dab1e5faef3cf01433e60ea9b..c53b9a01cd44112b63fc5d037f32d17b80f5f1e2 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
@@ -39,24 +39,24 @@ public class NewTabPageAdapterTest {
org.robolectric.shadows.ShadowLog.stream = System.out;
}
- private FakeSuggestionsSource mSnippetsSource = new FakeSuggestionsSource();
- private NewTabPageAdapter mNtpAdapter;
+ private FakeSuggestionsSource mSource;
+ private NewTabPageAdapter mAdapter;
/**
- * Asserts that {@link #mNtpAdapter}.{@link NewTabPageAdapter#getItemCount()} corresponds to an
+ * Asserts that {@link #mAdapter}.{@link NewTabPageAdapter#getItemCount()} corresponds to an
* NTP with the given sections in it.
* @param sections A list of sections, each represented by the number of items that are required
- * to represent it on the UI. For readability, these numbers should be generated
+ * to represent it in the UI. For readability, these numbers should be generated
* with the methods below.
*/
private void assertItemsFor(int... sections) {
int expectedCount = 1; // above-the-fold.
for (int section : sections) expectedCount += section;
- if (sections.length > 0) expectedCount += 1; // bottom spacer.
- int actualCount = mNtpAdapter.getItemCount();
+ if (sections.length > 0) expectedCount += 2; // footer and bottom spacer.
+ int actualCount = mAdapter.getItemCount();
assertEquals("Expected " + expectedCount + " items, but the following " + actualCount
- + " were present: " + mNtpAdapter.getItems(),
- expectedCount, mNtpAdapter.getItemCount());
+ + " were present: " + mAdapter.getItems(),
+ expectedCount, mAdapter.getItemCount());
}
/**
@@ -95,14 +95,6 @@ public class NewTabPageAdapterTest {
}
/**
- * 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.
@@ -116,156 +108,153 @@ public class NewTabPageAdapterTest {
RecordHistogram.disableForTests();
RecordUserAction.disableForTests();
- mSnippetsSource = new FakeSuggestionsSource();
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.INITIALIZING);
- mSnippetsSource.setInfoForCategory(
- KnownCategories.ARTICLES,
- new SuggestionsCategoryInfo(
- "Articles for you", ContentSuggestionsCardLayout.FULL_CARD, false, true));
- mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
+ mSource = new FakeSuggestionsSource();
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.INITIALIZING);
+ mSource.setInfoForCategory(KnownCategories.ARTICLES,
+ new SuggestionsCategoryInfo("Articles for you",
+ ContentSuggestionsCardLayout.FULL_CARD, false, true));
+ mAdapter = new NewTabPageAdapter(null, null, mSource, null);
}
/**
- * Tests the content of the adapter under standard conditions: on start and after a snippet
+ * Tests the content of the adapter under standard conditions: on start and after a suggestions
* fetch.
*/
@Test
@Feature({"Ntp"})
- public void testSnippetLoading() {
+ public void testSuggestionLoading() {
assertItemsFor(sectionWithStatusCard());
- assertEquals(NewTabPageItem.VIEW_TYPE_ABOVE_THE_FOLD, mNtpAdapter.getItemViewType(0));
- assertEquals(NewTabPageItem.VIEW_TYPE_HEADER, mNtpAdapter.getItemViewType(1));
- assertEquals(NewTabPageItem.VIEW_TYPE_STATUS, mNtpAdapter.getItemViewType(2));
- assertEquals(NewTabPageItem.VIEW_TYPE_PROGRESS, mNtpAdapter.getItemViewType(3));
- assertEquals(NewTabPageItem.VIEW_TYPE_SPACING, mNtpAdapter.getItemViewType(4));
-
- List<SnippetArticle> snippets = createDummySnippets(3);
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
-
- List<NewTabPageItem> loadedItems = new ArrayList<>(mNtpAdapter.getItems());
- assertEquals(NewTabPageItem.VIEW_TYPE_ABOVE_THE_FOLD, mNtpAdapter.getItemViewType(0));
- assertEquals(NewTabPageItem.VIEW_TYPE_HEADER, mNtpAdapter.getItemViewType(1));
+ assertEquals(NewTabPageItem.VIEW_TYPE_ABOVE_THE_FOLD, mAdapter.getItemViewType(0));
+ assertEquals(NewTabPageItem.VIEW_TYPE_HEADER, mAdapter.getItemViewType(1));
+ assertEquals(NewTabPageItem.VIEW_TYPE_STATUS, mAdapter.getItemViewType(2));
+ assertEquals(NewTabPageItem.VIEW_TYPE_PROGRESS, mAdapter.getItemViewType(3));
+ assertEquals(NewTabPageItem.VIEW_TYPE_FOOTER, mAdapter.getItemViewType(4));
+ assertEquals(NewTabPageItem.VIEW_TYPE_SPACING, mAdapter.getItemViewType(5));
+
+ List<SnippetArticle> suggestions = createDummySuggestions(3);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
+
+ List<NewTabPageItem> loadedItems = new ArrayList<>(mAdapter.getItems());
+ assertEquals(NewTabPageItem.VIEW_TYPE_ABOVE_THE_FOLD, mAdapter.getItemViewType(0));
+ assertEquals(NewTabPageItem.VIEW_TYPE_HEADER, mAdapter.getItemViewType(1));
// From the loadedItems, cut out aboveTheFold and header from the front,
- // and bottom spacer from the back.
- assertEquals(snippets, loadedItems.subList(2, loadedItems.size() - 1));
- assertEquals(NewTabPageItem.VIEW_TYPE_SPACING,
- mNtpAdapter.getItemViewType(loadedItems.size() - 1));
+ // and footer and bottom spacer from the back.
+ assertEquals(suggestions, loadedItems.subList(2, loadedItems.size() - 2));
+ assertEquals(
+ NewTabPageItem.VIEW_TYPE_FOOTER, mAdapter.getItemViewType(loadedItems.size() - 2));
+ assertEquals(
+ NewTabPageItem.VIEW_TYPE_SPACING, mAdapter.getItemViewType(loadedItems.size() - 1));
// The adapter should ignore any new incoming data.
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES,
- Arrays.asList(new SnippetArticle[] {new SnippetArticle(
- 0, "foo", "title1", "pub1", "txt1", "foo", "bar", 0, 0, 0,
- ContentSuggestionsCardLayout.FULL_CARD)}));
- assertEquals(loadedItems, mNtpAdapter.getItems());
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES,
+ Arrays.asList(new SnippetArticle[] {new SnippetArticle(0, "foo", "title1", "pub1",
+ "txt1", "foo", "bar", 0, 0, 0, ContentSuggestionsCardLayout.FULL_CARD)}));
+ assertEquals(loadedItems, mAdapter.getItems());
}
/**
- * Tests that the adapter keeps listening for snippet updates if it didn't get anything from
+ * Tests that the adapter keeps listening for suggestion updates if it didn't get anything from
* a previous fetch.
*/
@Test
@Feature({"Ntp"})
- public void testSnippetLoadingInitiallyEmpty() {
+ public void testSuggestionLoadingInitiallyEmpty() {
// If we don't get anything, we should be in the same situation as the initial one.
- mSnippetsSource.setSuggestionsForCategory(
+ mSource.setSuggestionsForCategory(
KnownCategories.ARTICLES, new ArrayList<SnippetArticle>());
assertItemsFor(sectionWithStatusCard());
- assertEquals(NewTabPageItem.VIEW_TYPE_ABOVE_THE_FOLD, mNtpAdapter.getItemViewType(0));
- assertEquals(NewTabPageItem.VIEW_TYPE_HEADER, mNtpAdapter.getItemViewType(1));
- assertEquals(NewTabPageItem.VIEW_TYPE_STATUS, mNtpAdapter.getItemViewType(2));
- assertEquals(NewTabPageItem.VIEW_TYPE_PROGRESS, mNtpAdapter.getItemViewType(3));
- assertEquals(NewTabPageItem.VIEW_TYPE_SPACING, mNtpAdapter.getItemViewType(4));
-
- // We should load new snippets when we get notified about them.
- List<SnippetArticle> snippets = createDummySnippets(5);
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
- List<NewTabPageItem> loadedItems = new ArrayList<>(mNtpAdapter.getItems());
- assertEquals(NewTabPageItem.VIEW_TYPE_ABOVE_THE_FOLD, mNtpAdapter.getItemViewType(0));
- assertEquals(NewTabPageItem.VIEW_TYPE_HEADER, mNtpAdapter.getItemViewType(1));
+ assertEquals(NewTabPageItem.VIEW_TYPE_ABOVE_THE_FOLD, mAdapter.getItemViewType(0));
+ assertEquals(NewTabPageItem.VIEW_TYPE_HEADER, mAdapter.getItemViewType(1));
+ assertEquals(NewTabPageItem.VIEW_TYPE_STATUS, mAdapter.getItemViewType(2));
+ assertEquals(NewTabPageItem.VIEW_TYPE_PROGRESS, mAdapter.getItemViewType(3));
+ assertEquals(NewTabPageItem.VIEW_TYPE_FOOTER, mAdapter.getItemViewType(4));
+ assertEquals(NewTabPageItem.VIEW_TYPE_SPACING, mAdapter.getItemViewType(5));
+
+ // We should load new suggestions when we get notified about them.
+ List<SnippetArticle> suggestions = createDummySuggestions(5);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
+ List<NewTabPageItem> loadedItems = new ArrayList<>(mAdapter.getItems());
+ assertEquals(NewTabPageItem.VIEW_TYPE_ABOVE_THE_FOLD, mAdapter.getItemViewType(0));
+ assertEquals(NewTabPageItem.VIEW_TYPE_HEADER, mAdapter.getItemViewType(1));
// From the loadedItems, cut out aboveTheFold and header from the front,
- // and bottom spacer from the back.
- assertEquals(snippets, loadedItems.subList(2, loadedItems.size() - 1));
- assertEquals(NewTabPageItem.VIEW_TYPE_SPACING,
- mNtpAdapter.getItemViewType(loadedItems.size() - 1));
+ // and footer and bottom spacer from the back.
+ assertEquals(suggestions, loadedItems.subList(2, loadedItems.size() - 2));
+ assertEquals(
+ NewTabPageItem.VIEW_TYPE_FOOTER, mAdapter.getItemViewType(loadedItems.size() - 2));
+ assertEquals(
+ NewTabPageItem.VIEW_TYPE_SPACING, mAdapter.getItemViewType(loadedItems.size() - 1));
// The adapter should ignore any new incoming data.
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES,
- Arrays.asList(new SnippetArticle[] {new SnippetArticle(
- 0, "foo", "title1", "pub1", "txt1", "foo", "bar", 0, 0, 0,
- ContentSuggestionsCardLayout.FULL_CARD)}));
- assertEquals(loadedItems, mNtpAdapter.getItems());
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES,
+ Arrays.asList(new SnippetArticle[] {new SnippetArticle(0, "foo", "title1", "pub1",
+ "txt1", "foo", "bar", 0, 0, 0, ContentSuggestionsCardLayout.FULL_CARD)}));
+ assertEquals(loadedItems, mAdapter.getItems());
}
/**
- * Tests that the adapter clears the snippets when asked to.
+ * Tests that the adapter clears the suggestions when asked to.
*/
@Test
@Feature({"Ntp"})
- public void testSnippetClearing() {
- List<SnippetArticle> snippets = createDummySnippets(4);
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ public void testSuggestionClearing() {
+ List<SnippetArticle> suggestions = createDummySuggestions(4);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
assertItemsFor(section(4));
- // If we get told that snippets are enabled, we just leave the current
- // ones there and not clear.
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.AVAILABLE);
+ // If we get told that the category is enabled, we just leave the current suggestions do not
+ // clear them.
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
assertItemsFor(section(4));
- // When snippets are disabled, we clear them and we should go back to
+ // When the category is disabled, the suggestions are cleared and we should go back to
// the situation with the status card.
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.SIGNED_OUT);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.SIGNED_OUT);
assertItemsFor(sectionWithStatusCard());
- // The adapter should now be waiting for new snippets.
- snippets = createDummySnippets(6);
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ // The adapter should now be waiting for new suggestions.
+ suggestions = createDummySuggestions(6);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
assertItemsFor(section(6));
}
/**
- * Tests that the adapter loads snippets only when the status is favorable.
+ * Tests that the adapter loads suggestions only when the status is favorable.
*/
@Test
@Feature({"Ntp"})
- public void testSnippetLoadingBlock() {
- List<SnippetArticle> snippets = createDummySnippets(3);
+ public void testSuggestionLoadingBlock() {
+ List<SnippetArticle> suggestions = createDummySuggestions(3);
- // By default, status is INITIALIZING, so we can load snippets
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ // By default, status is INITIALIZING, so we can load suggestions.
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
assertItemsFor(section(3));
// If we have snippets, we should not load the new list (i.e. the extra item does *not*
// appear).
- snippets.add(new SnippetArticle(0, "https://site.com/url1", "title1", "pub1", "txt1",
+ suggestions.add(new SnippetArticle(0, "https://site.com/url1", "title1", "pub1", "txt1",
"https://site.com/url1", "https://amp.site.com/url1", 0, 0, 0,
ContentSuggestionsCardLayout.FULL_CARD));
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
assertItemsFor(section(3));
// When snippets are disabled, we should not be able to load them.
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.SIGNED_OUT);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.SIGNED_OUT);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
assertItemsFor(sectionWithStatusCard());
// INITIALIZING lets us load snippets still.
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.INITIALIZING);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.INITIALIZING);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
assertItemsFor(sectionWithStatusCard());
// The adapter should now be waiting for new snippets and the fourth one should appear.
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, suggestions);
assertItemsFor(section(4));
}
@@ -275,23 +264,19 @@ public class NewTabPageAdapterTest {
@Test
@Feature({"Ntp"})
public void testProgressIndicatorDisplay() {
- int progressPos = mNtpAdapter.getBottomSpacerPosition() - 1;
- ProgressItem progress = (ProgressItem) mNtpAdapter.getItems().get(progressPos);
+ int progressPos = mAdapter.getLastContentItemPosition() - 1;
+ ProgressItem progress = (ProgressItem) mAdapter.getItems().get(progressPos);
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.INITIALIZING);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.INITIALIZING);
assertTrue(progress.isVisible());
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.AVAILABLE);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
assertFalse(progress.isVisible());
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.AVAILABLE_LOADING);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE_LOADING);
assertTrue(progress.isVisible());
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.SIGNED_OUT);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.SIGNED_OUT);
assertFalse(progress.isVisible());
}
@@ -302,31 +287,30 @@ public class NewTabPageAdapterTest {
@Test
@Feature({"Ntp"})
public void testSectionClearingWhenUnavailable() {
- List<SnippetArticle> snippets = createDummySnippets(5);
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ List<SnippetArticle> snippets = createDummySuggestions(5);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
assertItemsFor(section(5));
// When the category goes away with a hard error, the section is cleared from the UI.
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.LOADING_ERROR);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.LOADING_ERROR);
assertItemsFor();
// Same when loading a new NTP.
- mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
+ mAdapter = new NewTabPageAdapter(null, null, mSource, null);
assertItemsFor();
// Same for CATEGORY_EXPLICITLY_DISABLED.
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
- mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ mAdapter = new NewTabPageAdapter(null, null, mSource, null);
assertItemsFor(section(5));
- mSnippetsSource.setStatusForCategory(
+ mSource.setStatusForCategory(
KnownCategories.ARTICLES, CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
assertItemsFor();
// Same when loading a new NTP.
- mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
+ mAdapter = new NewTabPageAdapter(null, null, mSource, null);
assertItemsFor();
}
@@ -336,18 +320,18 @@ public class NewTabPageAdapterTest {
@Test
@Feature({"Ntp"})
public void testUIUntouchedWhenNotProvided() {
- List<SnippetArticle> snippets = createDummySnippets(4);
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ List<SnippetArticle> snippets = createDummySuggestions(4);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
assertItemsFor(section(4));
// When the category switches to NOT_PROVIDED, UI stays the same.
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.NOT_PROVIDED);
- mSnippetsSource.silentlyRemoveCategory(KnownCategories.ARTICLES);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.NOT_PROVIDED);
+ mSource.silentlyRemoveCategory(KnownCategories.ARTICLES);
assertItemsFor(section(4));
// But it disappears when loading a new NTP.
- mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
+ mAdapter = new NewTabPageAdapter(null, null, mSource, null);
assertItemsFor();
}
@@ -356,7 +340,8 @@ public class NewTabPageAdapterTest {
public void testSectionVisibleIfEmpty() {
final int category = 42;
final int sectionIdx = 1; // section 0 is the above-the-fold item, we test the one after.
- final List<SnippetArticle> articles = Collections.unmodifiableList(createDummySnippets(3));
+ final List<SnippetArticle> articles =
+ Collections.unmodifiableList(createDummySuggestions(3));
FakeSuggestionsSource suggestionsSource;
SuggestionsSection section;
@@ -368,7 +353,7 @@ public class NewTabPageAdapterTest {
"", ContentSuggestionsCardLayout.MINIMAL_CARD, false, true));
// 1.1 - Initial state
- mNtpAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
+ mAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
assertItemsFor(sectionWithStatusCard());
// 1.2 - With suggestions
@@ -377,8 +362,8 @@ public class NewTabPageAdapterTest {
assertItemsFor(section(3));
// 1.3 - When all suggestions are dismissed
- assertEquals(SuggestionsSection.class, mNtpAdapter.getGroups().get(sectionIdx).getClass());
- section = (SuggestionsSection) mNtpAdapter.getGroups().get(sectionIdx);
+ assertEquals(SuggestionsSection.class, mAdapter.getGroups().get(sectionIdx).getClass());
+ section = (SuggestionsSection) mAdapter.getGroups().get(sectionIdx);
assertEquals(section(3), section.getItems().size());
section.removeSuggestion(articles.get(0));
section.removeSuggestion(articles.get(1));
@@ -393,7 +378,7 @@ public class NewTabPageAdapterTest {
"", ContentSuggestionsCardLayout.MINIMAL_CARD, false, false));
// 2.1 - Initial state
- mNtpAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
+ mAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
assertItemsFor();
// 2.2 - With suggestions
@@ -412,7 +397,8 @@ public class NewTabPageAdapterTest {
public void testMoreButton() {
final int category = 42;
final int sectionIdx = 1; // section 0 is the above the fold, we test the one after.
- final List<SnippetArticle> articles = Collections.unmodifiableList(createDummySnippets(3));
+ final List<SnippetArticle> articles =
+ Collections.unmodifiableList(createDummySuggestions(3));
FakeSuggestionsSource suggestionsSource;
SuggestionsSection section;
@@ -424,7 +410,7 @@ public class NewTabPageAdapterTest {
"", ContentSuggestionsCardLayout.MINIMAL_CARD, true, true));
// 1.1 - Initial state.
- mNtpAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
+ mAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
assertItemsFor(sectionWithStatusCardAndMoreButton());
// 1.2 - With suggestions.
@@ -433,8 +419,8 @@ public class NewTabPageAdapterTest {
assertItemsFor(sectionWithMoreButton(3));
// 1.3 - When all suggestions are dismissed.
- assertEquals(SuggestionsSection.class, mNtpAdapter.getGroups().get(sectionIdx).getClass());
- section = (SuggestionsSection) mNtpAdapter.getGroups().get(sectionIdx);
+ assertEquals(SuggestionsSection.class, mAdapter.getGroups().get(sectionIdx).getClass());
+ section = (SuggestionsSection) mAdapter.getGroups().get(sectionIdx);
assertEquals(sectionWithMoreButton(3), section.getItems().size());
section.removeSuggestion(articles.get(0));
section.removeSuggestion(articles.get(1));
@@ -449,7 +435,7 @@ public class NewTabPageAdapterTest {
"", ContentSuggestionsCardLayout.MINIMAL_CARD, false, true));
// 2.1 - Initial state.
- mNtpAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
+ mAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
assertItemsFor(sectionWithStatusCard());
// 2.2 - With suggestions.
@@ -458,8 +444,8 @@ public class NewTabPageAdapterTest {
assertItemsFor(section(3));
// 2.3 - When all suggestions are dismissed.
- assertEquals(SuggestionsSection.class, mNtpAdapter.getGroups().get(sectionIdx).getClass());
- section = (SuggestionsSection) mNtpAdapter.getGroups().get(sectionIdx);
+ assertEquals(SuggestionsSection.class, mAdapter.getGroups().get(sectionIdx).getClass());
+ section = (SuggestionsSection) mAdapter.getGroups().get(sectionIdx);
assertEquals(section(3), section.getItems().size());
section.removeSuggestion(articles.get(0));
section.removeSuggestion(articles.get(1));
@@ -473,15 +459,15 @@ public class NewTabPageAdapterTest {
@Test
@Feature({"Ntp"})
public void testSuggestionInvalidated() {
- List<SnippetArticle> articles = createDummySnippets(3);
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
- mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, articles);
+ List<SnippetArticle> articles = createDummySuggestions(3);
+ mSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSource.setSuggestionsForCategory(KnownCategories.ARTICLES, articles);
assertItemsFor(section(3));
- assertEquals(articles, mNtpAdapter.getItems().subList(2, 5));
+ assertEquals(articles, mAdapter.getItems().subList(2, 5));
SnippetArticle removed = articles.remove(1);
- mSnippetsSource.fireSuggestionInvalidated(KnownCategories.ARTICLES, removed.mId);
- assertEquals(articles, mNtpAdapter.getItems().subList(2, 4));
+ mSource.fireSuggestionInvalidated(KnownCategories.ARTICLES, removed.mId);
+ assertEquals(articles, mAdapter.getItems().subList(2, 4));
}
/**
@@ -499,7 +485,7 @@ public class NewTabPageAdapterTest {
NewTabPageAdapter ntpAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
List<ItemGroup> groups = ntpAdapter.getGroups();
- assertEquals(6, groups.size());
+ assertEquals(7, groups.size());
assertEquals(AboveTheFoldItem.class, groups.get(0).getClass());
assertEquals(SuggestionsSection.class, groups.get(1).getClass());
assertEquals(KnownCategories.ARTICLES, getCategory(groups.get(1)));
@@ -520,7 +506,7 @@ public class NewTabPageAdapterTest {
ntpAdapter = new NewTabPageAdapter(null, null, suggestionsSource, null);
groups = ntpAdapter.getGroups();
- assertEquals(6, groups.size());
+ assertEquals(7, groups.size());
assertEquals(AboveTheFoldItem.class, groups.get(0).getClass());
assertEquals(SuggestionsSection.class, groups.get(1).getClass());
assertEquals(KnownCategories.ARTICLES, getCategory(groups.get(1)));
@@ -545,7 +531,7 @@ public class NewTabPageAdapterTest {
groups = ntpAdapter.getGroups();
- assertEquals(5, groups.size());
+ assertEquals(6, groups.size());
assertEquals(AboveTheFoldItem.class, groups.get(0).getClass());
assertEquals(SuggestionsSection.class, groups.get(1).getClass());
assertEquals(KnownCategories.ARTICLES, getCategory(groups.get(1)));
@@ -555,27 +541,29 @@ public class NewTabPageAdapterTest {
assertEquals(KnownCategories.DOWNLOADS, getCategory(groups.get(3)));
}
- private List<SnippetArticle> createDummySnippets(int count) {
- List<SnippetArticle> snippets = new ArrayList<>();
+ private List<SnippetArticle> createDummySuggestions(int count) {
+ List<SnippetArticle> suggestions = new ArrayList<>();
for (int index = 0; index < count; index++) {
- snippets.add(new SnippetArticle(0, "https://site.com/url" + index, "title" + index,
+ suggestions.add(new SnippetArticle(0, "https://site.com/url" + index, "title" + index,
"pub" + index, "txt" + index, "https://site.com/url" + index,
"https://amp.site.com/url" + index, 0, 0, 0,
ContentSuggestionsCardLayout.FULL_CARD));
}
- return snippets;
+ return suggestions;
}
/** Registers the category with hasMoreButton=false and showIfEmpty=true*/
private void registerCategory(FakeSuggestionsSource suggestionsSource,
@CategoryInt int category, int suggestionCount) {
- // FakeSuggestionSource does not provide snippets if the category's status is not available.
+ // FakeSuggestionSource does not provide suggestions if the category's status is not
+ // AVAILABLE.
suggestionsSource.setStatusForCategory(category, CategoryStatus.AVAILABLE);
// Important: showIfEmpty flag to true.
suggestionsSource.setInfoForCategory(
category, new SuggestionsCategoryInfo(
"", ContentSuggestionsCardLayout.FULL_CARD, false, true));
- suggestionsSource.setSuggestionsForCategory(category, createDummySnippets(suggestionCount));
+ suggestionsSource.setSuggestionsForCategory(
+ category, createDummySuggestions(suggestionCount));
}
private int getCategory(ItemGroup itemGroup) {
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698