| 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));
 | 
|      }
 | 
|  }
 | 
| 
 |