Chromium Code Reviews| 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 048b85e22a44cd0fb7ceff98b601ba594d9ac8a9..87d7c99212d209f71aee701355ef3dd5625bf53d 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 |
| @@ -132,22 +132,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(); |
|
gordanac
2016/08/04 15:52:19
I think you need to either merge https://coderevie
dgn
2016/08/04 16:24:05
Oh no, sorry it slipped. Will send a CL ASAP
|
| + |
| + // 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", |
|
gordanac
2016/08/04 15:52:19
Same as above.
|
| + "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<SnippetArticle> createDummySnippets() { |
| - return Arrays.asList(new SnippetArticle[] { |
| - new SnippetArticle("https://site.com/url1", "title1", "pub1", "txt1", |
| - "https://site.com/url1", "https://amp.site.com/url1", null, 0, 0, 0), |
| - new SnippetArticle("https://site.com/url2", "title2", "pub2", "txt2", |
| - "https://site.com/url2", "https://amp.site.com/url1", null, 0, 0, 0), |
| - new SnippetArticle("https://site.com/url3", "title3", "pub3", "txt3", |
| - "https://site.com/url3", "https://amp.site.com/url1", null, 0, 0, 0)}); |
| + List<SnippetArticle> snippets = new ArrayList<>(); |
| + snippets.add(new SnippetArticle("https://site.com/url1", "title1", "pub1", "txt1", |
| + "https://site.com/url1", "https://amp.site.com/url1", null, 0, 0, 0)); |
| + snippets.add(new SnippetArticle("https://site.com/url2", "title2", "pub2", "txt2", |
| + "https://site.com/url2", "https://amp.site.com/url2", null, 0, 0, 0)); |
| + snippets.add(new SnippetArticle("https://site.com/url3", "title3", "pub3", "txt3", |
| + "https://site.com/url3", "https://amp.site.com/url3", null, 0, 0, 0)); |
| + return snippets; |
| } |
| } |