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

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

Issue 2663313002: 📰 Merge the has_fetch_more and has_reload actions (Closed)
Patch Set: fix tests pt 2 Created 3 years, 11 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/SuggestionsSectionTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSectionTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSectionTest.java
index 198e424eff679497d1bc0862fb25483b6dbcb1b8..31e2f13faaeb40c3b0b0c6316dba3191c360d2e4 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSectionTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSectionTest.java
@@ -95,7 +95,7 @@ public void setUp() {
@EnableFeatures(ChromeFeatureList.NTP_SUGGESTIONS_SECTION_DISMISSAL)
public void testDismissSibling() {
List<SnippetArticle> snippets = createDummySuggestions(3, TEST_CATEGORY_ID);
- SuggestionsSection section = createSectionWithReloadAction(true);
+ SuggestionsSection section = createSectionWithFetchAction(true);
section.setStatus(CategoryStatus.AVAILABLE);
assertNotNull(section.getActionItemForTesting());
@@ -121,7 +121,7 @@ public void testDismissSibling() {
@EnableFeatures({})
public void testDismissSiblingWithSectionDismissalDisabled() {
List<SnippetArticle> snippets = createDummySuggestions(3, TEST_CATEGORY_ID);
- SuggestionsSection section = createSectionWithReloadAction(true);
+ SuggestionsSection section = createSectionWithFetchAction(true);
section.setStatus(CategoryStatus.AVAILABLE);
assertNotNull(section.getActionItemForTesting());
@@ -149,7 +149,7 @@ public void testAddSuggestionsNotification() {
List<SnippetArticle> snippets = createDummySuggestions(suggestionCount,
TEST_CATEGORY_ID);
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
// Simulate initialisation by the adapter. Here we don't care about the notifications, since
// the RecyclerView will be updated through notifyDataSetChanged.
section.setStatus(CategoryStatus.AVAILABLE);
@@ -169,7 +169,7 @@ public void testSetStatusNotification() {
final int suggestionCount = 5;
List<SnippetArticle> snippets = createDummySuggestions(suggestionCount,
TEST_CATEGORY_ID);
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
// Simulate initialisation by the adapter. Here we don't care about the notifications, since
// the RecyclerView will be updated through notifyDataSetChanged.
@@ -196,7 +196,7 @@ public void testSetStatusNotification() {
@Test
@Feature({"Ntp"})
public void testRemoveUnknownSuggestion() {
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
section.setStatus(CategoryStatus.AVAILABLE);
section.removeSuggestionById("foobar");
}
@@ -208,7 +208,7 @@ public void testRemoveSuggestionNotification() {
List<SnippetArticle> snippets = createDummySuggestions(suggestionCount,
TEST_CATEGORY_ID);
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
section.setStatus(CategoryStatus.AVAILABLE);
reset(mParent);
@@ -233,11 +233,7 @@ public void testRemoveSuggestionNotificationWithButton() {
TEST_CATEGORY_ID);
SuggestionsCategoryInfo info =
- new CategoryInfoBuilder(TEST_CATEGORY_ID)
- .withMoreAction()
- .withReloadAction()
- .showIfEmpty()
- .build();
+ new CategoryInfoBuilder(TEST_CATEGORY_ID).withFetchAction().showIfEmpty().build();
SuggestionsSection section = createSection(info);
section.setStatus(CategoryStatus.AVAILABLE);
reset(mParent);
@@ -261,7 +257,7 @@ public void testRemoveSuggestionNotificationWithButton() {
@Feature({"Ntp"})
@EnableFeatures({ChromeFeatureList.NTP_SUGGESTIONS_SECTION_DISMISSAL})
public void testDismissSection() {
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
section.setStatus(CategoryStatus.AVAILABLE);
reset(mParent);
assertEquals(2, section.getItemCount());
@@ -289,7 +285,7 @@ public void testOfflineStatus() {
mBridge.setIsOfflinePageModelLoaded(true);
mBridge.setItems(Arrays.asList(item0, item1));
- SuggestionsSection section = createSectionWithReloadAction(true);
+ SuggestionsSection section = createSectionWithFetchAction(true);
section.setSuggestions(snippets, CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
// Check that we pick up the correct information.
@@ -345,13 +341,11 @@ public void testViewAllActionPriority() {
// When all the actions are enabled, ViewAll always has the priority and is shown.
// Spy so that VerifyAction can check methods being called.
- SuggestionsCategoryInfo info =
- spy(new CategoryInfoBuilder(TEST_CATEGORY_ID)
- .withMoreAction()
- .withReloadAction()
- .withViewAllAction()
- .showIfEmpty()
- .build());
+ SuggestionsCategoryInfo info = spy(new CategoryInfoBuilder(TEST_CATEGORY_ID)
+ .withFetchAction()
+ .withViewAllAction()
+ .showIfEmpty()
+ .build());
SuggestionsSection section = createSection(info);
assertTrue(section.getActionItemForTesting().isVisible());
@@ -366,67 +360,22 @@ public void testViewAllActionPriority() {
@Test
@Feature({"Ntp"})
- public void testReloadAndFetchMoreActionPriority() {
- // When both Reload and FetchMore are enabled, FetchMore runs when we have suggestions, and
- // Reload when we don't.
-
- // Spy so that VerifyAction can check methods being called.
- SuggestionsCategoryInfo info =
- spy(new CategoryInfoBuilder(TEST_CATEGORY_ID)
- .withMoreAction()
- .withReloadAction()
- .showIfEmpty()
- .build());
- SuggestionsSection section = createSection(info);
-
- assertTrue(section.getActionItemForTesting().isVisible());
- verifyAction(section, ActionItem.ACTION_RELOAD);
-
- section.setSuggestions(createDummySuggestions(3, TEST_CATEGORY_ID),
- CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
-
- assertTrue(section.getActionItemForTesting().isVisible());
- verifyAction(section, ActionItem.ACTION_FETCH_MORE);
- }
-
- @Test
- @Feature({"Ntp"})
- public void testReloadActionPriority() {
- // When only Reload is enabled, it only shows when we have no suggestions.
+ public void testFetchActionPriority() {
dgn 2017/02/01 13:27:58 Not sure if I should remove the suggestion count d
Bernhard Bauer 2017/02/01 14:11:06 Yeah, I think that would make sense… It is intenti
dgn 2017/02/01 18:01:52 Done.
+ // When only FetchMore is enabled, it shows whether we have suggestions or not.
// Spy so that VerifyAction can check methods being called.
SuggestionsCategoryInfo info = spy(
- new CategoryInfoBuilder(TEST_CATEGORY_ID).withReloadAction().showIfEmpty().build());
+ new CategoryInfoBuilder(TEST_CATEGORY_ID).withFetchAction().showIfEmpty().build());
SuggestionsSection section = createSection(info);
assertTrue(section.getActionItemForTesting().isVisible());
- verifyAction(section, ActionItem.ACTION_RELOAD);
-
- section.setSuggestions(createDummySuggestions(3, TEST_CATEGORY_ID),
- CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
-
- assertFalse(section.getActionItemForTesting().isVisible());
- verifyAction(section, ActionItem.ACTION_NONE);
- }
-
- @Test
- @Feature({"Ntp"})
- public void testFetchMoreActionPriority() {
- // When only FetchMore is enabled, it only shows when we have suggestions.
-
- // Spy so that VerifyAction can check methods being called.
- SuggestionsCategoryInfo info = spy(
- new CategoryInfoBuilder(TEST_CATEGORY_ID).withMoreAction().showIfEmpty().build());
- SuggestionsSection section = createSection(info);
-
- assertFalse(section.getActionItemForTesting().isVisible());
- verifyAction(section, ActionItem.ACTION_NONE);
+ verifyAction(section, ActionItem.ACTION_FETCH);
section.setSuggestions(createDummySuggestions(3, TEST_CATEGORY_ID),
CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
assertTrue(section.getActionItemForTesting().isVisible());
- verifyAction(section, ActionItem.ACTION_FETCH_MORE);
+ verifyAction(section, ActionItem.ACTION_FETCH);
}
@Test
@@ -454,14 +403,14 @@ public void testNoAction() {
public void testFetchMoreProgressDisplay() {
final int suggestionCount = 3;
SuggestionsCategoryInfo info = spy(
- new CategoryInfoBuilder(TEST_CATEGORY_ID).withMoreAction().showIfEmpty().build());
+ new CategoryInfoBuilder(TEST_CATEGORY_ID).withFetchAction().showIfEmpty().build());
SuggestionsSection section = createSection(info);
section.setSuggestions(createDummySuggestions(suggestionCount, TEST_CATEGORY_ID),
CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
assertFalse(section.getProgressItemForTesting().isVisible());
// Tap the button
- verifyAction(section, ActionItem.ACTION_FETCH_MORE);
+ verifyAction(section, ActionItem.ACTION_FETCH);
assertTrue(section.getProgressItemForTesting().isVisible());
// Simulate receiving suggestions.
@@ -687,7 +636,7 @@ public void testSectionDoesNotUpdateOnNewSuggestionsWhenAppended() {
@Feature({"Ntp"})
public void testCardIsNotifiedWhenBecomingFirst() {
List<SnippetArticle> suggestions = createDummySuggestions(5, /* categoryId = */ 42);
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
section.setSuggestions(suggestions, CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
reset(mParent);
@@ -700,7 +649,7 @@ public void testCardIsNotifiedWhenBecomingFirst() {
@Feature({"Ntp"})
public void testCardIsNotifiedWhenBecomingLast() {
List<SnippetArticle> suggestions = createDummySuggestions(5, /* categoryId = */ 42);
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
section.setSuggestions(suggestions, CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
reset(mParent);
@@ -713,7 +662,7 @@ public void testCardIsNotifiedWhenBecomingLast() {
@Feature({"Ntp"})
public void testCardIsNotifiedWhenBecomingSoleCard() {
List<SnippetArticle> suggestions = createDummySuggestions(2, /* categoryId = */ 42);
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
section.setSuggestions(suggestions, CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
reset(mParent);
@@ -727,7 +676,7 @@ public void testCardIsNotifiedWhenBecomingSoleCard() {
@EnableFeatures(ChromeFeatureList.NTP_SUGGESTIONS_SECTION_DISMISSAL)
public void testGetItemDismissalGroupWithSuggestions() {
List<SnippetArticle> suggestions = createDummySuggestions(5, TEST_CATEGORY_ID);
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
section.setSuggestions(suggestions, CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
assertThat(section.getItemDismissalGroup(1).size(), is(1));
@@ -738,7 +687,7 @@ public void testGetItemDismissalGroupWithSuggestions() {
@Feature({"Ntp"})
@EnableFeatures(ChromeFeatureList.NTP_SUGGESTIONS_SECTION_DISMISSAL)
public void testGetItemDismissalGroupWithActionItem() {
- SuggestionsSection section = createSectionWithReloadAction(true);
+ SuggestionsSection section = createSectionWithFetchAction(true);
assertThat(section.getItemDismissalGroup(1).size(), is(2));
assertThat(section.getItemDismissalGroup(1), contains(1, 2));
}
@@ -747,7 +696,7 @@ public void testGetItemDismissalGroupWithActionItem() {
@Feature({"Ntp"})
@EnableFeatures(ChromeFeatureList.NTP_SUGGESTIONS_SECTION_DISMISSAL)
public void testGetItemDismissalGroupWithoutActionItem() {
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
assertThat(section.getItemDismissalGroup(1).size(), is(1));
assertThat(section.getItemDismissalGroup(1), contains(1));
}
@@ -756,7 +705,7 @@ public void testGetItemDismissalGroupWithoutActionItem() {
@Feature({"Ntp"})
public void testCardIsNotifiedWhenNotTheLastAnymore() {
List<SnippetArticle> suggestions = createDummySuggestions(5, /* categoryId = */ 42);
- SuggestionsSection section = createSectionWithReloadAction(false);
+ SuggestionsSection section = createSectionWithFetchAction(false);
section.setSuggestions(suggestions, CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
reset(mParent);
@@ -767,7 +716,7 @@ public void testCardIsNotifiedWhenNotTheLastAnymore() {
}
private SuggestionsSection createSectionWithSuggestions(List<SnippetArticle> snippets) {
- SuggestionsSection section = createSectionWithReloadAction(true);
+ SuggestionsSection section = createSectionWithFetchAction(true);
section.setStatus(CategoryStatus.AVAILABLE);
section.setSuggestions(snippets, CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
@@ -784,9 +733,9 @@ private SuggestionsSection createSectionWithSuggestions(List<SnippetArticle> sni
return set;
}
- private SuggestionsSection createSectionWithReloadAction(boolean hasReloadAction) {
+ private SuggestionsSection createSectionWithFetchAction(boolean hasReloadAction) {
CategoryInfoBuilder builder = new CategoryInfoBuilder(TEST_CATEGORY_ID).showIfEmpty();
- if (hasReloadAction) builder.withReloadAction();
+ if (hasReloadAction) builder.withFetchAction();
return createSection(builder.build());
}
@@ -816,10 +765,7 @@ private static void verifyAction(SuggestionsSection section, @ActionItem.Action
verify(section.getCategoryInfo(),
(action == ActionItem.ACTION_VIEW_ALL ? times(1) : never()))
.performViewAllAction(navDelegate);
- verify(suggestionsSource,
- action == ActionItem.ACTION_RELOAD || action == ActionItem.ACTION_FETCH_MORE
- ? times(1)
- : never())
+ verify(suggestionsSource, (action == ActionItem.ACTION_FETCH ? times(1) : never()))
.fetchSuggestions(anyInt(), any(String[].class));
}

Powered by Google App Engine
This is Rietveld 408576698