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

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

Issue 2395203002: NTP cards: Restructure change notifications. (Closed)
Patch Set: x Created 4 years, 2 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/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.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/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 b79c074da4c22c6cf53316eb30650d3b43516bc2..c8f05d141f8d64f7599cd9dab6fd2b726c8b6b60 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
@@ -9,17 +9,18 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import static org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.createDummySuggestions;
-import static org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.createInfo;
import static org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.createSection;
import org.chromium.base.test.util.Feature;
@@ -40,14 +41,21 @@ public class SuggestionsSectionTest {
*/
private static final int EMPTY_SECTION_COUNT = 4;
+ @Mock
+ private ItemGroup.Observer mObserver;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
@Test
@Feature({"Ntp"})
public void testDismissSibling() {
- ItemGroup.Observer observerMock = mock(ItemGroup.Observer.class);
List<SnippetArticle> snippets = createDummySuggestions(3);
SuggestionsSection section;
- section = new SuggestionsSection(createInfo(42, true, true), observerMock);
+ section = ContentSuggestionsTestUtils.createSection(true, true, mObserver);
section.setStatus(CategoryStatus.AVAILABLE);
assertNotNull(section.getActionItem());
@@ -65,95 +73,97 @@ public class SuggestionsSectionTest {
@Test
@Feature({"Ntp"})
public void testSetSuggestionsNotification() {
- ItemGroup.Observer observerMock = mock(ItemGroup.Observer.class);
-
final int suggestionCount = 5;
List<SnippetArticle> snippets = createDummySuggestions(suggestionCount);
- SuggestionsSection section = createSection(false, true, observerMock);
+ SuggestionsSection section = createSection(false, true, mObserver);
// Note: when status is not initialised, we insert an item for the status card, but it's
// null!
assertEquals(EMPTY_SECTION_COUNT, section.getItems().size());
section.setSuggestions(snippets, CategoryStatus.AVAILABLE);
- verify(observerMock)
- .notifyGroupChanged(
- eq(section), eq(EMPTY_SECTION_COUNT), eq(suggestionCount + 1 /* header */));
+ verify(mObserver).onItemRangeChanged(section, 1, EMPTY_SECTION_COUNT - 1);
+ verify(mObserver).onItemRangeInserted(
+ section, EMPTY_SECTION_COUNT, suggestionCount - EMPTY_SECTION_COUNT + 1);
}
@Test
@Feature({"Ntp"})
public void testSetStatusNotification() {
- ItemGroup.Observer observerMock = mock(ItemGroup.Observer.class);
final int suggestionCount = 5;
List<SnippetArticle> snippets = createDummySuggestions(suggestionCount);
- SuggestionsSection section = createSection(false, true, observerMock);
+ SuggestionsSection section = createSection(false, true, mObserver);
section.setStatus(CategoryStatus.AVAILABLE);
- verify(observerMock)
- .notifyGroupChanged(eq(section), eq(EMPTY_SECTION_COUNT), eq(EMPTY_SECTION_COUNT));
+ verify(mObserver).onItemRangeChanged(section, 1, EMPTY_SECTION_COUNT - 1);
section.setSuggestions(snippets, CategoryStatus.AVAILABLE);
// We don't clear suggestions when the status is AVAILABLE.
section.setStatus(CategoryStatus.AVAILABLE);
- verify(observerMock)
- .notifyGroupChanged(eq(section), eq(suggestionCount + 1), eq(suggestionCount + 1));
+ verify(mObserver, times(2)).onItemRangeChanged(section, 1, EMPTY_SECTION_COUNT - 1);
+ verify(mObserver).onItemRangeInserted(
+ section, EMPTY_SECTION_COUNT, suggestionCount - EMPTY_SECTION_COUNT + 1);
// We clear existing suggestions when the status is not AVAILABLE.
- section.setStatus(CategoryStatus.LOADING_ERROR);
- verify(observerMock)
- .notifyGroupChanged(eq(section), eq(suggestionCount + 1), eq(EMPTY_SECTION_COUNT));
+ section.setStatus(CategoryStatus.SIGNED_OUT);
+ verify(mObserver, times(3)).onItemRangeChanged(section, 1, EMPTY_SECTION_COUNT - 1);
+ verify(mObserver).onItemRangeRemoved(
+ section, EMPTY_SECTION_COUNT, suggestionCount - EMPTY_SECTION_COUNT + 1);
}
@Test
@Feature({"Ntp"})
public void testRemoveSuggestionNotification() {
- ItemGroup.Observer observerMock = mock(ItemGroup.Observer.class);
-
final int suggestionCount = 2;
List<SnippetArticle> snippets = createDummySuggestions(suggestionCount);
- SuggestionsSection section = createSection(false, true, observerMock);
+ SuggestionsSection section = createSection(false, true, mObserver);
section.removeSuggestion(snippets.get(0));
- verify(observerMock, never()).notifyGroupChanged(any(ItemGroup.class), anyInt(), anyInt());
- verify(observerMock, never()).notifyItemRemoved(any(ItemGroup.class), anyInt());
+ verify(mObserver, never())
+ .onItemRangeChanged(any(SuggestionsSection.class), anyInt(), anyInt());
+ verify(mObserver, never())
+ .onItemRangeInserted(any(SuggestionsSection.class), anyInt(), anyInt());
+ verify(mObserver, never())
+ .onItemRangeRemoved(any(SuggestionsSection.class), anyInt(), anyInt());
section.setSuggestions(snippets, CategoryStatus.AVAILABLE);
section.removeSuggestion(snippets.get(1));
- verify(observerMock).notifyItemRemoved(section, 2);
+ verify(mObserver).onItemRangeRemoved(eq(section), eq(2), eq(1));
section.removeSuggestion(snippets.get(0));
- verify(observerMock).notifyItemRemoved(section, 1);
- verify(observerMock).notifyItemInserted(section, 1);
- verify(observerMock).notifyItemInserted(section, 2);
+ verify(mObserver).onItemRangeRemoved(eq(section), eq(1), eq(1));
+ verify(mObserver).onItemRangeInserted(eq(section), eq(1), eq(1));
+ verify(mObserver).onItemRangeInserted(eq(section), eq(2), eq(1));
}
@Test
@Feature({"Ntp"})
public void testRemoveSuggestionNotificationWithButton() {
- ItemGroup.Observer observerMock = mock(ItemGroup.Observer.class);
-
final int suggestionCount = 2;
List<SnippetArticle> snippets = createDummySuggestions(suggestionCount);
- SuggestionsSection section = createSection(true, true, observerMock);
+ SuggestionsSection section = createSection(true, true, mObserver);
section.removeSuggestion(snippets.get(0));
- verify(observerMock, never()).notifyGroupChanged(any(ItemGroup.class), anyInt(), anyInt());
- verify(observerMock, never()).notifyItemRemoved(any(ItemGroup.class), anyInt());
+ verify(mObserver, never())
+ .onItemRangeChanged(any(SuggestionsSection.class), anyInt(), anyInt());
+ verify(mObserver, never())
+ .onItemRangeInserted(any(SuggestionsSection.class), anyInt(), anyInt());
+ verify(mObserver, never())
+ .onItemRangeRemoved(any(SuggestionsSection.class), anyInt(), anyInt());
section.setSuggestions(snippets, CategoryStatus.AVAILABLE);
section.removeSuggestion(snippets.get(0));
- verify(observerMock).notifyItemRemoved(section, 1);
+ verify(mObserver).onItemRangeRemoved(eq(section), eq(1), eq(1));
section.removeSuggestion(snippets.get(1));
- verify(observerMock, times(2)).notifyItemRemoved(section, 1);
- verify(observerMock).notifyItemInserted(section, 1);
- verify(observerMock).notifyItemInserted(section, 3);
+ verify(mObserver, times(2)).onItemRangeRemoved(eq(section), eq(1), eq(1));
+ verify(mObserver).onItemRangeInserted(eq(section), eq(1), eq(1));
+ verify(mObserver).onItemRangeInserted(eq(section), eq(3), eq(1));
}
}
« no previous file with comments | « chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698