| 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 3d8b185de739a343c971cea2afe761d28abf95ae..10b29b8cf441d003e047bb02da47471ebe37f13d 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
|
| @@ -32,6 +32,7 @@
|
| import org.robolectric.annotation.Config;
|
|
|
| import org.chromium.base.Callback;
|
| +import org.chromium.base.metrics.RecordHistogram;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.chrome.browser.ChromeFeatureList;
|
| import org.chromium.chrome.browser.EnableFeatures;
|
| @@ -41,6 +42,7 @@
|
| import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
|
| import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
|
| import org.chromium.chrome.browser.offlinepages.OfflinePageItem;
|
| +import org.chromium.chrome.browser.suggestions.PartialUpdateId;
|
| import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter;
|
| import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegate;
|
| import org.chromium.chrome.browser.suggestions.SuggestionsRanker;
|
| @@ -68,6 +70,7 @@
|
|
|
| @Before
|
| public void setUp() {
|
| + RecordHistogram.disableForTests();
|
| MockitoAnnotations.initMocks(this);
|
| mBridge = new FakeOfflinePageBridge();
|
|
|
| @@ -143,7 +146,6 @@ public void testSetStatusNotification() {
|
|
|
| section.setStatus(CategoryStatus.AVAILABLE);
|
| verify(mParent).onItemRangeRemoved(section, 2, 1);
|
| - verifyNoMoreInteractions(mParent);
|
| }
|
|
|
| @Test
|
| @@ -557,6 +559,32 @@ public void testSectionDoesNotUpdateOnNewSuggestionsWhenAllSeen() {
|
| }
|
| }
|
|
|
| + @Test
|
| + @Feature({"Ntp"})
|
| + public void testCardIsNotifiedWhenBecomingFirstOrLast() {
|
| + List<SnippetArticle> suggestions = createDummySuggestions(3, /* categoryId = */ 42);
|
| + SuggestionsSection section = createSectionWithReloadAction(false);
|
| + section.setStatus(CategoryStatus.AVAILABLE);
|
| + section.setSuggestions(suggestions, CategoryStatus.AVAILABLE, /* replaceExisting = */ true);
|
| +
|
| + // When the first suggestion is removed, the new first should be notified to update its
|
| + // background.
|
| + section.removeSuggestionById(suggestions.get(0).mIdWithinCategory);
|
| + verify(mParent).onItemRangeChanged(section, 2, 1, PartialUpdateId.CARD_BACKGROUND);
|
| +
|
| + // When the last suggestion is removed, the new last should be notified to update its
|
| + // background.
|
| + section.removeSuggestionById(suggestions.get(2).mIdWithinCategory);
|
| + verify(mParent).onItemRangeChanged(section, 1, 1, PartialUpdateId.CARD_BACKGROUND);
|
| +
|
| + // When items are added after the last suggestion, it should be notified to update its
|
| + // background.
|
| + section.setSuggestions(createDummySuggestions(2, /* categoryId = */ 42, "new"),
|
| + CategoryStatus.AVAILABLE, /* replaceExisting = */ false);
|
| + verify(mParent, times(2))
|
| + .onItemRangeChanged(section, 1, 1, PartialUpdateId.CARD_BACKGROUND);
|
| + }
|
| +
|
| private SuggestionsSection createSectionWithSuggestions(List<SnippetArticle> snippets) {
|
| SuggestionsSection section = createSectionWithReloadAction(true);
|
| section.setStatus(CategoryStatus.AVAILABLE);
|
|
|