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 21 matching lines...) Expand all Loading... |
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; | 36 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; |
37 import org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.Categor
yInfoBuilder; | 37 import org.chromium.chrome.browser.ntp.cards.ContentSuggestionsTestUtils.Categor
yInfoBuilder; |
38 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; | 38 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; |
39 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | 39 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; |
40 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | 40 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; |
41 import org.chromium.chrome.browser.offlinepages.OfflinePageItem; | 41 import org.chromium.chrome.browser.offlinepages.OfflinePageItem; |
| 42 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter; |
| 43 import org.chromium.chrome.browser.suggestions.SuggestionsRanker; |
42 import org.chromium.testing.local.LocalRobolectricTestRunner; | 44 import org.chromium.testing.local.LocalRobolectricTestRunner; |
43 | 45 |
44 import java.util.Arrays; | 46 import java.util.Arrays; |
45 import java.util.HashMap; | 47 import java.util.HashMap; |
46 import java.util.List; | 48 import java.util.List; |
47 | 49 |
48 /** | 50 /** |
49 * Unit tests for {@link SuggestionsSection}. | 51 * Unit tests for {@link SuggestionsSection}. |
50 */ | 52 */ |
51 @RunWith(LocalRobolectricTestRunner.class) | 53 @RunWith(LocalRobolectricTestRunner.class) |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 return section; | 457 return section; |
456 } | 458 } |
457 | 459 |
458 private SuggestionsSection createSectionWithReloadAction(boolean hasReloadAc
tion) { | 460 private SuggestionsSection createSectionWithReloadAction(boolean hasReloadAc
tion) { |
459 CategoryInfoBuilder builder = new CategoryInfoBuilder(42).showIfEmpty(); | 461 CategoryInfoBuilder builder = new CategoryInfoBuilder(42).showIfEmpty(); |
460 if (hasReloadAction) builder.withReloadAction(); | 462 if (hasReloadAction) builder.withReloadAction(); |
461 return createSection(builder.build()); | 463 return createSection(builder.build()); |
462 } | 464 } |
463 | 465 |
464 private SuggestionsSection createSection(SuggestionsCategoryInfo info) { | 466 private SuggestionsSection createSection(SuggestionsCategoryInfo info) { |
465 SuggestionsSection section = new SuggestionsSection(mDelegate, mManager,
mBridge, info); | 467 SuggestionsSection section = new SuggestionsSection( |
| 468 mDelegate, mManager, mock(SuggestionsRanker.class), mBridge, inf
o); |
466 section.setParent(mParent); | 469 section.setParent(mParent); |
467 return section; | 470 return section; |
468 } | 471 } |
469 | 472 |
470 private OfflinePageItem createOfflinePageItem(String url, long offlineId) { | 473 private OfflinePageItem createOfflinePageItem(String url, long offlineId) { |
471 return new OfflinePageItem(url, offlineId, "", "", "", 0, 0, 0, 0); | 474 return new OfflinePageItem(url, offlineId, "", "", "", 0, 0, 0, 0); |
472 } | 475 } |
473 | 476 |
474 private static void verifyAction(SuggestionsSection section, @ActionItem.Act
ion int action) { | 477 private static void verifyAction(SuggestionsSection section, @ActionItem.Act
ion int action) { |
475 SuggestionsSource suggestionsSource = mock(SuggestionsSource.class); | 478 SuggestionsSource suggestionsSource = mock(SuggestionsSource.class); |
476 NewTabPageManager manager = mock(NewTabPageManager.class); | 479 NewTabPageManager manager = mock(NewTabPageManager.class); |
477 when(manager.getSuggestionsSource()).thenReturn(suggestionsSource); | 480 when(manager.getSuggestionsSource()).thenReturn(suggestionsSource); |
| 481 when(manager.getSuggestionsMetricsReporter()) |
| 482 .thenReturn(mock(SuggestionsMetricsReporter.class)); |
478 | 483 |
479 if (action != ActionItem.ACTION_NONE) { | 484 if (action != ActionItem.ACTION_NONE) { |
480 section.getActionItem().performAction(manager); | 485 section.getActionItem().performAction(manager); |
481 } | 486 } |
482 | 487 |
483 verify(section.getCategoryInfo(), | 488 verify(section.getCategoryInfo(), |
484 (action == ActionItem.ACTION_VIEW_ALL ? times(1) : never())) | 489 (action == ActionItem.ACTION_VIEW_ALL ? times(1) : never())) |
485 .performViewAllAction(manager); | 490 .performViewAllAction(manager); |
486 verify(suggestionsSource, | 491 verify(suggestionsSource, |
487 action == ActionItem.ACTION_RELOAD || action == ActionItem.ACTIO
N_FETCH_MORE | 492 action == ActionItem.ACTION_RELOAD || action == ActionItem.ACTIO
N_FETCH_MORE |
488 ? times(1) | 493 ? times(1) |
489 : never()) | 494 : never()) |
490 .fetchSuggestions(anyInt(), any(String[].class)); | 495 .fetchSuggestions(anyInt(), any(String[].class)); |
491 } | 496 } |
492 } | 497 } |
OLD | NEW |