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

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

Issue 2570913003: [Android NTP] Move dismissing items into the TreeNode interface. (Closed)
Patch Set: comments Created 4 years 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 4ae471ac93ffe1c9d18f7d7c785aa58be482e95d..7802f8ab7994ddfa60b0ef4c561b919eb47422f0 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
@@ -29,7 +29,10 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import org.chromium.base.Callback;
import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.ChromeFeatureList;
+import org.chromium.chrome.browser.EnableFeatures;
import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
import org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.CategoryInfoBuilder;
import org.chromium.chrome.browser.ntp.snippets.CategoryStatus;
@@ -47,8 +50,10 @@ import java.util.List;
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class SuggestionsSectionTest {
-
- @Mock private NodeParent mParent;
+ @Mock
+ private SuggestionsSection.Delegate mDelegate;
+ @Mock
+ private NodeParent mParent;
@Mock private NewTabPageManager mManager;
private FakeOfflinePageBridge mBridge;
@@ -92,6 +97,7 @@ public class SuggestionsSectionTest {
reset(mParent);
assertEquals(2, section.getItemCount()); // When empty, we have the header and status card.
+ assertEquals(ItemViewType.STATUS, section.getItemViewType(1));
section.addSuggestions(snippets, CategoryStatus.AVAILABLE);
verify(mParent).onItemRangeInserted(section, 1, suggestionCount);
@@ -128,12 +134,12 @@ public class SuggestionsSectionTest {
verifyNoMoreInteractions(mParent);
}
- @Test(expected = IndexOutOfBoundsException.class)
+ @Test
@Feature({"Ntp"})
public void testRemoveUnknownSuggestion() {
SuggestionsSection section = createSectionWithReloadAction(false);
section.setStatus(CategoryStatus.AVAILABLE);
- section.removeSuggestion(createDummySuggestions(1).get(0));
+ section.removeSuggestionById("foobar");
}
@Test
@@ -148,12 +154,15 @@ public class SuggestionsSectionTest {
section.addSuggestions(snippets, CategoryStatus.AVAILABLE);
- section.removeSuggestion(snippets.get(1));
+ section.removeSuggestionById(snippets.get(1).mIdWithinCategory);
verify(mParent).onItemRangeRemoved(section, 2, 1);
- section.removeSuggestion(snippets.get(0));
+ section.removeSuggestionById(snippets.get(0).mIdWithinCategory);
verify(mParent).onItemRangeRemoved(section, 1, 1);
verify(mParent).onItemRangeInserted(section, 1, 1);
+
+ assertEquals(2, section.getItemCount());
+ assertEquals(ItemViewType.STATUS, section.getItemViewType(1));
}
@Test
@@ -174,13 +183,33 @@ public class SuggestionsSectionTest {
assertEquals(3, section.getItemCount()); // We have the header and status card and a button.
section.addSuggestions(snippets, CategoryStatus.AVAILABLE);
+ assertEquals(4, section.getItemCount());
- section.removeSuggestion(snippets.get(0));
+ section.removeSuggestionById(snippets.get(0).mIdWithinCategory);
verify(mParent).onItemRangeRemoved(section, 1, 1);
- section.removeSuggestion(snippets.get(1));
+ section.removeSuggestionById(snippets.get(1).mIdWithinCategory);
verify(mParent, times(2)).onItemRangeRemoved(section, 1, 1);
verify(mParent).onItemRangeInserted(section, 1, 1); // Only the status card is added.
+ assertEquals(3, section.getItemCount());
+ assertEquals(ItemViewType.STATUS, section.getItemViewType(1));
+ assertEquals(ItemViewType.ACTION, section.getItemViewType(2));
+ }
+
+ @Test
+ @Feature({"Ntp"})
+ @EnableFeatures({ChromeFeatureList.NTP_SUGGESTIONS_SECTION_DISMISSAL})
+ public void testDismissSection() {
+ SuggestionsSection section = createSectionWithReloadAction(false);
+ section.setStatus(CategoryStatus.AVAILABLE);
+ reset(mParent);
+ assertEquals(2, section.getItemCount());
+
+ @SuppressWarnings("unchecked")
+ Callback<String> callback = mock(Callback.class);
+ section.dismissItem(1, callback);
+ verify(mDelegate).dismissSection(section);
+ verify(callback).onResult(section.getHeaderText());
}
@Test
@@ -347,7 +376,7 @@ public class SuggestionsSectionTest {
}
private SuggestionsSection createSection(SuggestionsCategoryInfo info) {
- SuggestionsSection section = new SuggestionsSection(mManager, mBridge, info);
+ SuggestionsSection section = new SuggestionsSection(mDelegate, mManager, mBridge, info);
section.setParent(mParent);
return section;
}
« 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