| 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 21c09f24286f2560597eb604d4d2087439401226..0abac9d0f3d1931548fee61142f42cbd13c2caef 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
|
| @@ -134,22 +134,66 @@ public void testSnippetClearing() {
|
| mSnippetsObserver.onSnippetsReceived(snippets);
|
| assertEquals(3 + snippets.size(), ntpa.getItemCount());
|
|
|
| - // When we clear the snippets, we should go back to the situation with the status card.
|
| + // If we get told that snippets are enabled, we just leave the current
|
| + // ones there and not clear.
|
| mSnippetsObserver.onDisabledReasonChanged(DisabledReason.NONE);
|
| + assertEquals(3 + snippets.size(), ntpa.getItemCount());
|
| +
|
| + // When snippets are disabled, we clear them and we should go back to
|
| + // the situation with the status card.
|
| + mSnippetsObserver.onDisabledReasonChanged(DisabledReason.SIGNED_OUT);
|
| + assertEquals(4, ntpa.getItemCount());
|
| +
|
| + // The adapter should now be waiting for new snippets.
|
| + mSnippetsObserver.onDisabledReasonChanged(DisabledReason.NONE);
|
| + mSnippetsObserver.onSnippetsReceived(snippets);
|
| + assertEquals(3 + snippets.size(), ntpa.getItemCount());
|
| + }
|
| +
|
| + /**
|
| + * Tests that the adapter loads snippets only when the status is favorable.
|
| + */
|
| + @Test
|
| + @Feature({"Ntp"})
|
| + public void testSnippetLoadingBlock() {
|
| + NewTabPageAdapter ntpa = new NewTabPageAdapter(mNewTabPageManager, null, mSnippetsBridge);
|
| +
|
| + List<SnippetArticleListItem> snippets = createDummySnippets();
|
| +
|
| + // By default, state is DisabledReason.NONE, so we can load snippets
|
| + mSnippetsObserver.onSnippetsReceived(snippets);
|
| + assertEquals(3 + snippets.size(), ntpa.getItemCount());
|
| +
|
| + // If we have snippets, we should not load the new list.
|
| + snippets.add(new SnippetArticleListItem("https://site.com/url1", "title1", "pub1", "txt1",
|
| + "https://site.com/url1", "https://amp.site.com/url1", null, 0, 0, 0));
|
| + mSnippetsObserver.onSnippetsReceived(snippets);
|
| + assertEquals(3 + snippets.size() - 1, ntpa.getItemCount());
|
| +
|
| + // When snippets are disabled, we should not be able to load them
|
| + mSnippetsObserver.onDisabledReasonChanged(DisabledReason.SIGNED_OUT);
|
| + mSnippetsObserver.onSnippetsReceived(snippets);
|
| assertEquals(4, ntpa.getItemCount());
|
|
|
| + // HISTORY_SYNC_STATE_UNKNOWN lets us load snippets still.
|
| + mSnippetsObserver.onDisabledReasonChanged(DisabledReason.HISTORY_SYNC_STATE_UNKNOWN);
|
| + mSnippetsObserver.onSnippetsReceived(snippets);
|
| + assertEquals(3 + snippets.size(), ntpa.getItemCount());
|
| +
|
| // The adapter should now be waiting for new snippets.
|
| + mSnippetsObserver.onDisabledReasonChanged(DisabledReason.NONE);
|
| mSnippetsObserver.onSnippetsReceived(snippets);
|
| assertEquals(3 + snippets.size(), ntpa.getItemCount());
|
| }
|
|
|
| private List<SnippetArticleListItem> createDummySnippets() {
|
| - return Arrays.asList(new SnippetArticleListItem[] {
|
| - new SnippetArticleListItem("https://site.com/url1", "title1", "pub1", "txt1",
|
| - "https://site.com/url1", "https://amp.site.com/url1", null, 0, 0, 0),
|
| - new SnippetArticleListItem("https://site.com/url2", "title2", "pub2", "txt2",
|
| - "https://site.com/url2", "https://amp.site.com/url1", null, 0, 0, 0),
|
| - new SnippetArticleListItem("https://site.com/url3", "title3", "pub3", "txt3",
|
| - "https://site.com/url3", "https://amp.site.com/url1", null, 0, 0, 0)});
|
| + List<SnippetArticleListItem> snippets = new ArrayList<>();
|
| + snippets.add(new SnippetArticleListItem("https://site.com/url1", "title1", "pub1", "txt1",
|
| + "https://site.com/url1", "https://amp.site.com/url1", null, 0, 0, 0));
|
| + snippets.add(new SnippetArticleListItem("https://site.com/url2", "title2", "pub2", "txt2",
|
| + "https://site.com/url2", "https://amp.site.com/url2", null, 0, 0, 0));
|
| + snippets.add(new SnippetArticleListItem("https://site.com/url3", "title3", "pub3", "txt3",
|
| + "https://site.com/url3", "https://amp.site.com/url3", null, 0, 0, 0));
|
| + return snippets;
|
| }
|
| }
|
|
|