| 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.assertNotNull; | 9 import static org.junit.Assert.assertNotNull; |
| 10 import static org.junit.Assert.assertNull; | 10 import static org.junit.Assert.assertNull; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 import org.junit.Test; | 26 import org.junit.Test; |
| 27 import org.junit.runner.RunWith; | 27 import org.junit.runner.RunWith; |
| 28 import org.mockito.Mock; | 28 import org.mockito.Mock; |
| 29 import org.mockito.MockitoAnnotations; | 29 import org.mockito.MockitoAnnotations; |
| 30 import org.robolectric.annotation.Config; | 30 import org.robolectric.annotation.Config; |
| 31 | 31 |
| 32 import org.chromium.base.Callback; | 32 import org.chromium.base.Callback; |
| 33 import org.chromium.base.test.util.Feature; | 33 import org.chromium.base.test.util.Feature; |
| 34 import org.chromium.chrome.browser.ChromeFeatureList; | 34 import org.chromium.chrome.browser.ChromeFeatureList; |
| 35 import org.chromium.chrome.browser.EnableFeatures; | 35 import org.chromium.chrome.browser.EnableFeatures; |
| 36 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | |
| 37 import org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.Categor
yInfoBuilder; | 36 import org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.Categor
yInfoBuilder; |
| 38 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; | 37 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; |
| 39 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | 38 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; |
| 40 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | 39 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; |
| 41 import org.chromium.chrome.browser.offlinepages.OfflinePageItem; | 40 import org.chromium.chrome.browser.offlinepages.OfflinePageItem; |
| 42 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter; | 41 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter; |
| 42 import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegate; |
| 43 import org.chromium.chrome.browser.suggestions.SuggestionsRanker; | 43 import org.chromium.chrome.browser.suggestions.SuggestionsRanker; |
| 44 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate; |
| 44 import org.chromium.testing.local.LocalRobolectricTestRunner; | 45 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| 45 | 46 |
| 46 import java.util.Arrays; | 47 import java.util.Arrays; |
| 47 import java.util.HashMap; | 48 import java.util.HashMap; |
| 48 import java.util.List; | 49 import java.util.List; |
| 49 | 50 |
| 50 /** | 51 /** |
| 51 * Unit tests for {@link SuggestionsSection}. | 52 * Unit tests for {@link SuggestionsSection}. |
| 52 */ | 53 */ |
| 53 @RunWith(LocalRobolectricTestRunner.class) | 54 @RunWith(LocalRobolectricTestRunner.class) |
| 54 @Config(manifest = Config.NONE) | 55 @Config(manifest = Config.NONE) |
| 55 public class SuggestionsSectionTest { | 56 public class SuggestionsSectionTest { |
| 56 @Mock | 57 @Mock |
| 57 private SuggestionsSection.Delegate mDelegate; | 58 private SuggestionsSection.Delegate mDelegate; |
| 58 @Mock | 59 @Mock |
| 59 private NodeParent mParent; | 60 private NodeParent mParent; |
| 60 @Mock private NewTabPageManager mManager; | 61 @Mock |
| 62 private SuggestionsUiDelegate mUiDelegate; |
| 61 private FakeOfflinePageBridge mBridge; | 63 private FakeOfflinePageBridge mBridge; |
| 62 | 64 |
| 63 @Before | 65 @Before |
| 64 public void setUp() { | 66 public void setUp() { |
| 65 MockitoAnnotations.initMocks(this); | 67 MockitoAnnotations.initMocks(this); |
| 66 mBridge = new FakeOfflinePageBridge(); | 68 mBridge = new FakeOfflinePageBridge(); |
| 67 | 69 |
| 68 // Set empty variation params for the test. | 70 // Set empty variation params for the test. |
| 69 CardsVariationParameters.setTestVariationParams(new HashMap<String, Stri
ng>()); | 71 CardsVariationParameters.setTestVariationParams(new HashMap<String, Stri
ng>()); |
| 70 } | 72 } |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 460 } |
| 459 | 461 |
| 460 private SuggestionsSection createSectionWithReloadAction(boolean hasReloadAc
tion) { | 462 private SuggestionsSection createSectionWithReloadAction(boolean hasReloadAc
tion) { |
| 461 CategoryInfoBuilder builder = new CategoryInfoBuilder(42).showIfEmpty(); | 463 CategoryInfoBuilder builder = new CategoryInfoBuilder(42).showIfEmpty(); |
| 462 if (hasReloadAction) builder.withReloadAction(); | 464 if (hasReloadAction) builder.withReloadAction(); |
| 463 return createSection(builder.build()); | 465 return createSection(builder.build()); |
| 464 } | 466 } |
| 465 | 467 |
| 466 private SuggestionsSection createSection(SuggestionsCategoryInfo info) { | 468 private SuggestionsSection createSection(SuggestionsCategoryInfo info) { |
| 467 SuggestionsSection section = new SuggestionsSection( | 469 SuggestionsSection section = new SuggestionsSection( |
| 468 mDelegate, mManager, mock(SuggestionsRanker.class), mBridge, inf
o); | 470 mDelegate, mUiDelegate, mock(SuggestionsRanker.class), mBridge,
info); |
| 469 section.setParent(mParent); | 471 section.setParent(mParent); |
| 470 return section; | 472 return section; |
| 471 } | 473 } |
| 472 | 474 |
| 473 private OfflinePageItem createOfflinePageItem(String url, long offlineId) { | 475 private OfflinePageItem createOfflinePageItem(String url, long offlineId) { |
| 474 return new OfflinePageItem(url, offlineId, "", "", "", 0, 0, 0, 0); | 476 return new OfflinePageItem(url, offlineId, "", "", "", 0, 0, 0, 0); |
| 475 } | 477 } |
| 476 | 478 |
| 477 private static void verifyAction(SuggestionsSection section, @ActionItem.Act
ion int action) { | 479 private static void verifyAction(SuggestionsSection section, @ActionItem.Act
ion int action) { |
| 478 SuggestionsSource suggestionsSource = mock(SuggestionsSource.class); | 480 SuggestionsSource suggestionsSource = mock(SuggestionsSource.class); |
| 479 NewTabPageManager manager = mock(NewTabPageManager.class); | 481 SuggestionsUiDelegate manager = mock(SuggestionsUiDelegate.class); |
| 482 SuggestionsNavigationDelegate navDelegate = mock(SuggestionsNavigationDe
legate.class); |
| 480 when(manager.getSuggestionsSource()).thenReturn(suggestionsSource); | 483 when(manager.getSuggestionsSource()).thenReturn(suggestionsSource); |
| 481 when(manager.getSuggestionsMetricsReporter()) | 484 when(manager.getNavigationDelegate()).thenReturn(navDelegate); |
| 482 .thenReturn(mock(SuggestionsMetricsReporter.class)); | 485 when(manager.getMetricsReporter()).thenReturn(mock(SuggestionsMetricsRep
orter.class)); |
| 483 | 486 |
| 484 if (action != ActionItem.ACTION_NONE) { | 487 if (action != ActionItem.ACTION_NONE) { |
| 485 section.getActionItem().performAction(manager); | 488 section.getActionItem().performAction(manager); |
| 486 } | 489 } |
| 487 | 490 |
| 488 verify(section.getCategoryInfo(), | 491 verify(section.getCategoryInfo(), |
| 489 (action == ActionItem.ACTION_VIEW_ALL ? times(1) : never())) | 492 (action == ActionItem.ACTION_VIEW_ALL ? times(1) : never())) |
| 490 .performViewAllAction(manager); | 493 .performViewAllAction(navDelegate); |
| 491 verify(suggestionsSource, | 494 verify(suggestionsSource, |
| 492 action == ActionItem.ACTION_RELOAD || action == ActionItem.ACTIO
N_FETCH_MORE | 495 action == ActionItem.ACTION_RELOAD || action == ActionItem.ACTIO
N_FETCH_MORE |
| 493 ? times(1) | 496 ? times(1) |
| 494 : never()) | 497 : never()) |
| 495 .fetchSuggestions(anyInt(), any(String[].class)); | 498 .fetchSuggestions(anyInt(), any(String[].class)); |
| 496 } | 499 } |
| 497 } | 500 } |
| OLD | NEW |