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

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

Issue 2191593002: 📰 Add a spinner to indicate content is loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit tests, add an extra one 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_sources.gni ('k') | third_party/android_swipe_refresh/README.chromium » ('j') | 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 9a43670be3724ec50e037d1b25b742d0e09e57ba..c2e8c066bf5fc05525ec5b7766231e08af757b21 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
@@ -5,6 +5,8 @@
package org.chromium.chrome.browser.ntp.cards;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -66,11 +68,12 @@ public void testSnippetLoading() {
NewTabPageAdapter ntpa =
new NewTabPageAdapter(mNewTabPageManager, null, mSnippetsBridge, null);
- assertEquals(4, ntpa.getItemCount());
+ assertEquals(5, ntpa.getItemCount());
assertEquals(NewTabPageListItem.VIEW_TYPE_ABOVE_THE_FOLD, ntpa.getItemViewType(0));
assertEquals(NewTabPageListItem.VIEW_TYPE_HEADER, ntpa.getItemViewType(1));
assertEquals(NewTabPageListItem.VIEW_TYPE_STATUS, ntpa.getItemViewType(2));
- assertEquals(NewTabPageListItem.VIEW_TYPE_SPACING, ntpa.getItemViewType(3));
+ assertEquals(NewTabPageListItem.VIEW_TYPE_PROGRESS, ntpa.getItemViewType(3));
+ assertEquals(NewTabPageListItem.VIEW_TYPE_SPACING, ntpa.getItemViewType(4));
List<SnippetArticleListItem> snippets = createDummySnippets();
mSnippetsObserver.onSnippetsReceived(snippets);
@@ -101,11 +104,12 @@ public void testSnippetLoadingInitiallyEmpty() {
// If we don't get anything, we should be in the same situation as the initial one.
mSnippetsObserver.onSnippetsReceived(new ArrayList<SnippetArticleListItem>());
- assertEquals(4, ntpa.getItemCount());
+ assertEquals(5, ntpa.getItemCount());
assertEquals(NewTabPageListItem.VIEW_TYPE_ABOVE_THE_FOLD, ntpa.getItemViewType(0));
assertEquals(NewTabPageListItem.VIEW_TYPE_HEADER, ntpa.getItemViewType(1));
assertEquals(NewTabPageListItem.VIEW_TYPE_STATUS, ntpa.getItemViewType(2));
- assertEquals(NewTabPageListItem.VIEW_TYPE_SPACING, ntpa.getItemViewType(3));
+ assertEquals(NewTabPageListItem.VIEW_TYPE_PROGRESS, ntpa.getItemViewType(3));
+ assertEquals(NewTabPageListItem.VIEW_TYPE_SPACING, ntpa.getItemViewType(4));
// We should load new snippets when we get notified about them.
List<SnippetArticleListItem> snippets = createDummySnippets();
@@ -145,7 +149,7 @@ public void testSnippetClearing() {
// When snippets are disabled, we clear them and we should go back to
// the situation with the status card.
mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.SIGNED_OUT);
- assertEquals(4, ntpa.getItemCount());
+ assertEquals(5, ntpa.getItemCount());
// The adapter should now be waiting for new snippets.
mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.AVAILABLE);
@@ -177,7 +181,7 @@ public void testSnippetLoadingBlock() {
// When snippets are disabled, we should not be able to load them
mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.SIGNED_OUT);
mSnippetsObserver.onSnippetsReceived(snippets);
- assertEquals(4, ntpa.getItemCount());
+ assertEquals(5, ntpa.getItemCount());
// INITIALIZING lets us load snippets still.
mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.INITIALIZING);
@@ -190,6 +194,39 @@ public void testSnippetLoadingBlock() {
assertEquals(3 + snippets.size(), ntpa.getItemCount());
}
+ /**
+ * Tests how the loading indicator reacts to status changes.
+ */
+ @Test
+ @Feature({"Ntp"})
+ public void testProgressIndicatorDisplay() {
+ NewTabPageAdapter ntpa =
+ new NewTabPageAdapter(mNewTabPageManager, null, mSnippetsBridge, null);
+ int progressPos = ntpa.getBottomSpacerPosition() - 1;
+ ProgressListItem progress = (ProgressListItem) ntpa.getItemsForTesting().get(progressPos);
+
+ mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.INITIALIZING);
+ assertTrue(progress.isVisible());
+
+ mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.AVAILABLE);
+ assertFalse(progress.isVisible());
+
+ mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.AVAILABLE_LOADING);
+ assertTrue(progress.isVisible());
+
+ mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.NOT_PROVIDED);
+ assertFalse(progress.isVisible());
+
+ mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
+ assertFalse(progress.isVisible());
+
+ mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.SIGNED_OUT);
+ assertFalse(progress.isVisible());
+
+ mSnippetsObserver.onCategoryStatusChanged(CategoryStatus.LOADING_ERROR);
+ assertFalse(progress.isVisible());
+ }
+
private List<SnippetArticleListItem> createDummySnippets() {
List<SnippetArticleListItem> snippets = new ArrayList<>();
snippets.add(new SnippetArticleListItem("https://site.com/url1", "title1", "pub1", "txt1",
« no previous file with comments | « chrome/android/java_sources.gni ('k') | third_party/android_swipe_refresh/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698