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

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SectionListTest.java

Issue 2623993007: 🏠 Extract the ContentSuggestionManager interface from NTP (Closed)
Patch Set: address comments Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.ntp.cards; 5 package org.chromium.chrome.browser.ntp.cards;
6 6
7 import static org.hamcrest.CoreMatchers.equalTo; 7 import static org.hamcrest.CoreMatchers.equalTo;
8 import static org.junit.Assert.assertThat; 8 import static org.junit.Assert.assertThat;
9 import static org.mockito.Mockito.mock; 9 import static org.mockito.Mockito.mock;
10 import static org.mockito.Mockito.when; 10 import static org.mockito.Mockito.when;
11 11
12 import static org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils. createDummySuggestions; 12 import static org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils. createDummySuggestions;
13 import static org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils. registerCategory; 13 import static org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils. registerCategory;
14 14
15 import org.junit.Before; 15 import org.junit.Before;
16 import org.junit.Test; 16 import org.junit.Test;
17 import org.junit.runner.RunWith; 17 import org.junit.runner.RunWith;
18 import org.mockito.Mock; 18 import org.mockito.Mock;
19 import org.mockito.MockitoAnnotations; 19 import org.mockito.MockitoAnnotations;
20 import org.robolectric.annotation.Config; 20 import org.robolectric.annotation.Config;
21 21
22 import org.chromium.base.Callback; 22 import org.chromium.base.Callback;
23 import org.chromium.base.test.util.Feature; 23 import org.chromium.base.test.util.Feature;
24 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
25 import org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.Categor yInfoBuilder; 24 import org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.Categor yInfoBuilder;
26 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; 25 import org.chromium.chrome.browser.ntp.snippets.CategoryInt;
27 import org.chromium.chrome.browser.ntp.snippets.FakeSuggestionsSource; 26 import org.chromium.chrome.browser.ntp.snippets.FakeSuggestionsSource;
28 import org.chromium.chrome.browser.ntp.snippets.KnownCategories; 27 import org.chromium.chrome.browser.ntp.snippets.KnownCategories;
29 import org.chromium.chrome.browser.ntp.snippets.SectionHeaderViewHolder; 28 import org.chromium.chrome.browser.ntp.snippets.SectionHeaderViewHolder;
30 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; 29 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
31 import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder; 30 import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder;
32 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; 31 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
33 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter; 32 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter;
33 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate;
34 import org.chromium.testing.local.LocalRobolectricTestRunner; 34 import org.chromium.testing.local.LocalRobolectricTestRunner;
35 35
36 import java.util.Collections; 36 import java.util.Collections;
37 import java.util.List; 37 import java.util.List;
38 38
39 /** 39 /**
40 * Unit tests for {@link SuggestionsSection}. 40 * Unit tests for {@link SuggestionsSection}.
41 */ 41 */
42 @RunWith(LocalRobolectricTestRunner.class) 42 @RunWith(LocalRobolectricTestRunner.class)
43 @Config(manifest = Config.NONE) 43 @Config(manifest = Config.NONE)
44 public class SectionListTest { 44 public class SectionListTest {
45 @Mock 45 @Mock
46 private NewTabPageManager mNtpManager; 46 private SuggestionsUiDelegate mUiDelegate;
47 @Mock 47 @Mock
48 private OfflinePageBridge mOfflinePageBridge; 48 private OfflinePageBridge mOfflinePageBridge;
49 @Mock 49 @Mock
50 private SuggestionsMetricsReporter mMetricsReporter; 50 private SuggestionsMetricsReporter mMetricsReporter;
51 private FakeSuggestionsSource mSuggestionSource; 51 private FakeSuggestionsSource mSuggestionSource;
52 52
53 @Before 53 @Before
54 public void setUp() { 54 public void setUp() {
55 MockitoAnnotations.initMocks(this); 55 MockitoAnnotations.initMocks(this);
56 mSuggestionSource = new FakeSuggestionsSource(); 56 mSuggestionSource = new FakeSuggestionsSource();
57 57
58 when(mNtpManager.getSuggestionsSource()).thenReturn(mSuggestionSource); 58 when(mUiDelegate.getSuggestionsSource()).thenReturn(mSuggestionSource);
59 when(mNtpManager.getSuggestionsMetricsReporter()).thenReturn(mMetricsRep orter); 59 when(mUiDelegate.getMetricsReporter()).thenReturn(mMetricsReporter);
60 } 60 }
61 61
62 @Test 62 @Test
63 @Feature({"Ntp"}) 63 @Feature({"Ntp"})
64 public void testGetSuggestionRank() { 64 public void testGetSuggestionRank() {
65 // Setup the section list the following way: 65 // Setup the section list the following way:
66 // 66 //
67 // Item type | local rank | global rank 67 // Item type | local rank | global rank
68 // -----------+------------+------------- 68 // -----------+------------+-------------
69 // HEADER | | 69 // HEADER | |
70 // ARTICLE | 0 | 0 70 // ARTICLE | 0 | 0
71 // ARTICLE | 1 | 1 71 // ARTICLE | 1 | 1
72 // ARTICLE | 2 | 2 72 // ARTICLE | 2 | 2
73 // HEADER | | 73 // HEADER | |
74 // STATUS | | 74 // STATUS | |
75 // ACTION | 0 | 75 // ACTION | 0 |
76 // BOOKMARK | 0 | 3 76 // BOOKMARK | 0 | 3
77 // BOOKMARK | 1 | 4 77 // BOOKMARK | 1 | 4
78 // BOOKMARK | 2 | 5 78 // BOOKMARK | 2 | 5
79 // BOOKMARK | 3 | 6 79 // BOOKMARK | 3 | 6
80 List<SnippetArticle> articles = 80 List<SnippetArticle> articles =
81 registerCategory(mSuggestionSource, KnownCategories.ARTICLES, 3) ; 81 registerCategory(mSuggestionSource, KnownCategories.ARTICLES, 3) ;
82 registerCategory(mSuggestionSource, KnownCategories.DOWNLOADS, 0); 82 registerCategory(mSuggestionSource, KnownCategories.DOWNLOADS, 0);
83 List<SnippetArticle> bookmarks = 83 List<SnippetArticle> bookmarks =
84 registerCategory(mSuggestionSource, KnownCategories.BOOKMARKS, 4 ); 84 registerCategory(mSuggestionSource, KnownCategories.BOOKMARKS, 4 );
85 85
86 SectionList sectionList = new SectionList(mNtpManager, mOfflinePageBridg e); 86 SectionList sectionList = new SectionList(mUiDelegate, mOfflinePageBridg e);
87 87
88 assertThat(articles.get(0).getGlobalRank(), equalTo(0)); 88 assertThat(articles.get(0).getGlobalRank(), equalTo(0));
89 assertThat(articles.get(0).getPerSectionRank(), equalTo(0)); 89 assertThat(articles.get(0).getPerSectionRank(), equalTo(0));
90 assertThat(articles.get(2).getGlobalRank(), equalTo(2)); 90 assertThat(articles.get(2).getGlobalRank(), equalTo(2));
91 assertThat(articles.get(2).getPerSectionRank(), equalTo(2)); 91 assertThat(articles.get(2).getPerSectionRank(), equalTo(2));
92 assertThat(bookmarks.get(1).getGlobalRank(), equalTo(4)); 92 assertThat(bookmarks.get(1).getGlobalRank(), equalTo(4));
93 assertThat(bookmarks.get(1).getPerSectionRank(), equalTo(1)); 93 assertThat(bookmarks.get(1).getPerSectionRank(), equalTo(1));
94 94
95 // Test ranks after changes: remove then add some items. 95 // Test ranks after changes: remove then add some items.
96 @SuppressWarnings("unchecked") 96 @SuppressWarnings("unchecked")
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 assertThat(newBookmarks.get(1).getPerSectionRank(), equalTo(5)); 140 assertThat(newBookmarks.get(1).getPerSectionRank(), equalTo(5));
141 } 141 }
142 142
143 @Test 143 @Test
144 @Feature({"Ntp"}) 144 @Feature({"Ntp"})
145 public void testGetActionItemRank() { 145 public void testGetActionItemRank() {
146 registerCategory(mSuggestionSource, KnownCategories.ARTICLES, 0); 146 registerCategory(mSuggestionSource, KnownCategories.ARTICLES, 0);
147 registerCategory(mSuggestionSource, 147 registerCategory(mSuggestionSource,
148 new CategoryInfoBuilder(KnownCategories.DOWNLOADS).withViewAllAc tion().build(), 3); 148 new CategoryInfoBuilder(KnownCategories.DOWNLOADS).withViewAllAc tion().build(), 3);
149 149
150 SectionList sectionList = new SectionList(mNtpManager, mOfflinePageBridg e); 150 SectionList sectionList = new SectionList(mUiDelegate, mOfflinePageBridg e);
151 bindViewHolders(sectionList); 151 bindViewHolders(sectionList);
152 152
153 assertThat(sectionList.getSectionForTesting(KnownCategories.ARTICLES) 153 assertThat(sectionList.getSectionForTesting(KnownCategories.ARTICLES)
154 .getActionItem() 154 .getActionItem()
155 .getPerSectionRank(), 155 .getPerSectionRank(),
156 equalTo(0)); 156 equalTo(0));
157 assertThat(sectionList.getSectionForTesting(KnownCategories.DOWNLOADS) 157 assertThat(sectionList.getSectionForTesting(KnownCategories.DOWNLOADS)
158 .getActionItem() 158 .getActionItem()
159 .getPerSectionRank(), 159 .getPerSectionRank(),
160 equalTo(3)); 160 equalTo(3));
(...skipping 20 matching lines...) Expand all
181 return mock(StatusCardViewHolder.class); 181 return mock(StatusCardViewHolder.class);
182 case ItemViewType.ACTION: 182 case ItemViewType.ACTION:
183 return mock(ActionItem.ViewHolder.class); 183 return mock(ActionItem.ViewHolder.class);
184 case ItemViewType.PROGRESS: 184 case ItemViewType.PROGRESS:
185 return mock(ProgressViewHolder.class); 185 return mock(ProgressViewHolder.class);
186 default: 186 default:
187 return mock(NewTabPageViewHolder.class); 187 return mock(NewTabPageViewHolder.class);
188 } 188 }
189 } 189 }
190 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698