OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.junit.Assert.assertEquals; | 7 import static org.junit.Assert.assertEquals; |
8 import static org.junit.Assert.assertFalse; | 8 import static org.junit.Assert.assertFalse; |
9 import static org.junit.Assert.assertNotEquals; | 9 import static org.junit.Assert.assertNotEquals; |
10 import static org.junit.Assert.assertThat; | 10 import static org.junit.Assert.assertThat; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 import org.robolectric.annotation.Implementation; | 46 import org.robolectric.annotation.Implementation; |
47 import org.robolectric.annotation.Implements; | 47 import org.robolectric.annotation.Implements; |
48 import org.robolectric.shadows.ShadowResources; | 48 import org.robolectric.shadows.ShadowResources; |
49 | 49 |
50 import org.chromium.base.Callback; | 50 import org.chromium.base.Callback; |
51 import org.chromium.base.ContextUtils; | 51 import org.chromium.base.ContextUtils; |
52 import org.chromium.base.test.util.Feature; | 52 import org.chromium.base.test.util.Feature; |
53 import org.chromium.chrome.R; | 53 import org.chromium.chrome.R; |
54 import org.chromium.chrome.browser.ChromeFeatureList; | 54 import org.chromium.chrome.browser.ChromeFeatureList; |
55 import org.chromium.chrome.browser.DisableHistogramsRule; | 55 import org.chromium.chrome.browser.DisableHistogramsRule; |
| 56 import org.chromium.chrome.browser.Features; |
56 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 57 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
57 import org.chromium.chrome.browser.ntp.cards.SignInPromo.SigninObserver; | 58 import org.chromium.chrome.browser.ntp.cards.SignInPromo.SigninObserver; |
58 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; | 59 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; |
59 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; | 60 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; |
60 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | 61 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; |
61 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 62 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
62 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 63 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
63 import org.chromium.chrome.browser.signin.SigninManager; | 64 import org.chromium.chrome.browser.signin.SigninManager; |
64 import org.chromium.chrome.browser.signin.SigninManager.SignInAllowedObserver; | 65 import org.chromium.chrome.browser.signin.SigninManager.SignInAllowedObserver; |
65 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; | 66 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; |
66 import org.chromium.chrome.browser.suggestions.DestructionObserver; | 67 import org.chromium.chrome.browser.suggestions.DestructionObserver; |
67 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter; | 68 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter; |
68 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate; | 69 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate; |
69 import org.chromium.chrome.test.util.browser.suggestions.ContentSuggestionsTestU
tils.CategoryInfoBuilder; | 70 import org.chromium.chrome.test.util.browser.suggestions.ContentSuggestionsTestU
tils.CategoryInfoBuilder; |
70 import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource; | 71 import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource; |
71 import org.chromium.testing.local.LocalRobolectricTestRunner; | 72 import org.chromium.testing.local.LocalRobolectricTestRunner; |
72 | 73 |
73 import java.util.ArrayList; | 74 import java.util.ArrayList; |
74 import java.util.Collections; | 75 import java.util.Collections; |
75 import java.util.HashMap; | 76 import java.util.HashMap; |
76 import java.util.List; | 77 import java.util.List; |
77 | 78 |
78 /** | 79 /** |
79 * Unit tests for {@link NewTabPageAdapter}. | 80 * Unit tests for {@link NewTabPageAdapter}. |
80 */ | 81 */ |
81 @RunWith(LocalRobolectricTestRunner.class) | 82 @RunWith(LocalRobolectricTestRunner.class) |
82 @Config(manifest = Config.NONE) | 83 @Config(manifest = Config.NONE) |
| 84 @Features(@Features.Register(value = ChromeFeatureList.NTP_CONDENSED_LAYOUT, ena
bled = false)) |
83 public class NewTabPageAdapterTest { | 85 public class NewTabPageAdapterTest { |
84 @Rule | 86 @Rule |
85 public DisableHistogramsRule mDisableHistogramsRule = new DisableHistogramsR
ule(); | 87 public DisableHistogramsRule mDisableHistogramsRule = new DisableHistogramsR
ule(); |
86 | 88 |
| 89 @Rule |
| 90 public Features.Processor mFeatureProcessor = new Features.Processor(); |
| 91 |
87 @CategoryInt | 92 @CategoryInt |
88 private static final int TEST_CATEGORY = 42; | 93 private static final int TEST_CATEGORY = 42; |
89 | 94 |
90 private FakeSuggestionsSource mSource; | 95 private FakeSuggestionsSource mSource; |
91 private NewTabPageAdapter mAdapter; | 96 private NewTabPageAdapter mAdapter; |
92 @Mock | 97 @Mock |
93 private SigninManager mMockSigninManager; | 98 private SigninManager mMockSigninManager; |
94 @Mock | 99 @Mock |
95 private OfflinePageBridge mOfflinePageBridge; | 100 private OfflinePageBridge mOfflinePageBridge; |
96 @Mock | 101 @Mock |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 193 |
189 @Before | 194 @Before |
190 public void setUp() { | 195 public void setUp() { |
191 MockitoAnnotations.initMocks(this); | 196 MockitoAnnotations.initMocks(this); |
192 | 197 |
193 ContextUtils.initApplicationContextForTests(RuntimeEnvironment.applicati
on); | 198 ContextUtils.initApplicationContextForTests(RuntimeEnvironment.applicati
on); |
194 | 199 |
195 // Set empty variation params for the test. | 200 // Set empty variation params for the test. |
196 CardsVariationParameters.setTestVariationParams(new HashMap<String, Stri
ng>()); | 201 CardsVariationParameters.setTestVariationParams(new HashMap<String, Stri
ng>()); |
197 | 202 |
198 ChromeFeatureList.setTestEnabledFeatures(Collections.<String>emptySet())
; | |
199 | |
200 // Initialise the sign in state. We will be signed in by default in the
tests. | 203 // Initialise the sign in state. We will be signed in by default in the
tests. |
201 assertFalse(ChromePreferenceManager.getInstance().getNewTabPageSigninPro
moDismissed()); | 204 assertFalse(ChromePreferenceManager.getInstance().getNewTabPageSigninPro
moDismissed()); |
202 SigninManager.setInstanceForTesting(mMockSigninManager); | 205 SigninManager.setInstanceForTesting(mMockSigninManager); |
203 when(mMockSigninManager.isSignedInOnNative()).thenReturn(true); | 206 when(mMockSigninManager.isSignedInOnNative()).thenReturn(true); |
204 when(mMockSigninManager.isSignInAllowed()).thenReturn(true); | 207 when(mMockSigninManager.isSignInAllowed()).thenReturn(true); |
205 | 208 |
206 mSource = new FakeSuggestionsSource(); | 209 mSource = new FakeSuggestionsSource(); |
207 mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.INITIALIZING)
; | 210 mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.INITIALIZING)
; |
208 mSource.setInfoForCategory( | 211 mSource.setInfoForCategory( |
209 TEST_CATEGORY, new CategoryInfoBuilder(TEST_CATEGORY).showIfEmpt
y().build()); | 212 TEST_CATEGORY, new CategoryInfoBuilder(TEST_CATEGORY).showIfEmpt
y().build()); |
210 | 213 |
211 when(mUiDelegate.getSuggestionsSource()).thenReturn(mSource); | 214 when(mUiDelegate.getSuggestionsSource()).thenReturn(mSource); |
212 when(mUiDelegate.getMetricsReporter()).thenReturn(mock(SuggestionsMetric
sReporter.class)); | 215 when(mUiDelegate.getMetricsReporter()).thenReturn(mock(SuggestionsMetric
sReporter.class)); |
213 | 216 |
214 reloadNtp(); | 217 reloadNtp(); |
215 } | 218 } |
216 | 219 |
217 @After | 220 @After |
218 public void tearDown() { | 221 public void tearDown() { |
219 CardsVariationParameters.setTestVariationParams(null); | 222 CardsVariationParameters.setTestVariationParams(null); |
220 ChromeFeatureList.setTestEnabledFeatures(null); | |
221 SigninManager.setInstanceForTesting(null); | 223 SigninManager.setInstanceForTesting(null); |
222 ChromePreferenceManager.getInstance().setNewTabPageSigninPromoDismissed(
false); | 224 ChromePreferenceManager.getInstance().setNewTabPageSigninPromoDismissed(
false); |
223 } | 225 } |
224 | 226 |
225 /** | 227 /** |
226 * Tests the content of the adapter under standard conditions: on start and
after a suggestions | 228 * Tests the content of the adapter under standard conditions: on start and
after a suggestions |
227 * fetch. | 229 * fetch. |
228 */ | 230 */ |
229 @Test | 231 @Test |
230 @Feature({"Ntp"}) | 232 @Feature({"Ntp"}) |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 } | 1004 } |
1003 | 1005 |
1004 private boolean isSignInPromoVisible() { | 1006 private boolean isSignInPromoVisible() { |
1005 return mAdapter.getFirstPositionForType(ItemViewType.PROMO) != RecyclerV
iew.NO_POSITION; | 1007 return mAdapter.getFirstPositionForType(ItemViewType.PROMO) != RecyclerV
iew.NO_POSITION; |
1006 } | 1008 } |
1007 | 1009 |
1008 private int getCategory(TreeNode item) { | 1010 private int getCategory(TreeNode item) { |
1009 return ((SuggestionsSection) item).getCategory(); | 1011 return ((SuggestionsSection) item).getCategory(); |
1010 } | 1012 } |
1011 } | 1013 } |
OLD | NEW |