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

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

Issue 2230303003: Remove Error cards for content suggestions, error case refine behavior (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@allowmoreflag
Patch Set: Rebase (should be no change) Created 4 years, 4 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/java/src/org/chromium/chrome/browser/ntp/cards/StatusListItem.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/NewTabPageAdapterTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java
index f05387bdde2db5f3884ffa2151982872dfcc7c16..429cef5251b4a0f850383a2a98b1a2f11cfd5718 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapterTest.java
@@ -65,6 +65,12 @@ public class NewTabPageAdapterTest {
mCategoryInfo.put(category, info);
}
+ public void silentlyRemoveCategory(int category) {
+ mSuggestions.remove(category);
+ mCategoryStatus.remove(category);
+ mCategoryInfo.remove(category);
+ }
+
@Override
public void dismissSuggestion(SnippetArticleListItem suggestion) {
throw new UnsupportedOperationException();
@@ -132,11 +138,9 @@ public class NewTabPageAdapterTest {
for (int section : sections) expectedCount += section;
if (sections.length > 0) expectedCount += 1; // bottom spacer.
int actualCount = mNtpAdapter.getItemCount();
- if (expectedCount != actualCount) {
- assertEquals("Expected " + expectedCount + " items, but the following " + actualCount
- + " were present: " + mNtpAdapter.getItems(),
- expectedCount, mNtpAdapter.getItemCount());
- }
+ assertEquals("Expected " + expectedCount + " items, but the following " + actualCount
+ + " were present: " + mNtpAdapter.getItems(),
+ expectedCount, mNtpAdapter.getItemCount());
}
/**
@@ -349,20 +353,63 @@ public class NewTabPageAdapterTest {
assertTrue(progress.isVisible());
mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.NOT_PROVIDED);
- assertFalse(progress.isVisible());
-
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
- CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
- assertFalse(progress.isVisible());
-
- mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
CategoryStatus.SIGNED_OUT);
assertFalse(progress.isVisible());
+ }
+ /**
+ * Tests that the entire section disappears if its status switches to LOADING_ERROR or
+ * CATEGORY_EXPLICITLY_DISABLED. Also tests that they are not shown when the NTP reloads.
+ */
+ @Test
+ @Feature({"Ntp"})
+ public void testSectionClearingWhenUnavailable() {
+ List<SnippetArticleListItem> snippets = createDummySnippets(5);
+ mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ assertItemsFor(section(5));
+
+ // When the category goes away with a hard error, the section is cleared from the UI.
mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES,
CategoryStatus.LOADING_ERROR);
- assertFalse(progress.isVisible());
+ assertItemsFor();
+
+ // Same when loading a new NTP.
+ mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
+ assertItemsFor();
+
+ // Same for CATEGORY_EXPLICITLY_DISABLED.
+ mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ assertItemsFor(section(5));
+ mSnippetsSource.setStatusForCategory(
+ KnownCategories.ARTICLES, CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
+ assertItemsFor();
+
+ // Same when loading a new NTP.
+ mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
+ assertItemsFor();
+ }
+
+ /**
+ * Tests that the UI remains untouched if a category switches to NOT_PROVIDED.
+ */
+ @Test
+ @Feature({"Ntp"})
+ public void testUIUntouchedWhenNotProvided() {
+ List<SnippetArticleListItem> snippets = createDummySnippets(4);
+ mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.AVAILABLE);
+ mSnippetsSource.setSuggestionsForCategory(KnownCategories.ARTICLES, snippets);
+ assertItemsFor(section(4));
+
+ // When the category switches to NOT_PROVIDED, UI stays the same.
+ mSnippetsSource.setStatusForCategory(KnownCategories.ARTICLES, CategoryStatus.NOT_PROVIDED);
+ mSnippetsSource.silentlyRemoveCategory(KnownCategories.ARTICLES);
+ assertItemsFor(section(4));
+
+ // But it disappears when loading a new NTP.
+ mNtpAdapter = new NewTabPageAdapter(null, null, mSnippetsSource, null);
+ assertItemsFor();
}
@Test
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusListItem.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698